Error unfolding parts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a few issues with the code below. It's meant to loop through each sheet metal document
- Unfold it if no flat pattern exists
- Go into the edit flat pattern environment if a flat pattern does exist
- Do something to the flat pattern then exit the flat pattern (I've left this bit out of the code as its not where the problem is)
When I start a new session of Inventor, open an assembly that contains sheet metal parts and run the rule. I'll get an unspecified error (Exception from HRESULT blah blah blah) on the first sheet metal document my loop encounters.
If I then manually open each sheet metal part in the model then close them (without saving) and run the rule again, it works with no errors. What does opening and closing them change?
After that's solved, the next issue... if a flat pattern doesn't exist, it will open that part in a new window. How can I prevent that? or at least close the part if it must open it to create the flat pattern
And lastly... my ribbon bar in the assembly changes to the flat pattern one (see attached image). I need to open another window then return to the assembly for it to revert back.
' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get all of the referenced documents. Dim oRefDocs As DocumentsEnumerator oRefDocs = oAsmDoc.AllReferencedDocuments ' Iterate through the list of documents. Dim oRefDoc As Document ' Check for a non-part document If oAsmDoc.DocumentType <> kAssemblyDocumentObject Then MsgBox ("The Active document must be an 'Assembly'!") Exit Sub End If ' Iterate through all referenced documents beneath the active assembly For Each oRefDoc In oRefDocs ' Define summary property set of part oSummaryPropertySet = oRefDoc.PropertySets.Item("Inventor Document Summary Information") If oSummaryPropertySet.Item("Category").Value = "Sheet Metal Part" Then ' Set reference to document component definition Dim oCD As SheetMetalComponentDefinition = oRefDoc.ComponentDefinition ' Create flat pattern if none If Not oCD.HasFlatPattern() Then oCD.Unfold() Else ' Edit flat pattern oCD.FlatPattern.Edit() End If 'Perform action on flat pattern then exit flat pattern End If Next