Inventor Customization

Reply
Valued Contributor
gary.belisle
Posts: 80
Registered: ‎07-29-2011
Message 1 of 16 (1,523 Views)
Accepted Solution

Custom Property Format in iLogic

1523 Views, 15 Replies
09-21-2011 01:08 PM

I would like to set the custom property format for all user paramters from an iLogic code. This is what I've come up with. It runs, but it does not seem to alter the custom property format. What am I doing wrong here?

 

 

DimoPartDocAsPartDocument
oPartDoc=ThisApplication.ActiveDocument

DimoParameterAsParameter

ForEachoParameterInoPartDoc.ComponentDefinition.Parameters
oParameter.ExposedAsProperty=True
ShowUnitString=True
ShowLeadingZeros=True
ShowTrailingZeros=False
Precision=kTwoDecimalPlacesPrecision
NextoParameter

 

---------------------------------------------------------------------
i7-2720QM Dell Precision M6600, Win 7 Pro 64-bit, 8GB RAM
Autodesk Product Design Suite Ultimate 2013
Autodesk Vault Professional 2013
Employee
xiaoyan.qi
Posts: 44
Registered: ‎08-01-2008
Message 2 of 16 (1,510 Views)

Re: Custom Property Format in iLogic

09-21-2011 07:47 PM in reply to: gary.belisle

Hi, Gary

 

here is the VBA code for your request

=============================

Sub ChangeFormat()
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.ActiveDocument
    Dim oParameter As Parameter
   
   
   
    For Each oParameter In oPartDoc.ComponentDefinition.Parameters.UserParameters
        Dim oFormat As CustomPropertyFormat
        Set oFormat = oParameter.CustomPropertyFormat
       
        oParameter.ExposedAsProperty = True
        oFormat.PropertyType = kTextPropertyType
 

        oFormat.Precision = kTwoDecimalPlacesPrecision
        oFormat.Units = "in"
       
        oFormat.ShowUnitsString = True
        oFormat.ShowLeadingZeros = True
        oFormat.ShowTrailingZeros = False

    Next oParameter

End Sub

================================

i tried in iLogic, in iLogic code, you need to change the enumeration to the related value, see my code below:

================================

Dim oPartDoc As PartDocument
    oPartDoc = ThisApplication.ActiveDocument
    Dim oParameter As Parameter
    Dim oFormat As CustomPropertyFormat
   
   
    For Each oParameter In oPartDoc.ComponentDefinition.Parameters.UserParameters
       
        oFormat = oParameter.CustomPropertyFormat
       
        oParameter.ExposedAsProperty = True

        oFormat.PropertyType = 85249


        oFormat.Precision = 85507
        oFormat.Units = "in"
       
        oFormat.ShowUnitsString = True
        oFormat.ShowLeadingZeros = True
        oFormat.ShowTrailingZeros = False

Next oParameter

====================================

 

let me know if it works

Thanks

Mick

Employee
xiaoyan.qi
Posts: 44
Registered: ‎08-01-2008
Message 3 of 16 (1,504 Views)

Re: Custom Property Format in iLogic

09-22-2011 12:26 AM in reply to: gary.belisle

update the iLogic code

==================================

DimoPartDocAsPartDocument
oPartDoc=ThisApplication.ActiveDocument
DimoParameterAsParameter
DimoFormatAsCustomPropertyFormat
ForEachoParameterInoPartDoc.ComponentDefinition.Parameters.UserParameters
oFormat=oParameter.CustomPropertyFormat
oParameter.ExposedAsProperty=True

oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
oFormat.Units="in"
oFormat.ShowUnitsString=True
oFormat.ShowLeadingZeros=True
oFormat.ShowTrailingZeros=False
NextoParameter

the enumerate type in iLogic need to add the whole statement from Inventor.***

Valued Contributor
gary.belisle
Posts: 80
Registered: ‎07-29-2011
Message 4 of 16 (1,495 Views)

Re: Custom Property Format in iLogic

09-22-2011 06:27 AM in reply to: xiaoyan.qi

That works great! Thank you.

 

How do I get the value of a User Parameter unit type? I'll need to do an if statement for "in" or "mm" and set the custom property format accordingly.

