
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have spent a couple of days working on automating a couple of redundant tasks in an engineering workflow using inventor iLogic. At this point I'm stumped.
Here is my goal:
From IDW:
-> Open first view assembly
-> Iterate through assembly finding all components with a custom "CNC" iProp
-> Open our assembly template
-> Save the blank template in our CNC folder
-> Add only parts with "CNC" iProp to the new CNC assembly
-> Save assembly and close
Basically everything works so far (mostly a Frankenstein of code found on here, cheers to all unknown contributors) besides the line that actually adds the component.
I went this rout because since typically 5% of parts are CNC parts, it would be faster to create a new assembly then to save a copy and delete out all of the other parts.
Thoughts appreciated.
Thanks,
Funnybus
If System.IO.File.Exists(oCNCPath & oCNCName) Then oFileCheck = MessageBox.Show(oCNCPath & oCNCName & " already exists." & vbLf & vbLf & "Do you want to replace it?", "Confirm Save As", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) If oFileCheck = vbYes Then 'CREATE CNC End If Else oOldDoc = ThisApplication.Documents.Open(oAsmTemp, False) Dim oNewPath As String= oCNCPath & oCNCName oOldDoc.saveas(oNewPath, True) oOldDoc.Close() Dim oNewDoc As AssemblyDocument = ThisApplication.Documents.Open(oNewPath, False) TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, oNewDoc.ComponentDefinition.Occurrences, 1) oNewDoc.Close() End If
Private Sub TraverseAssembly(oAssyDocOccurrences As ComponentOccurrences, oNewDocOccurrences As ComponentOccurrences, Level As Integer) Dim oOcc As ComponentOccurrence Dim oOccName As String Dim oCNC As String For Each oOcc In oAssyDocOccurrences Try oCNC = oOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("CNC").Value If oCNC = "CNC" oOccName = oOcc.Definition.Document.FullFileName MessageBox.Show(oOccName) oNewDocOccurrences.Add(oOccName) End If Catch 'No Error End Try If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Call TraverseAssembly(oOcc.SubOccurrences, oNewDocOccurrences, Level + 1) End If Next End Sub
Solved! Go to Solution.