Hi everbody,
I put together lines of code from the forum, but something doesn't work right.
I want to make an external rule that will make invisible all the parts in all the subassemblies, except for those in "Reference".
So I can see only the parts in "Reference" in the entire structure of the assembly.
And add this to a new view representation
In my code this happens, but only to the parts that are in the top assembly. All the rest that are in other assemblies and subassemblies become invisible.
'define current document Dim openDoc As Document openDoc = ThisDoc.Document 'this assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'look at all of the components in the assembly Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition 'define view rep Dim oViewRep As DesignViewRepresentation 'define an arraylist to hold the list of view rep names Dim NameList As New ArrayList() 'check to see if the arraylist contains the desired view rep Try oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts") Catch NameList.Contains("Reference parts") If Not NameList.Contains("Reference parts") Then oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Reference parts") oViewRep.Activate Else If NameList.Contains("Reference parts") Then oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts") oViewRep.Activate End If End Try 'zoom all ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute 'Turn visibility of if.... For Each oOcc As ComponentOccurrence In oCompDef.Occurrences If oOcc.BOMStructure = BOMStructureEnum.kNormalBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kInseparableBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then oOcc.Visible = False End If If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then oOcc.Visible = True End If Next ThisApplication.ActiveView.Update() oViewRep.Locked = True
Can somebody help me to finish this?
Solved! Go to Solution.
Hi everbody,
I put together lines of code from the forum, but something doesn't work right.
I want to make an external rule that will make invisible all the parts in all the subassemblies, except for those in "Reference".
So I can see only the parts in "Reference" in the entire structure of the assembly.
And add this to a new view representation
In my code this happens, but only to the parts that are in the top assembly. All the rest that are in other assemblies and subassemblies become invisible.
'define current document Dim openDoc As Document openDoc = ThisDoc.Document 'this assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'look at all of the components in the assembly Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition 'define view rep Dim oViewRep As DesignViewRepresentation 'define an arraylist to hold the list of view rep names Dim NameList As New ArrayList() 'check to see if the arraylist contains the desired view rep Try oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts") Catch NameList.Contains("Reference parts") If Not NameList.Contains("Reference parts") Then oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Reference parts") oViewRep.Activate Else If NameList.Contains("Reference parts") Then oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts") oViewRep.Activate End If End Try 'zoom all ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute 'Turn visibility of if.... For Each oOcc As ComponentOccurrence In oCompDef.Occurrences If oOcc.BOMStructure = BOMStructureEnum.kNormalBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kInseparableBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then oOcc.Visible = False End If If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then oOcc.Visible = True End If Next ThisApplication.ActiveView.Update() oViewRep.Locked = True
Can somebody help me to finish this?
Solved! Go to Solution.
Solved by FINET_Laurent. Go to Solution.
Solved by FINET_Laurent. Go to Solution.
Hi @Cosmin_V,
From a quick look I can see that when checking for the reference property, your are going trought the Occurrence collection. This collection represents - only - the top assemblies / parts in the browser. If you want to go deeper in the tree, going trough the part of a sub assembly for instance, you could instead use the Occurences.AllLeafOccurences collection instead. This would instead go trough each individual part of the assembly, regardless of the type (top / sub assembly / sub part / ...). I did the fix on line 36:
'define current document
Dim openDoc As Document
openDoc = ThisDoc.Document
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition
'define view rep
Dim oViewRep As DesignViewRepresentation
'define an arraylist to hold the list of view rep names
Dim NameList As New ArrayList()
'check to see if the arraylist contains the desired view rep
Try
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts")
Catch
NameList.Contains("Reference parts")
If Not NameList.Contains("Reference parts") Then
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Reference parts")
oViewRep.Activate
Else If NameList.Contains("Reference parts") Then
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts")
oViewRep.Activate
End If
End Try
'zoom all
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
'Turn visibility of if....
For Each oOcc As ComponentOccurrence In oCompDef.Occurrences.AllLeafOccurrences
If oOcc.BOMStructure = BOMStructureEnum.kNormalBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Or
oOcc.BOMStructure = BOMStructureEnum.kInseparableBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then
oOcc.Visible = False
End If
If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
oOcc.Visible = True
End If
Next
ThisApplication.ActiveView.Update()
oViewRep.Locked = True
Can you give it a try ?
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"Hi @Cosmin_V,
From a quick look I can see that when checking for the reference property, your are going trought the Occurrence collection. This collection represents - only - the top assemblies / parts in the browser. If you want to go deeper in the tree, going trough the part of a sub assembly for instance, you could instead use the Occurences.AllLeafOccurences collection instead. This would instead go trough each individual part of the assembly, regardless of the type (top / sub assembly / sub part / ...). I did the fix on line 36:
'define current document
Dim openDoc As Document
openDoc = ThisDoc.Document
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'look at all of the components in the assembly
Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition
'define view rep
Dim oViewRep As DesignViewRepresentation
'define an arraylist to hold the list of view rep names
Dim NameList As New ArrayList()
'check to see if the arraylist contains the desired view rep
Try
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts")
Catch
NameList.Contains("Reference parts")
If Not NameList.Contains("Reference parts") Then
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Reference parts")
oViewRep.Activate
Else If NameList.Contains("Reference parts") Then
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Reference parts")
oViewRep.Activate
End If
End Try
'zoom all
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
'Turn visibility of if....
For Each oOcc As ComponentOccurrence In oCompDef.Occurrences.AllLeafOccurrences
If oOcc.BOMStructure = BOMStructureEnum.kNormalBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Or
oOcc.BOMStructure = BOMStructureEnum.kInseparableBOMStructure Or oOcc.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then
oOcc.Visible = False
End If
If oOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then
oOcc.Visible = True
End If
Next
ThisApplication.ActiveView.Update()
oViewRep.Locked = True
Can you give it a try ?
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"Tanks @FINET_Laurent
It works for some parts in the first assembly, but after that an error occurs on line 39
oOcc.Visible = False
Tanks @FINET_Laurent
It works for some parts in the first assembly, but after that an error occurs on line 39
oOcc.Visible = False
I can't debug the code for you. For this I would need all the assembly and the parts to test. Can you provide us with the files so we can test out ? A dirty fix would be to put the command in a try /catch and skip a beat if it fails :
Try
oOcc.Visible = False
Catch
Continue For
End Try
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"
I can't debug the code for you. For this I would need all the assembly and the parts to test. Can you provide us with the files so we can test out ? A dirty fix would be to put the command in a try /catch and skip a beat if it fails :
Try
oOcc.Visible = False
Catch
Continue For
End Try
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"There it will be something else...😁
Can somehow to turn back the visibility on the parts which are place in the "Reference" assemblies?
Because some of the subassemblies are in "reference" but has parts "Normal" and I want to see all pars in to this "reference" subassemblies.
There it will be something else...😁
Can somehow to turn back the visibility on the parts which are place in the "Reference" assemblies?
Because some of the subassemblies are in "reference" but has parts "Normal" and I want to see all pars in to this "reference" subassemblies.
Can't find what you're looking for? Ask the community or share your knowledge.