Using Ilogic how to access Model Parameter that does not exist yet

Using Ilogic how to access Model Parameter that does not exist yet

Anonymous
Not applicable
820 Views
4 Replies
Message 1 of 5

Using Ilogic how to access Model Parameter that does not exist yet

Anonymous
Not applicable

Hello, 

 

I have inventor 2014 and am very new to programing but I am creating an ilogic program to my Standard part file that semi-automatically fills in the material details when a new part is created.  I am pretty far along but am stuck on one point.

 

The program determines the length width and height of the part automatically as well as the material shape\type, but on some parts I want to know the wall thickness as well.  What I was hoping to do is if such a part is created the user could just create a dimensions with an agreed upon name such as "dimH=5mm" in which case the program would recognize that the "dimH" model parameter now exists and to use it.  The problem I'm having is how to look for something that is not there yet, and it seems if I just don't declare it, it does not recognize that it is a model parameter until I open the editor and close it again.  If there is a way to directly change a user parameter when you are in the dimensioning box that would potentially also work , but I am unaware of how to do that either.  I'm sure this is something quite simple but I cannot seem to find it on the forum.  Any help or work around would be appreciated.

 

Thank you

 

Michael

0 Likes
Accepted solutions (1)
821 Views
4 Replies
Replies (4)
Message 2 of 5

J-Camper
Advisor
Advisor
Accepted solution

I'm not sure how much iLogic has changed from 2014, but here is a sample using Try/Catch:

Dim allParams As Parameters = ThisDoc.Document.ComponentDefinition.Parameters
Dim param1 As Inventor.Parameter
Dim findName As String = "dimH"

Try
	param1 = allParams.Item(findName)
	MessageBox.Show("Parameter: " & param1.Name & " was found to be: " & param1.Value, "Success")
Catch
	MessageBox.Show("Parameter: " & findName & " does not exist.  I will make the parameter", "Failure")
	param1 = allParams.UserParameters.AddByExpression(findName, "5 mm", "mm")
End Try

 

A Try/Catch is a form of error handling, and when a parameter exists you can call it using the name.  With these two together I Try to get a Parameter with a known name.  If the parameter exists, I can have it defined and can use it for whatever.  If the Parameter does not exist, the the code will read the Catch Portion, where I am Telling the user that the parameter is missing, and that it will be created.

 

Let me know if you have any questions, or if this is not working as intended.

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you for taking the time to respond back to me,  I believe this should work great but I am curious about one thing, the value that comes back seems to be consistently off by a factor of 10.  Its not a big deal so long as it is always off by 10 but curious as to why this is?  For example if the dimension is 250mm it will reply with 25.

 

Thanks again!

 

Dim allParams As Parameters = ThisDoc.Document.ComponentDefinition.Parameters
Dim param1 As Inventor.Parameter
Dim findName As String = "dimH"


Try


	param1 = allParams.Item(findName)
	MessageBox.Show("Parameter: " & param1.Name & " was found to be: " & param1.Value*10, "Success")


Catch
	
	
	myparam1 = InputBox("Please enter wall thickness in inches", "NO WALL THICKNESS DETECTED", "")
	param1 = allParams.UserParameters.AddByExpression(findName, myparam1, "in")


End Try


Dim param2 As Double = param1.Value*10
	

	MessageBox.Show(param2, "Title")

 

0 Likes
Message 4 of 5

J-Camper
Advisor
Advisor

Inventor handles all internal length calculations in centimeters, so that is the offset you are seeing.  It will also spit out radians instead of degrees if you start to get into angles.

0 Likes
Message 5 of 5

Anonymous
Not applicable

Makes sense,  Thank you again really appreciated!

0 Likes