Help: iLogic Rule change Position (Representations) selected items

Help: iLogic Rule change Position (Representations) selected items

ngdnam88
Advocate Advocate
456 Views
4 Replies
Message 1 of 5

Help: iLogic Rule change Position (Representations) selected items

ngdnam88
Advocate
Advocate

Dears,

I have some sub-assemblies need to change the new one position in representations. I'm working with this Code. Please help me to correct it. Thanks you very much!

Dim oComponent As Object
Dim oComponents As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

While True
	oComponent = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Components")	
	If IsNothing(oComponent) Then Exit While	
	oComponents.Add(oComponent) 
End While

For Each oComponent In oComponents
	Dim sActivePosRep as String = oComponent.ComponentDefinition.RepresentationsManager.ActivePositionalRepresentation.Name
	Dim MyArrayList As New ArrayList
	For Each oPosRep In oComponent.ComponentDefinition.RepresentationsManager.PositionalRepresentations
		MyArrayList.Add(oPosRep.Name)
	Next
	iArrayList = MyArrayList.Count
		sPosRep = InputListBox("Select from the List:", MyArrayList, sActivePosRep, "iLogic", "Positional")
		oComponent.ComponentDefinition.RepresentationsManager.PositionalRepresentations.Item(sPosRep).Activate
Next
0 Likes
Accepted solutions (1)
457 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @ngdnam88.  You can give this version of your code a try if you want.  I assume you want to changes to effect what you see in the assembly, not within the component's individual model files, so I am working with the component's direct properties, instead of their definition model properties.  I also generally prefer to work with List type objects when possible, instead of ObjectCollection or ArrayList, because it is more specific to the object type, and are very convenient to use.

Dim oCompsList As New List(Of ComponentOccurrence)
Dim oComp As ComponentOccurrence
While True
	oComp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Components")	
	If IsNothing(oComp) Then Exit While	
	oCompsList.Add(oComp) 
End While
If oCompsList.Count = 0 Then Return
For Each oComp In oCompsList
	Dim sActivePosRep As String = oComp.ActivePositionalRepresentation
	Dim PosRepNames As New List(Of String)
	Dim oPosReps As PositionalRepresentations = oComp.ComponentDefinition.RepresentationsManager.PositionalRepresentations
	For Each oPosRep As PositionalRepresentation In oPosReps
		PosRepNames.Add(oPosRep.Name)
	Next
	If PosRepNames.Count < 1 Then Continue For
	Dim sPosRep As String = InputListBox("Select from the List:", PosRepNames, sActivePosRep, "iLogic", "Positional")
	If sPosRep = "" Then Continue For
	oComp.ActivePositionalRepresentation = sPosRep
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

ngdnam88
Advocate
Advocate

Thanks @WCrihfield ,

I'm trying your code, but I got an error:

 

ngnam1988_0-1662995898152.png

Maybe there's some incorrect code line. I'm studying your code. Thanks,

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Hi @ngdnam88.  Yes, that was my hasty mistake.  I forgot to change how I was setting the value of a variable in the code.

This line:

Dim oPosReps As PositionalRepresentations = oComp.ComponentDefinition.RepresentationsManager.PositionalRepresentations

...should have been like this:

Dim oPosReps As PositionalRepresentations = oComp.Definition.RepresentationsManager.PositionalRepresentations

...because a PartDocument or AssemblyDocument has the ComponentDefinition property, but a ComponentOccurrence object has the Definition property to return the same thing.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

ngdnam88
Advocate
Advocate

Thank you very much! @WCrihfield 

It's working very good now!

0 Likes