Determine Largest and second largest Parameter Values

Determine Largest and second largest Parameter Values

Anonymous
Not applicable
649 Views
5 Replies
Message 1 of 6

Determine Largest and second largest Parameter Values

Anonymous
Not applicable

I am trying to determine the 1st and 2nd largest values out of 3 parameters.  I am trying to use a nested if function to determine this, then write the values of the parameters to iProperties.  

 

This is what I have so far. 

 

If (ZDIM > XDIM) AndAlso (ZDIM > YDIM) Then
		iProperties.Value("Custom", "LENGTH")= Ceil(Parameter("ZDIM"))
		If YDIM>XDIM Then
				iProperties.Value("Custom", "WIDTH") = Ceil(Parameter("YDIM"))
			Else
				iProperties.Value("Custom", "WIDTH") = Ceil(Parameter("XDIM"))
		End If
		
	ElseIf (YDIM > XDIM) AndAlso (YDIM > ZDIM) Then
		iProperties.Value("Custom", "LENGTH")= Ceil(Parameter("YDIM"))
		If XDIM>ZDIM Then
				iProperties.Value("Custom", "WIDTH") = Ceil(Parameter("XDIM"))
			Else
				iProperties.Value("Custom", "WIDTH") = Ceil(Parameter("ZDIM"))
		End If
		
	ElseIf (XDIM > YDIM) AndAlso (XDIM > ZDIM) Then
		iProperties.Value("Custom", "LENGTH")= Ceil(Parameter("XDIM"))
		If YDIM>ZDIM Then
				iProperties.Value("Custom", "WIDTH") = Ceil(Parameter("YDIM"))
			Else
				iProperties.Value("Custom", "WIDTH") = Ceil(Parameter("ZDIM"))
		End If
End If

I don't get any errors, and no values are written to iProperties. 

0 Likes
Accepted solutions (1)
650 Views
5 Replies
Replies (5)
Message 2 of 6

HermJan.Otterman
Advisor
Advisor

you code works.

 

I tested it in Inventor 2017

 

At first I thought that it might not work, bacause of the "Ceil", to round parameters. They have to be unitless, but even with Units it worked.

 

my screencast : http://autode.sk/2n0ArSI

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 3 of 6

rhasell
Advisor
Advisor
Accepted solution

Hi

 

Try this.

 

Here is a bit of code I wrote for you. You can modify it as you wish.

 

Change the order to suit (0,1,2)

 

 

	Dim sizes As New List(Of Double)
			sizes.Add(Parameter("ZDIM"))
			sizes.Add(Parameter("XDIM"))
			sizes.Add(Parameter("YDIM"))
			sizes.Sort()
			Parameter("HEIGHT") = sizes(2)
			Parameter("WIDTH") = sizes(1)
			Parameter("LENGTH") = sizes(0)
Reg
2026.1
0 Likes
Message 4 of 6

Anonymous
Not applicable

That's very strange.   Nothing I do gets it to work.  The lines that write to iProperties work fine on their own, but once I add the if statements, nothing.  

0 Likes
Message 5 of 6

Anonymous
Not applicable

Beautiful.  I was trying to get to something like this, but dont have enough VBA experience to write it off-hand. 

 

I modified it slightly to write to iProperties instead of parameters.  

 

Dim sizes As New List(Of Double)
			sizes.Add(Ceil(Parameter("ZDIM")))
			sizes.Add(Ceil(Parameter("XDIM")))
			sizes.Add(Ceil(Parameter("YDIM")))
			sizes.Sort()
			iProperties.Value("Custom", "THICKNESS") = sizes(0)
			iProperties.Value("Custom", "WIDTH") = sizes(1)
			iProperties.Value("Custom", "LENGTH") = sizes(2)
0 Likes
Message 6 of 6

rhasell
Advisor
Advisor

Hi

 

My VBA skills are pretty poor as well.

 

The Help file has a lot of info and code snippets. Most of my code started out as cut and paste, I then debug it with message boxes and small snippets, I then adjust it to suit my needs.

 

Always glad to help.

 

 

Reg
2026.1
0 Likes