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

(Not an Autodesk Employee)