I made an iLogic rule which iterates through each of the components within an assembly and switches the design view to "Default" but when I attempt to run the rule in a weldment it errors out with "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))". I have tested the code in a normal assembly and it performs as I had expected.
I still have to add coding to add "Default" in event it doesn't exist but I want to first solve this error.
When I look at the logger for the information I requested I notice it is looking at the weldment itself as an occurrence, then attempts to set the design view then errors out. Is this being done because it is a weldment?
The code I am using is below and I have added a test weldment.
Thanks
Dim oAssyDoc As AssemblyDocument oAssyDoc = ThisApplication.ActiveDocument Dim oAssyCompDef As ComponentDefinition oAssyCompDef = oAssyDoc.ComponentDefinition Dim oOccurrences As ComponentOccurrences oOccurrences = oAssyCompDef.Occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oOccurrences Logger.Info(oOcc.DefinitionDocumentType) If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Logger.Info(oOcc.BOMStructure) Logger.Info(oOcc.Name) oOcc.SetDesignViewRepresentation("Default", , True) Logger.Info("Confirm If") End If Next
Solved! Go to Solution.
I made an iLogic rule which iterates through each of the components within an assembly and switches the design view to "Default" but when I attempt to run the rule in a weldment it errors out with "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))". I have tested the code in a normal assembly and it performs as I had expected.
I still have to add coding to add "Default" in event it doesn't exist but I want to first solve this error.
When I look at the logger for the information I requested I notice it is looking at the weldment itself as an occurrence, then attempts to set the design view then errors out. Is this being done because it is a weldment?
The code I am using is below and I have added a test weldment.
Thanks
Dim oAssyDoc As AssemblyDocument oAssyDoc = ThisApplication.ActiveDocument Dim oAssyCompDef As ComponentDefinition oAssyCompDef = oAssyDoc.ComponentDefinition Dim oOccurrences As ComponentOccurrences oOccurrences = oAssyCompDef.Occurrences Dim oOcc As ComponentOccurrence For Each oOcc In oOccurrences Logger.Info(oOcc.DefinitionDocumentType) If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Logger.Info(oOcc.BOMStructure) Logger.Info(oOcc.Name) oOcc.SetDesignViewRepresentation("Default", , True) Logger.Info("Confirm If") End If Next
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
Your assumption that welds are seen as occurrences is correct. You can skip the welds like this:
Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyCompDef As ComponentDefinition = oAssyDoc.ComponentDefinition
Dim oOccurrences As ComponentOccurrences = oAssyCompDef.Occurrences
For Each oOcc As ComponentOccurrence In oOccurrences
If (oOcc.Definition.Type = ObjectTypeEnum.kWeldsComponentDefinitionObject) Then
Dim weldOccDefinition As WeldsComponentDefinition = oOcc.Definition
' This is impossible ;-)
' weldOccDefinition.SetDesignViewRepresentation("Default", , True)
MsgBox("Found a weld lets continue to the next oOcc")
Continue For
End If
logger.Info(oOcc.DefinitionDocumentType)
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
logger.Info(oOcc.BOMStructure)
logger.Info(oOcc.Name)
oOcc.SetDesignViewRepresentation("Default", , True)
logger.Info("Confirm If")
End If
Next
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Your assumption that welds are seen as occurrences is correct. You can skip the welds like this:
Dim oAssyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssyCompDef As ComponentDefinition = oAssyDoc.ComponentDefinition
Dim oOccurrences As ComponentOccurrences = oAssyCompDef.Occurrences
For Each oOcc As ComponentOccurrence In oOccurrences
If (oOcc.Definition.Type = ObjectTypeEnum.kWeldsComponentDefinitionObject) Then
Dim weldOccDefinition As WeldsComponentDefinition = oOcc.Definition
' This is impossible ;-)
' weldOccDefinition.SetDesignViewRepresentation("Default", , True)
MsgBox("Found a weld lets continue to the next oOcc")
Continue For
End If
logger.Info(oOcc.DefinitionDocumentType)
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
logger.Info(oOcc.BOMStructure)
logger.Info(oOcc.Name)
oOcc.SetDesignViewRepresentation("Default", , True)
logger.Info("Confirm If")
End If
Next
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Thanks for the help!
Thanks for the help!
Can't find what you're looking for? Ask the community or share your knowledge.