Controlling positional rep of IAM within subassembly

Controlling positional rep of IAM within subassembly

Electrik
Advocate Advocate
283 Views
1 Reply
Message 1 of 2

Controlling positional rep of IAM within subassembly

Electrik
Advocate
Advocate

I'm using the following code to change a positional rep of an IAM within my model, based on the LoadDia variable:

Dim oOcc As ComponentOccurrences = ThisApplication.ActiveDocument.ComponentDefinition.Occurrences
Dim oPos As ComponentOccurrence
oPos = oOcc.ItemByName("1166964:2")
oPos.ActivePositionalRepresentation = LoadDia

It's working great. However, now, I want to change the positional rep of a Subassy within another IAM (as if the original IAM had been demoted). I would think my third line simply changes to reflect the new, demoted relationship:

 

oPos = oOcc.ItemByName("MA Auto FRAME SUB:1", "1166964:1"

 No such luck. Various attempts give me errors like: 

Too many arguments to 'Public ReadOnly Property ItemByName(Name As String) As Inventor.ComponentOccurrence'.

or Cannot convert to String

 

Please let me know if this can be done. Thanks!

Inventor Professional 2021
Vault Professional 2021
0 Likes
284 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

Hi @Electrik 

 

Edit: incorrectly referenced a part being looked for when in fact it is a sub assembly. 

 

Your assembly in the sub assembly cannot be reached from simply the occurrences of the top level assembly. That will only go one level deep. You need to get to the sub assembly sub occurrences. 

 

In ilogic editor manually you can add the subassembly your working with and that will add the path to get to it.

 

Alternatively you can get the sub assembly occurrence and then loop through the sub occurrences looking for the subassembly by name. The loop is required due to it only accepting an index value. 

 

There might be more to this process but maybe try those too methods first..

 

Working rule. If you need to go deeper then a recursion rule would be better. 

Dim occ As ManagedComponentOccurrence = Components.Item("Assembly2:1")
For Each subocc As ComponentOccurrence In occ.Occurrence.SubOccurrences
	If subocc.Name = "AssemblyNew:1" Then
		MessageBox.Show(occ.Name, "Title")
		subocc.ActivePositionalRepresentation = "Position1"
	End If
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes