Adding physical properties to f(x) parameters

Adding physical properties to f(x) parameters

Anonymous
Not applicable
2,973 Views
9 Replies
Message 1 of 10

Adding physical properties to f(x) parameters

Anonymous
Not applicable

Hello,

im here again to ask you about help 🙂
When I was doing customised title block for my drawings I had no problems with adding a block with physical properties like e.x. Area. In text box I just had to choose from list: physical properties - model -> area -> press arrow icon and I had this formule in text <area> and everything works well. 
Now I need this one and some others properties to create custimised BOM list but they aren't available to chose from list and I dont see them in parameters. So my questions are:
1. How to add physical property to parameter list? I've found rule like this but it doesnt work:

surfaceArea=iProperties.Area

2.  If this rule above would work it looks easy because I want to take a "easy access" property. But when I was creating a titble block I also could choose (in sheet metal part) flat part length and flat part width but i dont see this properties in iProperties. So from where can I get a names of this properties to do similar formule like from question no 1?

Generally I want to pick some properties to parameters to have possibility to use it in customised BOM list.


I hope you can understand me 🙂

Best regards, Wojciech

0 Likes
Accepted solutions (1)
2,974 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Can anyone help?

I've tried few rules but I got communicate like "Area property is read-only" when I just wanted to call out this property. And because of this it didnt work.

0 Likes
Message 3 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Anonymous.  This can be a tricky area.  There are several routes to retrieving physical properties of model documents.  Some are ReadOnly, while others are Read/Write.  Then there is the issue of what units you need them to be in.  Some sources may return them in 'document' units, while other sources will return 'database' units.  The standard iProperties that exist in all documents are ReadOnly and return these values in database units.  In this case, database units means Area will be in centimeters squared, Volume will be in centimeters cubed, Mass will be in grams, and Density will be in grams per centimeters cubed.  You can set up document units for length, angles, mass, & time, and those will be reflected in the 'Physical' tab of the iProperties dialog, but they don't seem to effect the Density value shown.  So, knowing these things, I generally prefer to access these values through the standard iProperties, since I know what I will be getting, and that they can't be written over.  Then just convert the units as needed using the built-in ConvertUnits tool.  Then use a series of Try...Catch blocks to update or create the needed user parameters with the values retrieved.

Since the title of this post is adding physical properties to parameters, here is an iLogic rule to do that:

 

Dim oDoc As Document = ThisDoc.Document
If Not (TypeOf oDoc Is PartDocument) And Not (TypeOf oDoc Is AssemblyDocument) Then Exit Sub
oUM = oDoc.UnitsOfMeasure
Dim oLengthUnits As String = oUM.GetStringFromType(oUM.LengthUnits)
Dim oMassUnits As String = oUM.GetStringFromType(oUM.MassUnits)
Dim oAreaUnits As String = oLengthUnits & " " & oLengthUnits
Dim oVolumeUnits As String = oAreaUnits & " " & oLengthUnits
Dim oDensityUnits As String = oMassUnits & " / " & oVolumeUnits
Dim oPProps As PropertySet = oDoc.PropertySets.Item(3)
Dim oArea, oMass, oVolume, oDensity As Double

'collect values from iProperties (these few are ReadOnly)
'all these values will be in 'database units' (based on centimeters & grams)
'may have value of -1, if not calculated for first time yet
oArea = oPProps.Item("SurfaceArea").Value
oMass = oPProps.Item("Mass").Value
oVolume = oPProps.Item("Volume").Value
oDensity = oPProps.Item("Density").Value

'convert these values from 'database units' to 'document units'
If oArea <> (-1) Then
	oArea = oUM.ConvertUnits(oArea, "cm cm", oAreaUnits)
End If
If oMass <> (-1) Then
	oMass = oUM.ConvertUnits(oMass, "g", oMassUnits)
End If
If oVolume <> (-1) Then
	oVolume = oUM.ConvertUnits(oVolume, "cm cm cm", oVolumeUnits)
End If
If oDensity <> (-1) Then
	oDensity = oUM.ConvertUnits(oDensity, "g / cm cm cm", oDensityUnits)
End If

MsgBox("Physical Properties:" & vbCrLf & _
"Area = " & oArea & vbCrLf & _
"Mass = " & oMass & vbCrLf & _
"Volume = " & oVolume & vbCrLf & _
"Density = " & oDensity, , "")

'write values to user parameters
Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
Dim oAreaParam, oMassParam, oVolumeParam, oDensityParam As UserParameter
Try
	oAreaParam = oUParams.Item("Area")
	oAreaParam.Value = oArea
Catch
	oAreaParam = oUParams.AddByExpression("Area", oArea.ToString, oAreaUnits)
	oAreaParam.ExposedAsProperty = True
	oAreaParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
	oAreaParam.CustomPropertyFormat.Units = oAreaUnits
	oAreaParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
End Try
Try
	oMassParam = oUParams.Item("Mass")
	oMassParam.Value = oMass
Catch
	oMassParam = oUParams.AddByExpression("Mass", oMass.ToString, oMassUnits)
	oMassParam.ExposedAsProperty = True
	oMassParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
	oMassParam.CustomPropertyFormat.Units = oMassUnits
	oMassParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
End Try
Try
	oVolumeParam = oUParams.Item("Volume")
	oVolumeParam.Value = oVolume
Catch
	oVolumeParam = oUParams.AddByExpression("Volume", oVolume.ToString, oVolumeUnits)
	oVolumeParam.ExposedAsProperty = True
	oVolumeParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
	oVolumeParam.CustomPropertyFormat.Units = oVolumeUnits
	oVolumeParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
End Try
Try
	oDensityParam = oUParams.Item("Density")
	oDensityParam.Value = oDensity
Catch
	oDensityParam = oUParams.AddByExpression("Density", oDensity.ToString, oDensityUnits)
	oDensityParam.ExposedAsProperty = True
	oDensityParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
	oDensityParam.CustomPropertyFormat.Units = oDensityUnits
	oDensityParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
End Try

 

Also, if you need to add these values as BOM columns, you will need to add those columns as representing iProperties, and since trying to do this with the standard iProperties may not work for you, due to the read-only thing, then maybe we can use the custom iProperty versions of them, which are generated by the parameters we just made here.  As you may know, when you 'expose' or 'export' a parameter in the parameters dialog box, it automatically creates a custom iProperty with the same name and value as the parameter.  And every time the value of that parameter changes, it will automatically update the associated custom iProperty.

 

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)

0 Likes
Message 4 of 10

nivyus
Contributor
Contributor
你好,我尝试运行了代码,想请教下:如何在子零部件中的iProperty 自定义中也显示。当前只在第一层级的部件iProperty 中显示
0 Likes
Message 5 of 10

nivyus
Contributor
Contributor
你好我尝试运行了代码,下:如何在子项零部件中的iProperty自定义中也显示。当前只在第一层级的用户iProperty中显示
0 Likes
Message 6 of 10

Anonymous
Not applicable

everything works fine, thank you again!

0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor

Hi @nivyus.  I hope you can correctly translate my reply from English to your language, so you can use this.

You basically asked me how to apply this code to an assembly situation, so that it will effect all components and sub components.  I slightly modified this rule so that it should be able to work from an active assembly, and process all components at all levels of that assembly.  For simplicity, I mainly moved the bulk of the code down into a separate Sub routine that can be called to run on each component as we loop through them.  Then I created another little separate Sub routine to help recursively step down through all the lower levels of the assembly.

Here is the new iLogic rule code:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	StepDown(oADef.Occurrences)
End Sub

Sub PhysicalPropsToUParams(oComp As ComponentOccurrence)
	Dim oCompDoc As Document = oComp.Definition.Document
	oUM = oCompDoc.UnitsOfMeasure
	Dim oLengthUnits As String = oUM.GetStringFromType(oUM.LengthUnits)
	Dim oMassUnits As String = oUM.GetStringFromType(oUM.MassUnits)
	Dim oAreaUnits As String = oLengthUnits & " " & oLengthUnits
	Dim oVolumeUnits As String = oAreaUnits & " " & oLengthUnits
	Dim oDensityUnits As String = oMassUnits & " / " & oVolumeUnits
	Dim oPProps As PropertySet = oCompDoc.PropertySets.Item(3)
	Dim oArea, oMass, oVolume, oDensity As Double

	'collect values from iProperties (these few are ReadOnly)
	'all these values will be in 'database units' (based on centimeters & grams)
	'may have value of -1, if not calculated for first time yet
	oArea = oPProps.Item("SurfaceArea").Value
	oMass = oPProps.Item("Mass").Value
	oVolume = oPProps.Item("Volume").Value
	oDensity = oPProps.Item("Density").Value

	'convert these values from 'database units' to 'document units'
	If oArea <> (-1) Then
		oArea = oUM.ConvertUnits(oArea, "cm cm", oAreaUnits)
	End If
	If oMass <> (-1) Then
		oMass = oUM.ConvertUnits(oMass, "g", oMassUnits)
	End If
	If oVolume <> (-1) Then
		oVolume = oUM.ConvertUnits(oVolume, "cm cm cm", oVolumeUnits)
	End If
	If oDensity <> (-1) Then
		oDensity = oUM.ConvertUnits(oDensity, "g / cm cm cm", oDensityUnits)
	End If

'	MsgBox("Physical Properties:" & vbCrLf & _
'	"Area = " & oArea & vbCrLf & _
'	"Mass = " & oMass & vbCrLf & _
'	"Volume = " & oVolume & vbCrLf & _
'	"Density = " & oDensity, , "")

	'write values to user parameters
	Dim oUParams As UserParameters = oCompDoc.ComponentDefinition.Parameters.UserParameters
	Dim oAreaParam, oMassParam, oVolumeParam, oDensityParam As UserParameter
	Try
		oAreaParam = oUParams.Item("Area")
		oAreaParam.Value = oArea
	Catch
		oAreaParam = oUParams.AddByExpression("Area", oArea.ToString, oAreaUnits)
		oAreaParam.ExposedAsProperty = True
		oAreaParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
		oAreaParam.CustomPropertyFormat.Units = oAreaUnits
		oAreaParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
	End Try
	Try
		oMassParam = oUParams.Item("Mass")
		oMassParam.Value = oMass
	Catch
		oMassParam = oUParams.AddByExpression("Mass", oMass.ToString, oMassUnits)
		oMassParam.ExposedAsProperty = True
		oMassParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
		oMassParam.CustomPropertyFormat.Units = oMassUnits
		oMassParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
	End Try
	Try
		oVolumeParam = oUParams.Item("Volume")
		oVolumeParam.Value = oVolume
	Catch
		oVolumeParam = oUParams.AddByExpression("Volume", oVolume.ToString, oVolumeUnits)
		oVolumeParam.ExposedAsProperty = True
		oVolumeParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
		oVolumeParam.CustomPropertyFormat.Units = oVolumeUnits
		oVolumeParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
	End Try
	Try
		oDensityParam = oUParams.Item("Density")
		oDensityParam.Value = oDensity
	Catch
		oDensityParam = oUParams.AddByExpression("Density", oDensity.ToString, oDensityUnits)
		oDensityParam.ExposedAsProperty = True
		oDensityParam.CustomPropertyFormat.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
		oDensityParam.CustomPropertyFormat.Units = oDensityUnits
		oDensityParam.CustomPropertyFormat.Precision = CustomPropertyPrecisionEnum.kTwoDecimalPlacesPrecision
	End Try
End Sub

Sub StepDown(oComps As ComponentOccurrences)
	For Each oComp As ComponentOccurrence In oComps
		PhysicalPropsToUParams(oComp)
		If oComp.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			StepDown(oComp.Definition.Occurrences)
		End If
	Next
End Sub

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 8 of 10

WCrihfield
Mentor
Mentor

Also, just in case others who visit this post are curious, one of the other routes for accessing these physical properties of model documents (Part or Assembly) is through their Document.ComponentDefinition.MassProperties.  This MassProperties object has the Mass, Area, & Volume properties under it.  The Area property is ReadOnly, but Mass & Volume are Read/Write (Get/Set), and have other properties that specify whether their values are overridden.  They still return values in 'database' units, so you would still need to convert the units as needed, if those aren't what you normally use.  Density is not one of the properties included here, so to get that just use the math equation (density = mass / volume).

 

Also, the units strings I am using can be done a little differently if you would prefer.  Instead of using the same base measurement units String multiple times in a String with spaces between them to represent 'squared' or 'cubed' you could just put a "^2" for squared (area), or "^3" for cubed (volume) after the base units String.  It will work the same either way, so it's just personal preference.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 10

nivyus
Contributor
Contributor

Thank you very much for your thoughtfulness

It's great to try your way. Happy for a long time.

Setting "cm" to "mm" can meet the requirements, but the density does not participate in the operation. The modification attempt does not work. The result shows that the density is 0

Please continue to help, thank you very much.

0 Likes
Message 10 of 10

nivyus
Contributor
Contributor
oDensityParam.Value = oDensity*1000000 在fx中发现可以满足要求。在自定义中不显示小数点。
基本满足使用要求,多谢。
0 Likes