Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add a view representation

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Cosmin_V
433 Views, 4 Replies

Add a view representation

Cosmin_V
Advocate
Advocate

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?

0 Likes

Add a view representation

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?

4 REPLIES 4
Message 2 of 5
FINET_Laurent
in reply to: Cosmin_V

FINET_Laurent
Advisor
Advisor
Accepted 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"

@LinkedIn     @JohnCockerill

0 Likes

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"

@LinkedIn     @JohnCockerill

Message 3 of 5
Cosmin_V
in reply to: FINET_Laurent

Cosmin_V
Advocate
Advocate

Tanks @FINET_Laurent 

 

It works for some parts in the first assembly, but after that an error occurs on line 39

oOcc.Visible = False

 

0 Likes

Tanks @FINET_Laurent 

 

It works for some parts in the first assembly, but after that an error occurs on line 39

oOcc.Visible = False

 

Message 4 of 5
FINET_Laurent
in reply to: Cosmin_V

FINET_Laurent
Advisor
Advisor
Accepted solution

@Cosmin_V , 

 

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"

@LinkedIn     @JohnCockerill

0 Likes

@Cosmin_V , 

 

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"

@LinkedIn     @JohnCockerill

Message 5 of 5
Cosmin_V
in reply to: FINET_Laurent

Cosmin_V
Advocate
Advocate

@FINET_Laurent 

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.

0 Likes

@FINET_Laurent 

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.

Post to forums  

Autodesk Design & Make Report