iLogic List Checks

iLogic List Checks

DRoam
Mentor Mentor
3,904 Views
6 Replies
Message 1 of 7

iLogic List Checks

DRoam
Mentor
Mentor

I'd like to find some iLogic code that will do three things:

 

1. I'd like some code that will check if a value is in a MultiValue parameter list (or an ArrayList variable).

 

I've tried using [list name].Contains([desired value]), but it always returns false even if the value IS in the list. I've tried this with MultiValue parameters as well as ArrayList variables.

 

Right now I'm using:

 

 

foundvalue = MultiValue.FindValue("MultiValue.List("[list name]"), "=", [desired value])

If foundvalue = [desired value] Then
      'The value is in the MultiValue list
Else
      'The value is not in the MultiValue list
End If

It works, but I'd much rather use a single line that will return true if it's in the list or false if it's not.

 

 

2. I'd like some code that will compare two lists (whether MultiValue parameters or ArrayLists or mixed) and indicate if they are identical or not.

 

3. I'd like some code that will check if a Parameter is a MultiValue parameter at all.

 

Thanks for any suggestions!

 

0 Likes
Accepted solutions (2)
3,905 Views
6 Replies
Replies (6)
Message 2 of 7

Curtis_Waguespack
Consultant
Consultant

Hi DRoam,

 

I think you'll need to use a For Each statement. Here are some links that contain examples:

http://forums.autodesk.com/t5/inventor-general-discussion/how-to-create-a-rule-in-ilogic/m-p/3419793...

http://forums.autodesk.com/t5/inventor-general-discussion/how-to-remove-custom-iproperty-with-ilogic...

 

http://inventortrenches.blogspot.com/2014/03/ilogic-delete-custom-iproperties.html

 

If those don't help I'll try to look at this again tomorrow as well.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

EESignature

0 Likes
Message 3 of 7

DRoam
Mentor
Mentor

Thanks for the help, Curtis.

 

I'm still having the problem where the "contains" check always returns false, even if the value IS in the list.

 

Please see the attached part (Inv 2016) that's exibiting this behavior for me. All it contains is a multivalue parameter with the values 1 through 3, and an iLogic rule that checks for the values 1 through 3. If it goes the same for you as for me, you'll see three messages pop up saying each value wasn't found.

 

What am I doing wrong?

0 Likes
Message 4 of 7

Curtis_Waguespack
Consultant
Consultant

Hi DRoam,

Can you post the iLogic code? I don't have 2016 installed on this system.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 5 of 7

DRoam
Mentor
Mentor

Sure, sorry about that.

 

Dim MyListVar As New ArrayList

MyListVar = MultiValue.List("MyListParam")

For i=1 To 3
	If MyListVar.Contains(i) Then
		MessageBox.Show("Success! Found the value """ & i & """ in the list!", "Success!",MessageBoxButtons.OK)
	Else
		MessageBox.Show("Failure! Value """ & i & """ not found in the list!", "Failure!",MessageBoxButtons.OK,MessageBoxIcon.Error)
	End If
Next i
0 Likes
Message 6 of 7

MegaJerk
Collaborator
Collaborator
Accepted solution

Ah, the lovely ‘gotchas’ of Multivalue Lists.

Long story short, you’re looking for the wrong ‘type’ of value. Use the code below, and read the explanation just beyond for more learning and extra credit.

Dim MyListVar As New ArrayList()
MyListVar = MultiValue.List("MyListParam")

For i=1 To 3
	''' UNCOMMENT THE BELOW CODE TO SEE THE 'TYPE'
	''' OF THE ACTUAL OBJECT STORED IN THE POSITION
	''' (i-1) OF THE MyListVar PARAMETER! 
	''MessageBox.Show(TypeName(MyListVar(i-1)))
	
	If MyListVar.Contains(CStr(i)) Then
		MessageBox.Show("Success! Found the value """ & i & """ in the list!", "Success!",MessageBoxButtons.OK)
	Else
		MessageBox.Show("Failure! Value """ & i & """ not found in the list!", "Failure!",MessageBoxButtons.OK,MessageBoxIcon.Error)
	End If
Next i



Alright, so what that iLogic function isn’t telling you is that the ArrayList is being built from the ExpressionList object that is attached to the MultiValue Property.

PICTURE TIME! :

 

MultiValueExpList.PNG

 

----------------

An Expression is a string that can be interpreted as just a mathematical value or formula that shakes down to a value, and so in this case, the ExpressionList is just a collection of String Objects (or Variants according to the debug window).

What the ‘MultiValue.List(“Parameter”) does is take all of those Variant / String values, adds them to an ArrayList, and then sends that entire ArrayList back into whatever called it. In this case, it’s the MyListVar that you have declared.

When you ask it to check whether or not the value of “i” is inside of that ArrayList, it looks for an INTEGER value because ‘i’ was assigned a numeric value at the start of the For loop. Because the ArrayList contains only Strings, it wouldn’t be able to find any match and would return false.

Converting the value of ‘i’ into a String beforehand (as I have done in my code) clears up the issue! And now hopefully, this mystery should also be a bit more clear to you as well!

-----------

Question on my mind : Why would you like to search through the Multivalue list in this way? Are you worried about users inputting their own ‘non-standard’ values? Just curious



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 7 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi DRoam,

 

In addtion to MegJerk's info, have a look at the attached file for some examples.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature