Insertion of Part into a [weldment] Assembly via Macro at the part level
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on adding some macros that can run via a custom button when in the part environment. I have a similar system for inserting parts/assemblies directly into our specific drawing templates, so I figured slight modifications to code would accomplish this new behavior. I am gettin the appropriate weldment templates to open, however, I am gettin the error that I don't have a part open to insert (an error programmed in the macro). When stepping through the debug, I can see I am capturing the current part name, so I am pretty sure the issue is how I am handling the insertion into the actual assembly. For that matter, I know the CommandManager.StartCommand (kInsertPartCommand) is not correct. direction would be appreciated....here's the code (there's other stuff but this is the section I am concenred with):
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 sTemplateAssembly As String
If Units = "Metric" Then
sTemplateAssembly = "K:\R2016 Inventor\R2016 Templates\_RND\Metric Weldment.iam"
ElseIf Units = "Imperial" Then
sTemplateAssembly = "K:\R2016 Inventor\R2016 Templates\_RND\Std Weldment.iam"
End If
Select Case UseDefaultTemplate
Case True
Set oNewDoc = oApp.Documents.Add(kAssemblyDocumentObject, oApp.FileManager.GetTemplateFile(kAssemblyDocumentObject), True)
Case False
Set oNewDoc = oApp.Documents.Add(kAssemblyDocumentObject, sTemplateAssembly, True)
End Select
'Post the filename to the private event queue.
Call ThisApplication.CommandManager.PostPrivateEvent(kFileNameEvent, sCurrentFilename) '<---Pretty sure this works
'Start the insert part into the weldment assembly command.
Call oApp.CommandManager.StartCommand(kInsertPartCommand) '<----Pretty sure this is my issue
Case Else
ErrorSub:
MsgBox "You must first have a Part or Assembly document open"
End Select