Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: rprivittB3TTG

I've been running into a problem making this happen by iLogic too.  I believe the main problem is the different units we're trying to 'mix' together.  I was hoping to set the resulting user parameter's units to pounds (mass units), but this fails because you can't multiply a value in length units by a value in mass units.  The unit types are incompatible.  You can multiply the inches value by a unit-less value, but the result is in inches, not pounds.  And if you try to change the units to pounds afterwards, it changes the numerical value also.  Mass = Volume x Density.

 

In order to have the resulting parameter set to pounds units, and get a compatible result, you would have to have a unit-less representation of the 'LENGTH' parameter to multiply by.  I tried creating another user parameter, set to unit less units, then setting its equation to LENGTH.  It results in a larger numerical value (basically as if the inches had been converted to centimeters).  So, my next thought was to leave that NewMASS user parameter as Inches units, but then set the custom iProperty's units to Pounds, within the custom property formatting, but I found out that this is not an option.  The property's units must also be in length type units.

 

So, in conclusion, you either have to do a lot of work around to get a resulting parameter that is in pounds units, or just leave the results in inches, when doing it this way.  If I know, or could obtain the Area of the end profile of the extrusion, I could then multiply that by the length to get its true Volume.  Then multiply that by its Density to get its Mass.  That true Volume value could also be another user parameter, if you were considering going that route.

 

Here is the iLogic code to do the process at the end of the last post.  The resulting user parameter is just in inches instead of pounds, but I'm assuming you know how to deal with that from there.

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
		MsgBox("A Part Document must be active for this rule to work. Exiting.",vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
	'run the custom Sub below on this part document
	CreateNewMASSParamAndProp(oPDoc)
End Sub

Sub CreateNewMASSParamAndProp(oPart As PartDocument)
	Parameter.UpdateAfterChange = True
	MultiValue.UpdateAfterChange = True
	Dim oParams As Parameters = oPart.ComponentDefinition.Parameters
	Dim oUParams As UserParameters = oParams.UserParameters
	oMassUnits = oPart.UnitsOfMeasure.MassUnits 'document units for Mass
	oLengthUnits = oPart.UnitsOfMeasure.LengthUnits 'document units for Length
	'make sure the model parameter named 'LENGTH' exists
	Dim oParam, oLENGTH As Inventor.Parameter
	Dim oMassMultiplier, oNewMASS As UserParameter
	For Each oParam In oParams
		If oParam.Name = "LENGTH" Then
			oLENGTH = oParam
		ElseIf oParam.Name = "MassMultiplier" Then
			oMassMultiplier = oParam
		ElseIf oParam.Name = "NewMASS" Then
			oNewMASS = oParam
		End If
	Next
	'if it did not find the 'LENGTH' parameter, let the user know then exit the rule
	If IsNothing(oLENGTH) Then
		MsgBox("The model parameter named 'LENGTH' could not be found.  Exiting Rule.", vbExclamation, "iLogic")
		Exit Sub
	End If
	
	'create or update the user parameter for the 'MassMultiplier'
	If IsNothing(oMassMultiplier) Then
		'oMassMultiplier = oUParams.AddByExpression("MassMultiplier", "0.1575", oMassUnits)
		oMassMultiplier = oUParams.AddByExpression("MassMultiplier", "0.1575", "ul")
	Else
		'oMassMultiplier.Units = oMassUnits
		oMassMultiplier.Units = "ul"
		oMassMultiplier.Expression = "0.1575"
	End If
	'assemble the new equation in one place, so we can use it in two places below
	oNewEquation = "MassMultiplier * LENGTH"
	
	If Not IsNothing(oNewMASS) Then
		'the user parameter 'NewMASS' was found, so make sure it is up-to-date
		'oNewMASS.Units = oMassUnits
		oNewMASS.Units = oLengthUnits
		oNewMASS.Expression = oNewEquation
	Else
		'the user parameter 'NewMASS' was not found, so create it
		Try
			'oNewMASS = oUParams.AddByExpression("NewMASS", oNewEquation, oMassUnits)
			oNewMASS = oUParams.AddByExpression("NewMASS", oNewEquation, oLengthUnits)
		Catch oEx As Exception
			MsgBox("Failed to create the 'NewMASS' user parameter." & vbCrLf & _
			oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "iLogic")
		End Try
	End If
	'expose the 'NewMASS' user parameter as a custom iProperty
	If Not IsNothing(oNewMASS) Then
		Try
			If Not oNewMASS.ExposedAsProperty Then oNewMASS.ExposedAsProperty = True
			oCPF = oNewMASS.CustomPropertyFormat
			oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
			oCPF.Units = oLengthUnits
			oCPF.Precision = CustomPropertyPrecisionEnum.kEightDecimalPlacesPrecision
		Catch oEx As Exception
			MsgBox("Failed to expose the 'NewMASS' user parameter as iProperty." & vbCrLf & _
			oEx.Message & vbCrLf & oEx.StackTrace, vbCritical, "iLogic")
		End Try
	End If
	If oPart.Dirty Then
		oPart.Update
		oPart.Save
	End If
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)