Unspecified Error When Attempting To Suppress Component In Subassembly Model State
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi! I keep running into an unspecified error when trying to use this loop to suppress components in a subassembly. I'm having trouble diagnosing the exact issue because the error is unspecified. This is my first time working with Model States using Inventor Programming so I think it may be related to that but I'm not sure.
So to start, I have this loop in my main() subroutine:
Sub Main() ' Get the assembly component definition Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisDoc.ModelDocument.ComponentDefinition ' Loop through each occurrence in the assembly Dim asmOcc As ComponentOccurrence Dim asmDoc As Document For Each asmOcc In oAsmCompDef.Occurrences asmDoc = asmOcc.Definition.Document If asmOcc.DefinitionDocumentType = kAssemblyDocumentObject And asmDoc.IsModifiable = True Then ' Get the iProperty description of the current occurrence Dim occDescription As String = asmOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Description").Value If needsSTP(occDescription) Then 'MsgBox(asmOcc.Name) ' Create STP model representation, suppress non-pipe features, export assembly Call createSTEPModelState(asmOcc) Dim destinationPath As String = getSTPAddress(IO.Path.GetFileNameWithoutExtension(asmOcc.Definition.Document.FullFileName)) 'MsgBox(destinationPath) Call suppressNonPipe(asmOcc) Call exportAsSTP(asmOcc, destinationPath) asmOcc.ActiveModelState = "[Primary]" End If End If Next asmOcc End Sub
The needsSTP function simply compares the description against an array of keywords and identifies if the description contains any of the key words. The getSTPAddress is a helper function that takes the address of the file being examined and creates a save location file address.
createSTEPModelState is the subroutine I'm using to create an alternate Model State for STEP exporting:
Sub createSTEPModelState(ByVal oOcc As ComponentOccurrence) Dim oDoc As AssemblyDocument = oOcc.Definition.Document Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim oModelStates As ModelStates Dim stepState As ModelState oModelStates = oDoc.ComponentDefinition.ModelStates Try stepState = oCompDef.ModelStates.Item("STEP") oOcc.ActiveModelState = stepState.Name Catch stepState = oCompDef.ModelStates.Add("STEP") oOcc.ActiveModelState = stepState.Name End Try End Sub
Lastly, here is the subroutine I'm using to suppress components:
Sub suppressNonPipe(ByVal oOcc As ComponentOccurrence) If oOcc.ActiveModelState = "STEP" Then Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = oOcc.Definition.Document.ComponentDefinition ' Loop through each occurrence in the assembly Dim asmOcc As ComponentOccurrence Dim asmDoc As Document For Each asmOcc In oAsmCompDef.Occurrences asmDoc = asmOcc.Definition.Document ' Get the iProperty description of the current occurrence Dim occDescription As String = asmOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Description").Value Try asmOcc.Suppress Catch MsgBox(asmOcc.Name & " cannot be suppressed!") End Try Next asmOcc Else MsgBox("The model state is not set for STEP files!") End If End Sub
I am running into issues with the asmOcc.Suppress line, where I am consistently getting the Catch statement MsgBox. I'm able to create the alternate model state, save as a STEP file, and return to the primary model state just fine, the only issue is with part suppression. The intent of the entire rule is to loop through the subassemblies of a top-level assembly and identify if they need to be exported (hence the needsSTP function), then if so go into that subassembly, create the alternate model state, suppress components not desired for the STEP export (anything without "PIPE" in the description), then export the subassembly as a .STP and return to the original ([Primary]) model state. All of this works for the suppression and I'm not sure why. The files are modifiable and I'm able to manually suppress the components.