---------------------------------------------------------------------
i7-2720QM Dell Precision M6600, Win 7 Pro 64-bit, 8GB RAM
Autodesk Product Design Suite Ultimate 2013
Autodesk Vault Professional 2013
Valued Contributor
gary.belisle
Posts: 80
Registered: ‎07-29-2011
Message 5 of 16 (1,493 Views)

Re: Custom Property Format in iLogic

09-22-2011 06:56 AM in reply to: xiaoyan.qi

I think I figured this out. Thanks for the help!

 


SyntaxEditor Code Snippet

'*** Begin Code for setting Custom Property Types for User Parameters ***
'''
''' If Exposed As Property = True then check for "in" or "mm" and
''' Set Custom Property Types accordingly.
'''
'*** Dim variables....
'[
DimoPartDocAsPartDocument
oPartDoc=ThisApplication.ActiveDocument
DimoParameterAsParameter
DimoFormatAsCustomPropertyFormat
']
'*** For Each User Parameter....
'[
ForEachoParameterInoPartDoc.ComponentDefinition.Parameters.UserParameters
IfoParameter.ExposedAsPropertyThen
IfoParameter.Units="mm"Then
oFormat=oParameter.CustomPropertyFormat
oParameter.ExposedAsProperty=True
oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
oFormat.Units="mm"
oFormat.ShowUnitsString=True
oFormat.ShowLeadingZeros=True
oFormat.ShowTrailingZeros=False
ElseIfoParameter.Units="in"Then
oFormat=oParameter.CustomPropertyFormat
oParameter.ExposedAsProperty=True
oFormat.PropertyType=Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Precision=Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
oFormat.Units="in"
oFormat.ShowUnitsString=True
oFormat.ShowLeadingZeros=False
oFormat.ShowTrailingZeros=False
Else
EndIf
Else
EndIf
NextoParameter
']
'*** End Code for setting Custom Property Types for User Parameters ***

 

---------------------------------------------------------------------
i7-2720QM Dell Precision M6600, Win 7 Pro 64-bit, 8GB RAM
Autodesk Product Design Suite Ultimate 2013
Autodesk Vault Professional 2013
Valued Contributor
LSA-skan
Posts: 95
Registered: ‎08-09-2012
Message 6 of 16 (1,048 Views)

Re: Custom Property Format in iLogic

02-04-2013 04:16 AM in reply to: gary.belisle

Hi

 

I need this code in Inventor 2013, but it´s not working...

Error message..:

 

Error on Line 8 : 'DimoPartDocAsPartDocument' is not declared. It may be inaccessible due to its protection level.

Error on Line 10 : 'DimoParameterAsParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 11 : 'DimoFormatAsCustomPropertyFormat' is not declared. It may be inaccessible due to its protection level.
Error on Line 15 : 'ForEachoParameterInoPartDoc' is not declared. It may be inaccessible due to its protection level.
Error on Line 16 : 'IfoParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 17 : 'IfoParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 17 : End of statement expected.
Error on Line 18 : 'oParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 19 : 'oParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 26 : 'ElseIfoParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 26 : End of statement expected.
Error on Line 27 : 'oParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 28 : 'oParameter' is not declared. It may be inaccessible due to its protection level.
Error on Line 35 : 'Else' must be preceded by a matching 'If' or 'ElseIf'.
Error on Line 36 : 'End If' must be preceded by a matching 'If'.
Error on Line 36 : 'EndIf' statements are no longer supported; use 'End If' instead.
Error on Line 37 : 'Else' must be preceded by a matching 'If' or 'ElseIf'.
Error on Line 38 : 'End If' must be preceded by a matching 'If'.
Error on Line 38 : 'EndIf' statements are no longer supported; use 'End If' instead.
Error on Line 39 : 'NextoParameter' is not declared. It may be inaccessible due to its protection level.

 

Im not a pro in anyway regarding this, so im sure it´s something simple im unaware of...

 

Hope some of you guys, can help me sort this out for the new version of Inventor...

 

/LSA-Skan

Valued Contributor
gary.belisle
Posts: 80
Registered: ‎07-29-2011
Message 7 of 16 (1,042 Views)

Re: Custom Property Format in iLogic

02-04-2013 06:23 AM in reply to: LSA-skan

If you cut and paste that, you'll need to add the spaces back in....

 

"DimoPartDocAsPartDocument" should be "Dim oPart As PartDocument", etc.

 

I think when I cut and pasted the code into here it removed the spaces.

---------------------------------------------------------------------
i7-2720QM Dell Precision M6600, Win 7 Pro 64-bit, 8GB RAM
Autodesk Product Design Suite Ultimate 2013
Autodesk Vault Professional 2013
Valued Contributor
LSA-skan
Posts: 95
Registered: ‎08-09-2012
Message 8 of 16 (1,034 Views)

Re: Custom Property Format in iLogic

02-04-2013 11:36 PM in reply to: gary.belisle

ahh.. Thanks Gary

 

Works like a charm now.. :smileyhappy:

 

Do you know if theres is a way to specify the parameters..?

 

Like if i want Parameter "Diameter" to have Units String = False & Trailing Zeros = False

but on all others parameters Units string = True

 

/LSA.Skan

Valued Contributor
LSA-skan
Posts: 95
Registered: ‎08-09-2012
Message 9 of 16 (1,029 Views)

Re: Custom Property Format in iLogic

02-05-2013 05:13 AM in reply to: gary.belisle

...Another thing...

 

I have now made the rule so it changes both the User Parameters and the Model Parameters, but i would like to change the Sheet Metal Parameters as well, if it is a sheet metal part, but i don't know the code for it.. 

These lines doesn't work..:

 

If oPartDoc.ComponentDefinition.Type = kSheetMetalComponentDefinitionObject Then
For Each oParameter In oPartDoc.ComponentDefinition.Parameters.SheetMetalParameters
Valued Contributor
gary.belisle
Posts: 80
Registered: ‎07-29-2011
Message 10 of 16 (1,026 Views)

Re: Custom Property Format in iLogic

02-05-2013 06:06 AM in reply to: LSA-skan

You can try to nest another if statement to get to a specific parameter like this... I'm not sure if you are even able to do this with the sheet metal parameters because they are controlled by a style.

 

'[
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument
Dim oUserParam As UserParameter


For Each oUserParam In oPartDoc.ComponentDefinition.Parameters.UserParameters
	oUserParamName = oUserParam.Name
If oUserParamName = "Diameter" Then
	If oUserParam.ExposedAsProperty Then
		If oUserParam.Units = "mm" Then
			oFormat = oUserParam.CustomPropertyFormat
			oUserParam.ExposedAsProperty = True
			oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kNumberPropertyType
			oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
			oFormat.Units = "mm"
		ElseIf oUserParam.Units = "in" Then
			oFormat = oUserParam.CustomPropertyFormat
			oUserParam.ExposedAsProperty = True
			oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kNumberPropertyType
			oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
			oFormat.Units = "in"
		Else
		End If
	Else
		oUserParamValue = Parameter(oUserParam.Name)
		iProperties.Value("Custom", oUserParam.Name) = UCase(oUserParamValue)
	End If
Else
	If oUserParam.ExposedAsProperty Then
		If oUserParam.Units = "mm" Then
			oFormat = oUserParam.CustomPropertyFormat
			oUserParam.ExposedAsProperty = True
			oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kNumberPropertyType
			oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
			oFormat.Units = "mm"
		ElseIf oUserParam.Units = "in" Then
			oFormat = oUserParam.CustomPropertyFormat
			oUserParam.ExposedAsProperty = True
			oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kNumberPropertyType
			oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kThreeDecimalPlacesPrecision
			oFormat.Units = "in"
		ElseIf oUserParam.Units = "deg" Then
			oFormat = oUserParam.CustomPropertyFormat
			oUserParam.ExposedAsProperty = True
			oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kNumberPropertyType
			oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kOneDecimalPlacePrecision
			oFormat.Units = "deg"
		ElseIf oUserParam.Units = "ul" Then
			oFormat = oUserParam.CustomPropertyFormat
			oUserParam.ExposedAsProperty = True
			oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kNumberPropertyType
			oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kZeroDecimalPlacePrecision
			oFormat.Units = "ul"
		Else
		End If
	Else
		oUserParamValue = Parameter(oUserParam.Name)
		iProperties.Value("Custom", oUserParam.Name) = UCase(oUserParamValue)
	End If
End If
Next oUserParam
']

 

---------------------------------------------------------------------
i7-2720QM Dell Precision M6600, Win 7 Pro 64-bit, 8GB RAM
Autodesk Product Design Suite Ultimate 2013
Autodesk Vault Professional 2013

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube