Exposed property not working @ creating user parameters using Try .. Catch

Exposed property not working @ creating user parameters using Try .. Catch

RoyWickrama_RWEI
Advisor Advisor
218 Views
1 Reply
Message 1 of 2

Exposed property not working @ creating user parameters using Try .. Catch

RoyWickrama_RWEI
Advisor
Advisor

I am back using Inventor after a spell of two years.

I was dong easily with creating all my needs. But, today, I find that I can't get around creating the user parameters.

oPara.ExposedAsProperty = True

The exposed property not doing well.

I wasted so many hours without success. Please help Thanks.

Dim oPartDoc As PartDocument
'oPartDoc = ThisDoc.Document
oPartDoc = ThisApplication.ActiveDocument


' Get the UserParameters collection
Dim userParams As UserParameters
userParams = oPartDoc.ComponentDefinition.Parameters.UserParameters


Try
    oTest = Parameter("B_L2")
    Catch
    param = userParams.AddByExpression("B_L2", 0, UnitsTypeEnum.kFootLengthUnits)
    oParam = oPartDoc.ComponentDefinition.Parameters.Item("B_L2") 
    oParam.Units = "ft"
    oParam.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
End Try

iLogicVb.UpdateWhenDone = True

For Each oPara In oPartDoc.ComponentDefinition.Parameters
	oPara.ExposedAsProperty = True
	oPara.ShowUnitsString = True 
	oPara.ShowLeadingZeros = False
Next oPara

 

0 Likes
219 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @RoyWickrama_RWEI.  Not all parameters can be 'ExposedAsProperty'.  Text type and Boolean type (Yes/No) user parameters can not be exported or ExposedAsProperty right now.  Many have been requesting this ability for many years.  Also, in order to change some of those settings that apply to the custom property, you must first ensure that the parameter is ExposedAsProperty.  If the parameter is not already ExposedAsProperty, then attempting to change those settings will fail and/or throw an error.

Here is an example iLogic rule for looping through all user parameters and using a Try...Catch block to expose all parameters a certain way.  You can change this as needed.

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
oPDef = oPDoc.ComponentDefinition
Dim oUParams As UserParameters = oPDef.Parameters.UserParameters
For Each oUParam As UserParameter In oUParams
	Try
		oUParam.ExposedAsProperty = True
		oUParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
		oUParam.CustomPropertyFormat.Units = "in"
		oUParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kEightDecimalPlacesPrecision
		'oUParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision 'only when kTextPropertyType
		'oUParam.CustomPropertyFormat.ShowUnitsString = True 'only when kTextPropertyType
		'oUParam.CustomPropertyFormat.ShowLeadingZeros = False 'only when kTextPropertyType
		'oUParam.CustomPropertyFormat.ShowTrailingZeros = False 'only when kTextPropertyType
	Catch
		Logger.Error("ExposedAsProperty Failed for " & oUParam.Name)
	End Try
Next

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 :bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes