Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom Property Format in iLogic

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
gary.belisle
7143 Views, 15 Replies

Custom Property Format in iLogic

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-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
15 REPLIES 15
Message 2 of 16
xiaoyan.qi
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

Message 3 of 16
xiaoyan.qi
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.***

Message 4 of 16
gary.belisle
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-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
Message 5 of 16
gary.belisle
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-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
Message 6 of 16
LSA-skan
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

Message 7 of 16
gary.belisle
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-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
Message 8 of 16
LSA-skan
in reply to: gary.belisle

ahh.. Thanks Gary

 

Works like a charm now.. 🙂

 

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

Message 9 of 16
LSA-skan
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
Message 10 of 16
gary.belisle
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-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
Message 11 of 16
LSA-skan
in reply to: gary.belisle

Hi Gary

 

thanks.. !! I will try with this.. 🙂

 

Regarding the Sheetmatal parameters... then my thought is, that if i can do it manually, then i should also be able to do it with an iLogic rule..?? but as mentioned, im not a pro with this.. 🙂

 

/LSA-Skan

Message 12 of 16
gary.belisle
in reply to: LSA-skan

Glad to help. I'd investigate the code but I can't commit the time right now. What I've done is set up User Parameters to drive the sheet metal parameters. For example I drive thickness with a User Parameters named "Thickness" but you have to disable the sheet metal default checkbox "Use Thickness from Rule" to do that.

---------------------------------------------------------------------
i7-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360
Message 13 of 16
LSA-skan
in reply to: gary.belisle

All good..! thanks for the effort.. i will give you a Kudos for your help 🙂

Message 14 of 16
wseaston
in reply to: gary.belisle

Hi My requirment is slightly different so I hope someone can provide me with some assistance please.

 

I need to change the custom property format for a single specified fx parameter (<G_L>) as created by Inventor Frame generator, so that it drops the "mm" units and the trailing zero's.

 

The trickier part is that I would like to run an iLogic rule from the assembly level so that the custom property changes are made to the "<G_L>" fx parameter in all the parts in the assembly.

 

Thanks,

Wayne

Message 15 of 16
wseaston
in reply to: gary.belisle

Please help.

 

I have tried to use this iLogic code but am getting the following error code:

 

Rule Compile Errors in Rule4, in Part1

Error on Line 5 : 'For' must end with a matching 'Next'.
Error on Line 15 : 'NextoParameter' is not declared. It may be inaccessible due to its protection level.

 

Please can someone suggest a solution. 

Message 16 of 16
gary.belisle
in reply to: wseaston

Try adding a space between "Next" and "oParameter" in "NextoParameter"

---------------------------------------------------------------------
i7-4800MQ Dell Precision M6800, Win 7 Enterprise 64-bit, 16GB RAM
Autodesk Product Design Suite Ultimate 2015
Autodesk Vault Professional 2015
PLM 360

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report