iLogic: working with Collection(Item)

iLogic: working with Collection(Item)

Allen_Hart
Advocate Advocate
1,549 Views
6 Replies
Message 1 of 7

iLogic: working with Collection(Item)

Allen_Hart
Advocate
Advocate

I had one version of this working using ArrayList and  a For Each loop. 

This version tries to avoid the loop by using a keyed collection. But it seems "i" is not being set.

Why does this code not work?  I'm sure it's something stoopid on my part, but I can't see it.

Class Clip
	Property clipLeg1 As Double
	Property clipLeg2 As Double
	Property clipThickness As Double
	Property clipDescription As String
	
	Sub New(L1 As Double, L2 As Double, T As Double, D As String)
		clipLeg1 = L1
		clipLeg2 = L2
		clipThickness = T
		clipDescription = D
	End Sub
	
End Class

Sub Main()
	
	Dim ClipList As New Collection()	'items are accessable via "Key"
	With ClipList
		.Add(New Clip(1.75, 1.0, 0.125, "1-3/4 x 1 x 1/8 Angle"), "158262")
		.Add(New Clip(2.0, 1.5, 0.125, "2 x 1-1/2 x 1/8 Angle"), "17338")
		.Add(New Clip(2.0, 0.75, 0.125, "2 x 3/4 x 1/8 Angle"), "205621")
		.Add(New Clip(1.5, 0.75, 0.125, "1-1/2 x 3/4 x 1/8 Angle"), "5137")
		.Add(New Clip(2.0, 1.0, 0.125, "2 x 1 x 1/8 Angle"), "6844")
		.Add(New Clip(1.0, 0.75, 0.125, "1 x 3/4 x 1/8 Angle"), "7385")
		.Add(New Clip(1.5, 1.0, 0.125, "1-1/2 x 1 x 1/8 Angle"), "7613")
		.Add(New Clip(0.75, 0.75, 0.125, "3/4 x 3/4 x 1/8 Angle"), "79a")
		.Add(New Clip(1.0, 1.0, 0.125, "79g, 1 x 1 x 1/8 Angle"), "79g")
		.Add(New Clip(1.25, 1.25, 0.125, "1-1/4 x 1-1/4 x 1/8 Angle"), "79t")
		.Add(New Clip(1.5,1.5,0.125,"1-1/2 x 1-1/2 x 1/8 Angle"), "79v")
	End With
	
	'get value of selection parameter
	Dim p = Parameter.Param("CLIP_TAG")

	'get selection from ClipList
	Dim i As Clip = ClipList(p.Value)
	
	Parameter("CLIP_LEG1") = i.clipLeg1
	Parameter("CLIP_LEG2") = i.clipLeg2
	Parameter("CLIP_THK") = i.clipThickness
	iProperties.Value("Project", "Description") = p.Value & ", " & i.clipDescription
	Parameter.Param("CLIP_TAG").Comment = "L" & 
		CStr(i.clipLeg1) & " x " & 
		CStr(i.clipLeg2) & " x " &
		CStr(i.clipThickness)
	
ThisApplication.ActiveDocument.Update

End Sub

 

0 Likes
Accepted solutions (1)
1,550 Views
6 Replies
Replies (6)
Message 2 of 7

Allen_Hart
Advocate
Advocate

Should have attached the ipt that goes with this code.

Allen

 

0 Likes
Message 3 of 7

J-Camper
Advisor
Advisor

I'm not having any issue with this part/rule.  I can change the list value of the "CLIP_TAG" parameter and watch the part parameters update.  I checked a few of the options and the parameters seem to match what the rule says to make them. 

 

I can't re-create a failure.  What does your error message say?  Is it persistent if you restart the program/computer?

0 Likes
Message 4 of 7

Allen_Hart
Advocate
Advocate

Thanks for looking.  I'm not getting any error. It just doesn't update at all. 

I have restarted Inventor, but not the pc. will try it.

Allen

 

0 Likes
Message 5 of 7

Allen_Hart
Advocate
Advocate

PC restart didn't help. 

Oddly; I select an item and nothing happens, then open the code, pick Save & Run, it will update with the last selected item. Can do this over and over. Just won't update as I select.

😞 Allen

 

0 Likes
Message 6 of 7

J-Camper
Advisor
Advisor
Accepted solution

That is weird, I opened the Old Versions file to see if I did something in my first look through the rule and I'm seeing what you are seeing now.  I didn't actually save any changes to the rule before so I'm not sure why it was working for me earlier.  I added 1 line at the beginning of the  Sub Main and I'm getting the instant change again.

 

Make this the first line of Sub Main:

Dim Activate As String = CLIP_TAG

This should work for the rule as long as it remains local to the document.  When a parameter referenced in a local rule gets updated iLogic triggers the containing rule to run.

 

 

0 Likes
Message 7 of 7

Allen_Hart
Advocate
Advocate

Well, that did the trick. Thanks!

Allen

 

0 Likes