It is currently Sat May 25, 2013 7:36 am

All times are UTC





Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Nov 15, 2011 1:42 pm 
Offline
Forum Admin
User avatar

Joined: 29 Jan 2004
Posts: 13448
Country: United States
State: Florida
CAD System: Inventor
Not seeing hwo to set the sheet size in a IDW... current have some VBA code I'm working on converting to an addin. From a part file or assembly it opend my drawing template and then inserts the file as a view. Want to be able to have a radio button set the sheet size as well...

Code:
Public Sub SaveAsDrawing()

'written by Sean Dotson with a little change by Kevin Schneider, copyright 2006

'declare the environment
Dim oApp As Application
Dim oCurrentDoc As Document
Dim oNewDoc As Document
Dim UseDefaultTemplate As Boolean
Dim oNewDwg As DrawingDocument

Set oApp = ThisApplication
Set oCurrentDoc = oApp.ActiveDocument

On Error GoTo ErrorSub

Select Case oApp.ActiveDocumentType

Case kAssemblyDocumentObject, kPartDocumentObject

    sCurrentFilename = ThisApplication.ActiveDocument.FullFileName
   
    If sCurrentFilename = "" Then
        MsgBox "The active file must first be saved"
        Exit Sub
    End If
   
    'if you want to use the default template then set UseDefaultTemplate = True
    'if you want to use a custom template set the path and filename of sTemplatePart and UseDefaultTemaplte = False
   
    UseDefaultTemplate = False
   
    Dim sTemplateDrawing As String
   
    If Units = "Metric" Then
        sTemplateDrawing = "K:\Inventor Synced\R2012 Templates\_RND\Metric Detail.idw"
    ElseIf Units = "Imperial" Then
        sTemplateDrawing = "K:\Inventor Synced\R2012 Templates\_RND\Std Detail.idw"
    End If
   
    Select Case UseDefaultTemplate
        Case True
            Set oNewDoc = oApp.Documents.Add(kDrawingDocumentObject, oApp.FileManager.GetTemplateFile(kDrawingDocumentObject), True)
        Case False
            Set oNewDoc = oApp.Documents.Add(kDrawingDocumentObject, sTemplateDrawing, True)
    End Select
     
-----------------------------------

[b]<--- NEED TO SET SHEET SIZE HERE -->    [/b]

--------------------------------------
     
    'Post the filename to the private event queue.
    Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, sCurrentFilename)
       
    'Start the derived part command.
    Call oApp.CommandManager.StartCommand(kCreateDrawingViewCommand)

Case Else

ErrorSub:
    MsgBox "You must first have a Part or Assembly document open"

End Select

End Sub

_________________
Sean Dotson, PE
RND Automation & Engineering
Free 30 day trial of iPropWiz v5
Follow @seandotson & @mcadforums & @rndautomationon Twitter


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
PostPosted: Tue Nov 15, 2011 7:30 pm 
Offline
MCAD Regular

Joined: 12 Feb 2004
Posts: 338
This example is hard coded to make sheet 1 = B size. Tested fine here using my default template.

Adding radio buttons to select a different size should be trivial from this point as long as the sizes you need are on the DrawingSheetSizeEnum list.

Sheet formats would be another way to do this-- it could even be the better choice if you need to use size-specific title blocks or portrait/landscape options.

Code:
Public Sub SaveAsDrawing()

'written by Sean Dotson with a little change by Kevin Schneider, copyright 2006

'declare the environment
Dim oApp As Application
Dim oCurrentDoc As Document
Dim oNewDoc As Document
Dim UseDefaultTemplate As Boolean
Dim oNewDwg As DrawingDocument

Set oApp = ThisApplication
Set oCurrentDoc = oApp.ActiveDocument

On Error GoTo ErrorSub

Select Case oApp.ActiveDocumentType

Case kAssemblyDocumentObject, kPartDocumentObject

    sCurrentFilename = ThisApplication.ActiveDocument.FullFileName
   
    If sCurrentFilename = "" Then
        MsgBox "The active file must first be saved"
        Exit Sub
    End If
   
    'if you want to use the default template then set UseDefaultTemplate = True
    'if you want to use a custom template set the path and filename of sTemplatePart and UseDefaultTemaplte = False
   
    UseDefaultTemplate = False
   
    Dim sTemplateDrawing As String

    If Units = "Metric" Then
        sTemplateDrawing = "K:\Inventor Synced\R2012 Templates\_RND\Metric Detail.idw"
    ElseIf Units = "Imperial" Then
        sTemplateDrawing = "K:\Inventor Synced\R2012 Templates\_RND\Std Detail.idw"
    End If
   
    Select Case UseDefaultTemplate
        Case True
            Set oNewDoc = oApp.Documents.Add(kDrawingDocumentObject, oApp.FileManager.GetTemplateFile(kDrawingDocumentObject), True)
        Case False
            Set oNewDoc = oApp.Documents.Add(kDrawingDocumentObject, sTemplateDrawing, True)
    End Select
   
' Public Enum DrawingSheetSizeEnum
'  kCustomDrawingSheetSize = 9986
'  kADrawingSheetSize = 9987
'  kBDrawingSheetSize = 9988
'  kCDrawingSheetSize = 9989
'  kDDrawingSheetSize = 9990
'  kEDrawingSheetSize = 9991
'  kFDrawingSheetSize = 9992
'  kA0DrawingSheetSize = 9993
'  kA1DrawingSheetSize = 9994
'  kA2DrawingSheetSize = 9995
'  kA3DrawingSheetSize = 9996
'  kA4DrawingSheetSize = 9997
'  k9x12InDrawingSheetSize = 9998
'  k12x18InDrawingSheetSize = 9999
'  k18x24InDrawingSheetSize = 10000
'  k24x36InDrawingSheetSize = 10001
'  k36x48InDrawingSheetSize = 10002
'  k30x42InDrawingSheetSize = 10003
'End Enum
'
   
oNewDoc.Sheets.Item(1).Size = kBDrawingSheetSize
     
'-----------------------------------
'
'[b]<--- NEED TO SET SHEET SIZE HERE -->    [/b]
'
'--------------------------------------
     
    'Post the filename to the private event queue.
    Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, sCurrentFilename)
       
    'Start the derived part command.
    Call oApp.CommandManager.StartCommand(kCreateDrawingViewCommand)

Case Else

ErrorSub:
    MsgBox "You must first have a Part or Assembly document open"

End Select

End Sub


_________________
George Radcliffe


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
POWERED_BY