Use Mass, Area, Volume value or variable from Physical iProperties to User Parameters

Use Mass, Area, Volume value or variable from Physical iProperties to User Parameters

engilic
Advocate Advocate
4,432 Views
16 Replies
Message 1 of 17

Use Mass, Area, Volume value or variable from Physical iProperties to User Parameters

engilic
Advocate
Advocate

Hi,

 

Is there any way to use a value or variable from iProperties / Physical/ Mass (Area or Volume) in User Parameters?
Is it possible to say something like =<Mass> in User Parameters.

 

If it is possible to use it in iProperties why not in User Parameters.

 

Not using iLogic.

 

Thank you

 

Edit: PS: By the way how to move a post from one board to another?

0 Likes
Accepted solutions (3)
4,433 Views
16 Replies
Replies (16)
Message 2 of 17

WCrihfield
Mentor
Mentor

You can set UserParameters update custom iProperty values, but there isn't currently a built-in way to set something up so that when an iProperty value changes it will update a UserParameter, without using code.

If that functionality is needed, but you don't want to have to manually do something to make it happen, and you don't want to have any local iLogic rules in your documents, you could always create an external iLogic rule to manipulate the data, then put that external iLogic rule under the 'iProperty Change' event in the Event Triggers dialog box.  Then when that event happens, it will run the external rule to make it happen.

 

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)

Message 3 of 17

bradeneuropeArthur
Mentor
Mentor

You could create an Inventor Add-in!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 4 of 17

engilic
Advocate
Advocate

Thank you @WCrihfield ,

 

I think I saw a post with iLogic for having Mass and Volume in User Parameters but cannot find it now, can you help?

Cheers

0 Likes
Message 5 of 17

WCrihfield
Mentor
Mentor

Here is some simple iLogic to get the "Mass" and "Volume" properties.  These are standard iProperties that are present in all inventor documents.

Dim oDoc As Document = ThisDoc.Document

Dim oMass As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Mass").Value
'or
'Dim oMass As String = iProperties.Value("Project", "Mass")

Dim oVolume As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Volume").Value
'or
'Dim oVolume As String = iProperties.Value("Project", "Volume")

MsgBox("Mass = " & oMass & vbCrLf & _
"Volume = " & oVolume,,"")

 

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)

Message 6 of 17

engilic
Advocate
Advocate

Thank you @WCrihfield ,

 

Almost there, just need to update Physical Properties (Mass, Volume, ...) before setting the value to User properties.

Now I need manually to update the properties and that is not the solution.

 

Please, how to ilogically update Physical Properties?

 

At the end will post the hole code.

0 Likes
Message 7 of 17

WCrihfield
Mentor
Mentor

Here is the iLogic command that updates the mass properties by code.

ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute2(True)

 

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)

Message 8 of 17

bradeneuropeArthur
Mentor
Mentor

@engilic wrote:

Hi,

 

Is there any way to use a value or variable from iProperties / Physical/ Mass (Area or Volume) in User Parameters?
Is it possible to say something like =<Mass> in User Parameters.

 

If it is possible to use it in iProperties why not in User Parameters.

 

What do you mean with:

Not using iLogic.

Either not using Ilogic

Or you don't want to use I-logic

 

Thank you

 

Edit: PS: By the way how to move a post from one board to another?


 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 9 of 17

WCrihfield
Mentor
Mentor

Here is an iLogic rule that will work when ran from either a part or assembly document.  It will first execute the command I showed in my previous post to make sure the mass properties are up-to-date.  Then it gets the values of the Mass and Volume Properties (one way or the other).  Then it checks to see if there are already user parameters with the names "Mass" and "Volume".  If found, it updates their values.  If not found, it creates them, then sets their values.  Beware the 'units' though.  When retrieved through the MassProperties route, the values will be in 'database units', not document units.  If you don't want those units, you may have to include some simple math to convert them to the units of your choice, or include a different units conversion method in there.  Also, you may or may not want to change the units specified within the lines of code to create the two user parameters.  I'm specifying pounds for mass units, and ounces for volume units.

 

Here's the code:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
	ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("This rule only works for Assembly or Part documents. Exiting.", , "")
	Exit Sub
End If
Parameter.UpdateAfterChange = True
MultiValue.UpdateAfterChange = True

ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute2(True)

Dim oMassProps As MassProperties = ThisApplication.ActiveDocument.ComponentDefinition.MassProperties
Dim oMass As Double = oMassProps.Mass '(will be in database units, not document units)
Dim oVol As Double = oMassProps.Volume '(will be in database units, not document units)
'or
'Dim oDTProps As Inventor.PropertySet = ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties")
'Dim oMass As Double = CDbl(oDTProps.Item("Mass").Value)
'Dim oVol As Double = CDbl(oDTProps.Item("Volume").Value)

Dim oUParams As UserParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter

Dim oMExists, oVExists As Boolean
For Each oUParam In oUParams
	If oUParam.Name = "Mass" Then
		oMExists = True
		oUParam.Value = oMass
	ElseIf oUParam.Name = "Volume" Then
		oVExists = True
		oUParam.Value = oVol
	End If
Next

If oMExists = False Then
	'<<<<  USING POUNDS FOR MASS UNITS, CHANGE FOR OTHER UNITS  >>>>
	oUParam = oUParams.AddByValue("Mass", CDbl(oMass), UnitsTypeEnum.kLbMassMassUnits)
End If
If oVExists = False Then
		'<<<<  USING OUNCE VOLUME UNITS, CHANGE FOR OTHER UNITS  >>>>
	oUParam = oUParams.AddByValue("Volume", CDbl(oVol), UnitsTypeEnum.kOunceVolumeUnits)
End If

'Output Parameters values from this rule to the Model. (Use this before Document Update)
RuleParametersOutput()
'Immediately update the current document.
InventorVb.DocumentUpdate()

As I hinted at before, you may want to include this rule under one or more event triggers, but beware...doing so may cause slowness.  When it executes that command it will need to recalculate the mass properties, which the bigger the assembly, the more time it may take.

 

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)

Message 10 of 17

engilic
Advocate
Advocate

Thank you @WCrihfield 

 

The last code works fine, except for 2 things:

 

1.
I changed units to UnitsTypeEnum.kKilogramMassUnits and "m^3" since I could not find volume units in cubic meters.
That works ok, but, I noticed if there are already parameters with that names it won't change the unit, it will just keep the same unit no matter what you say for UnitsTypeEnum in the code.

 

2.
Surprisingly it doesn't work when I put a code as an event trigger when Any Model Parameter Change.
I get an error.
The code by itself works but as a trigger no, I was surprised that can happen.

Screenshot attached.

 

Thank you and have a lovely day. 

0 Likes
Message 11 of 17

WCrihfield
Mentor
Mentor
Accepted solution

There are a couple of options to deal with pre-existing parameters with the wrong units.

- Option 1:  Attempt to change its units with a Try...Catch...End Try block of code, just before attempting to update its value.

- Option 2:  Just delete the parameter, set the 'Exists' boolean to False, then the lower section will create a new one with the units you specify.

 

As for the Event Trigger...The AnyModelParameterChange event only works on model parameters, so it won't be triggered when user parameters get changed.  That's one of the main drawbacks of using user parameters vs model parameters.  However, using user parameters is most often more stable, because they won't disappear on you like model parameters can.  Model parameters are created (and deleted) automatically by Inventor when you create (or delete) features, dimensions, etc.

 

Here is an updated rule code, in which I have changed the mass units to your specifications.  It now also includes some code showing you how you can check the units of an existing user parameter, and attempt to change its units.  If changing the existing parameters units fails, it will then just delete the parameter, then set the boolean back to False, so the later method will create a new one.  I commented out this portion of the Volume parameter check, since I'm unsure how you set your volume units and how you may have done any math for units conversion, but it is fairly easy to follow.  Then again in the second method below, where it is to create the Volume parameter, I left that alone too, for the same reasons.  You can just use what you did in your last fix to correct the units.

I hope this helps some.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
	ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("This rule only works for Assembly or Part documents. Exiting.", , "")
	Exit Sub
End If
Parameter.UpdateAfterChange = True
MultiValue.UpdateAfterChange = True

ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute2(True)

Dim oMassProps As MassProperties = ThisApplication.ActiveDocument.ComponentDefinition.MassProperties
Dim oMass As Double = oMassProps.Mass '(will be in database units, not document units)
Dim oVol As Double = oMassProps.Volume '(will be in database units, not document units)
'or
'Dim oDTProps As Inventor.PropertySet = ThisApplication.ActiveDocument.PropertySets.Item("Design Tracking Properties")
'Dim oMass As Double = CDbl(oDTProps.Item("Mass").Value)
'Dim oVol As Double = CDbl(oDTProps.Item("Volume").Value)

Dim oUParams As UserParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter

Dim oMExists, oVExists As Boolean
For Each oUParam In oUParams
	If oUParam.Name = "Mass" Then
		oMExists = True
		Try
			If oUParam.Units <> UnitsTypeEnum.kKilogramMassUnits Then
				oUParam.Units = UnitsTypeEnum.kKilogramMassUnits
			End If
			oUParam.Value = oMass
		Catch
			oUParam.Delete
			oMExists = False
		Catch
			MsgBox("Failed to change Mass 'Units' to Kilograms and/or delete the parameter.", , "")
		End Try
	ElseIf oUParam.Name = "Volume" Then
		oVExists = True
'		Try
'			If oUParam.Units <> "m^3" Then
'				oUParam.Units = "m^3"
'			End If
'			oUParam.Value = oVol
'		Catch
'			oUParam.Delete
'			oVExists = False
'		Catch
'			MsgBox("Failed to change Volume 'Units' to meters cubed.", , "")
'		End Try
	End If
