Set Custom IProperty as Parameter Value

Set Custom IProperty as Parameter Value

mark_haustein
Explorer Explorer
4,200 Views
4 Replies
Message 1 of 5

Set Custom IProperty as Parameter Value

mark_haustein
Explorer
Explorer

I've created a rule in a part file to see if a Parameter called "Length" exists.  If so, a Custom iProperty is created called "Length" that has the value of the Length Parameter.  I've got a trigger set to run this rule before save.  It doesn't appear to work at first.  A custom iProperty is created, but it has no value and has a Text type.  If I delete this property and edit my rule and directly from there "save and run", it creates the custom iProperty as I'm wanting (value shows up as Number type).

 

I've tried working on this most of the day and have gotten two different versions of code to do the same thing. 

 

Parameter.Quiet = True

If Parameter(ThisDoc, "Length") Then
		iProperties.Value("Custom", "Length") = Length
End If

 

Dim oParam As Parameters
oParam = ThisDoc.Document.ComponentDefinition.Parameters

Parameter.Quiet = True

If Parameter(oParam, "Length") Then
		iProperties.Value("Custom", "Length") = Length
End If

What should i change to get it to create the custom iProperty correctly? 

 

I'd also like to see what the units are for my Length parameter.  It will be either inches or mm.  Is there a way to pull that value and set it as a custom iProperty as well?  I haven't had any luck creating the code for this. 

 

Thanks

 

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

Ralf_Krieg
Advisor
Advisor

Hello

 

Forget this, take a look at the ExposedAsProperty property of an user parameter and the export options available to this export.

 

Or, if you only want to export this parameter, you don't need iLogic. Take a look at the second chapter

https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-E1276A10-1DB0-4AF5-8E4B-EF7E99E50D59

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 5

WCrihfield
Mentor
Mentor
Accepted solution

The manual process explained at the link that @Ralf_Krieg provided, is the simplest, easiest way to do what you seem to be trying to do.   However, if you still want to know how to do this using an iLogic rule, there are multiple ways to do it.

One way is like this:

oDV = Length
iProperties.Value("Custom", "Length") = Parameter("Length")

In that rule, since this is a 'local' rule (saved within the part) the word Length will turn blue (by default), indicating that it is recognized as a local parameter.  The presence of that in the rule, will cause this rule to be triggered to run any time the value of that parameter changes.  The second line, then causes the value of that custom iProperty to be updated to the value of that parameter.  Again, this code will only work as a local rule.

Another way do to it using an iLogic rule is to actually set that 'exposed as property' property to True, by code, which is arguably the better and more proper way to do it.

Dim oPDoc As PartDocument = ThisDoc.Document
Dim oParam As Inventor.Parameter = oPDoc.ComponentDefinition.Parameters.Item("Length")
If Not oParam.ExposedAsProperty Then
	oParam.ExposedAsProperty = True
	Dim oCPF As CustomPropertyFormat = oParam.CustomPropertyFormat
	'<<<< CHANGE ANY OF THESE AS NEEDED >>>
	oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
	oCPF.Units = "in" 'for Inches
	oCPF.Precision = CustomPropertyPrecisionEnum.kEightDecimalPlacesPrecision 
End If

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

mark_haustein
Explorer
Explorer

Thanks @Ralf_Krieg and @WCrihfield for the help on this.  I've added the "more proper" code to a template file.  I did add another If statement to check if the "Length" parameter was there, because we won't always use it.  Thanks both of you for the help on this. 

 

Parameter.Quiet = True
Dim oPDoc As PartDocument = ThisDoc.Document
If Parameter(oPDoc, "Length") Then
Dim oParam As Inventor.Parameter = oPDoc.ComponentDefinition.Parameters.Item("Length")
If Not oParam.ExposedAsProperty Then
	oParam.ExposedAsProperty = True
	Dim oCPF As CustomPropertyFormat = oParam.CustomPropertyFormat
	oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
	oCPF.Units = "in" 'for Inches
	oCPF.Precision = CustomPropertyPrecisionEnum.kFourDecimalPlacesPrecision 
End If
End If
0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Glad we could help.

By the way, I think you will need to change the way you are checking for that parameter.  The way you have it, I believe it will still throw an error when it is not found.  The two most popular ways to check if a specific named parameter exists are by either enclosing the line where you try to get that parameter within a Try...Catch block, or by looping through all parameters for one whose name matches.

Here's the Try...Catch version:  (within the Catch, you could also create the parameter, if you wanted to)

 

Parameter.Quiet = True
Dim oPDoc As PartDocument = ThisDoc.Document
Dim oParam As Inventor.Parameter
Try
	oParam = oPDoc.ComponentDefinition.Parameters.Item("Length")
Catch
	MsgBox("The parameter 'Length' was not found.  Exiting.", , "")
	Exit Sub 'or Return
End Try
If Not oParam.ExposedAsProperty Then
	oParam.ExposedAsProperty = True
	Dim oCPF As CustomPropertyFormat = oParam.CustomPropertyFormat
	oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
	oCPF.Units = "in" 'for Inches
	oCPF.Precision = CustomPropertyPrecisionEnum.kFourDecimalPlacesPrecision 
End If

 

  And here is an example showing one (of multiple) way to use a loop to check:

 

Parameter.Quiet = True
Dim oPDoc As PartDocument = ThisDoc.Document
For Each oParam As Inventor.Parameter In oPDoc.ComponentDefinition.Parameters
	If oParam.Name = "Thickness" Then
		If Not oParam.ExposedAsProperty Then
			oParam.ExposedAsProperty = True
			Dim oCPF As CustomPropertyFormat = oParam.CustomPropertyFormat
			oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
			oCPF.Units = "in" 'for Inches
			oCPF.Precision = CustomPropertyPrecisionEnum.kFourDecimalPlacesPrecision 
		End If
	End If
Next

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)