Change Design View Representation To Sub-Sub component

Change Design View Representation To Sub-Sub component

JhoelForshav
Mentor Mentor
481 Views
2 Replies
Message 1 of 3

Change Design View Representation To Sub-Sub component

JhoelForshav
Mentor
Mentor

Hi,

I'm having issues with changing the Design view representation of a part within a sub assembly of a sub assembly.

Basically i want to mimic the behaviour of right click browser node -> "Representation...".

representation.PNG

 

The code below runs with no error, yet the representation doesn't change.

Dim oDoc As AssemblyDocument = ThisDoc.Document
	Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	
	Dim oViewReps As DesignViewRepresentations = oCompDef.RepresentationsManager.DesignViewRepresentations
	
	Dim viewExists As Boolean = False
	For Each oRep As DesignViewRepresentation In oViewReps
		If oRep.Name = "NoGD" Then
			viewExists = True
			Exit For
		End If
	Next
	
	If viewExists = False Then
		Dim NoGDRep As DesignViewRepresentation = oViewReps.Add("NoGD")
		NoGDRep.Activate
		Dim oOcc As ComponentOccurrence

		For i = 1 To QtyRuns
			For j = 1 To Parameter("Run_" & i, "StepQty")
			Try
			oOcc = oCompDef.Occurrences.ItemByName("Run_" & i).Definition.Occurrences.ItemByName("StairStep_" & j).Definition.Occurrences.ItemByName("StepPlate")
			oOcc.SetDesignViewRepresentation("NoGD")
			MsgBox("Run_" & i & ".StairStep_" & j & " Works)
			Catch
				MsgBox("Run_" & i & ".StairStep_" & j & " Doesn't work")
			End Try
		Next
		Next
		NoGDRep.Locked = True
		oViewReps.Item("Default").Activate
		iLogicVb.UpdateWhenDone = True
	End If

From what i've read there seems to be a problem with this functionallity through API/iLogic for components on levels below first level.

There is a workaround presented in this thread:

https://forums.autodesk.com/t5/inventor-customization/design-view-representation-issue/td-p/7502910

But unfortunately this is not an option for me.

Does anybody here have a solution for the problem?

Thanks in advance,

Jhoel

 

Accepted solutions (1)
482 Views
2 Replies
Replies (2)
Message 2 of 3

JhoelForshav
Mentor
Mentor

After some further investigation I can see that the representation of the part changes in the subassembly that it belongs to. Just not at the top level assembly where i want it to change.

0 Likes
Message 3 of 3

JhoelForshav
Mentor
Mentor
Accepted solution

I actually managed to solve it. Thought i would post the solution here if anybody else has the same problem in the future.

I had to get the component in the context of the top level assembly so i used

oOcc = Component.InventorComponentInThisContext

I assume this is an iLogic function to create a proxy of the component in the assembly.

This function takes an ArrayList as a path to the object as argument.

The code now looks like this and it works like a charm.

Class ThisRule
	Sub Main()
	Dim oDoc As AssemblyDocument = ThisDoc.Document
	Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	
	Dim oViewReps As DesignViewRepresentations = oCompDef.RepresentationsManager.DesignViewRepresentations
	
	Dim viewExists As Boolean = False
	For Each oRep As DesignViewRepresentation In oViewReps
		If oRep.Name = "NoGD" Then
			viewExists = True
			Exit For
		End If
	Next
	
	If viewExists = False Then
		Dim NoGDRep As DesignViewRepresentation = oViewReps.Add("NoGD")
		NoGDRep.Activate
		Dim oOcc As ComponentOccurrence

		For i = 1 To QtyRuns
			For j = 1 To Parameter("Run_" & i, "StepQty")
			Try
			oOcc = Component.InventorComponentInThisContext(GetArrayList("Run_" & i & ".StairStep_" & j & ".StepPlate"))
			oOcc.SetDesignViewRepresentation("NoGD")
			Catch
			End Try
		Next
		Next
		NoGDRep.Locked = True
		oViewReps.Item("Default").Activate
		iLogicVb.UpdateWhenDone = True
	End If
	

	End Sub
Public Function GetArrayList(occPath As String) As ArrayList
		Dim oArrayList As New ArrayList 
		Dim oItems() As String = occPath.Split(".")
		For Each item In oItems
			oArrayList.Add(item)
		Next
		Return oArrayList
End Function
End Class