Next

If oMExists = False Then
	oUParam = oUParams.AddByValue("Mass", CDbl(oMass), UnitsTypeEnum.kKilogramMassUnits)
End If
If oVExists = False Then
		'<<<<  USING OUNCE VOLUME UNITS, CHANGE FOR OTHER UNITS  >>>>
	oUParam = oUParams.AddByValue("Volume", CDbl(oVol), UnitsTypeEnum.kOunceVolumeUnits)
End If

'Output Parameters values from this rule to the Model. (Use this before Document Update)
RuleParametersOutput()
'Immediately update the current document.
InventorVb.DocumentUpdate()

 

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)

Message 12 of 17

engilic
Advocate
Advocate
Accepted solution

Thank you @WCrihfield ,

 

It is good to have this code but basically, you say we cannot have updated Mass & Volume, so any formula we have which has Mass or Volume cannot work.

 

Is it possible somehow to get always the updated volume of the part?

 

Have a lovely day.

 

EDIT: I found this :

iProperties.Volume

and it works, so far, always updates the volume, triggers work.

Thank you

0 Likes
Message 13 of 17

engilic
Advocate
Advocate

@WCrihfield ,

 

One more thing if you can, please.

 

How to get units of Physical properties of Volume and Mass in iProperties (probably document units for Mass and Volume will be appropriate of document units for Length)?

0 Likes
Message 14 of 17

WCrihfield
Mentor
Mentor

Actually, I believe accessing those values from the component definition's MassProperties should be more reliable than the getting them from iProperties.  Here are a few links about it.  There are other things you can do with the MassProperties object too (see the last link).

AssemblyComponentDefinition.MassProperties Property 

PartComponentDefinition.MassProperties Property 

MassProperties Object 

 

Also, the command that last rule is executing near the beginning should force those values to update, so that should make the values you retrieve after that point in the rule as accurate as your accuracy settings.  Theck the accuracy settings within the MassProperties object.

 

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)

Message 15 of 17

WCrihfield
Mentor
Mentor

@engilic 

Here is a link to a page documenting which units Inventor's iLogic uses as its 'database units' for most types of measurements.  Sadly it doesn't mention volume though.

 

There are other ways to convert units if you don't want to include actual math to do so.

The UnitsOfMeasure object has a ConvertUnits method you may be able to use also.  Notice that in the documentation for the ConvertUnits method that you can use either a value from the UnitsTypeEnum, or you can use a string representation when specifying units type to convert between.  You may be able to use this to your advantage.

 

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)

Message 16 of 17

engilic
Advocate
Advocate
Accepted solution

Hi @WCrihfield ,

 

This is my final code that works with triggers.
The code you suggested may be more reliable but not working with triggers, and not point to have User Parameter "Volume" and "Mass" if not refreshing when the geometry changes.

 

Sadly if the Unit of User Parameter is set to "mm^3" or anything that is not in UnitsTypeEnum Enumerator the Inventor does not recognize it.

I tested it and it returns an empty string, so cannot check if it is "mm^3" or not, that's why I set it in liters, then in the formula it can be converted to something else.

 

If you have a better solution I am open to test it and use it.

 

Thank you @WCrihfield , you are so fast in responding, great.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject And _
	ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("This rule only works for Assembly or Part documents.", , "NOT ASSEMBLY OR PART")
	Exit Sub
End If

Dim oVolume As Double = iProperties.Volume
Dim oMass As Double = iProperties.Mass
Dim oUParams As UserParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
Dim oUParam As UserParameter
Dim oMExists, oVExists As Boolean

oVolume = oVolume/10^3 'CONVERT TO liters, ASSUMED IT IS IN cm^3

oMExists = False
oVExists = False

For Each oUParam In oUParams
	If oUParam.Name = "Mass" Then
		oMExists = True
		If oUParam.Units <> "kg" Then
				oUParam.Units = UnitsTypeEnum.kKilogramMassUnits
		End If
		oUParam.Value = oMass
	End If
	If oUParam.Name = "Volume" Then
		oVExists = True
		If oUParam.Units <> "l" Then
				oUParam.Units = kLiterVolumeUnits
		End If
		oUParam.Value = oVolume
	End If
Next

If oMExists = False Then
	oUParam = oUParams.AddByValue("Mass", oMass, UnitsTypeEnum.kKilogramMassUnits)
End If

If oVExists = False Then
	oUParam = oUParams.AddByValue("Volume", oVolume, kLiterVolumeUnits)
End If

'Output Parameters values from this rule to the Model. (Use this before Document Update)
RuleParametersOutput()
'Immediately update the current document.
InventorVb.DocumentUpdate()

 

0 Likes
Message 17 of 17

WCrihfield
Mentor
Mentor

It all looks good to me.  As long as it is working OK for you, that's the main thing.  I'm glad I was able to help out.  Good luck in your future Inventor automation endeavors 🙂.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)