Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

iLogic Mass to BoM decimal problem

creggo
Enthusiast

iLogic Mass to BoM decimal problem

creggo
Enthusiast
Enthusiast

Hi Folks, 

 

Trying to create an external rule that adds a 'Mass' parameter that will be used in drawing parts list instead of unit QTY. The code seems to work so far achieving the following:

  1. Change document precision to 0 places
  2. Create the parameter (Mass) = to iprop mass
  3. Change the BoM base QTY to use new parameter (Mass)

Works so far, but I cant get the mass in the BoM to change precision to 0. It remains at 3 places as per original ipt template.

After running ruleAfter running rule

Something strange tho, after running the rule, if I click the precision drop down and re-select 0 (even when already set), and then do the same for the parameter in base quantity drop down to mass, it updates the precision correctly to 0 places. Not sure if I'm missing something in the ilogic to make this happen?

 

Dim oDoc = ThisDoc.Document

'-----Change document unit type, comment out as required.-----
oMassType = 11284 'Grams
'oMassType = 11283 'Kilograms
oDoc.UnitsOfMeasure.MassUnits = oMassType
oDoc.UnitsOfMeasure.LengthDisplayPrecision = 0

'-----Create the Mass Parameter if it does not exist.-----
Try
	Parameter("Mass")=Ceil(iProperties.Mass)
Catch
	oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
	oParameter=oMyParameter.AddByExpression("Mass", "5", "g")
	'oParameter=oMyParameter.AddByValue("Mass", "", UnitsTypeEnum.kGramMassUnits)
	Parameter("Mass")=Ceil(iProperties.Mass)
End Try

'-----Change the BoM Quantity to use the Mass parameter.-----
oDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, Parameter.Param("Mass"))
oDoc.ComponentDefinition.BOMQuantity.BaseUnits = "g"

'-----Update the document.-----
 iLogicVb.UpdateWhenDone = True

 

Appreciate any help!

Thanks,

0 Likes
Reply
Accepted solutions (1)
746 Views
2 Replies
Replies (2)

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @creggo 

I don't think you actually want to change the LengthDisplayPrecision. If you set that to 0 and have a dimension in a sketch that is say 15.5 mm, It'll display the dimension as 16.

 

What you want is to change the precision of the parameter you use as base quantity.

 

See code below:

Dim oDoc As Document = ThisDoc.Document

'-----Change document unit type, comment out as required.-----
oMassType = 11284 'Grams
'oMassType = 11283 'Kilograms
oDoc.UnitsOfMeasure.MassUnits = oMassType

'-----Create the Mass Parameter if it does not exist.-----
Try
	Parameter("Mass")=Ceil(iProperties.Mass)
Catch
	oMyParameter=ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
	oParameter=oMyParameter.AddByExpression("Mass", "5", "g")
	'oParameter=oMyParameter.AddByValue("Mass", "", UnitsTypeEnum.kGramMassUnits)
	Parameter("Mass")=Ceil(iProperties.Mass)
End Try

'-----Change the BoM Quantity to use the Mass parameter.-----

Parameter.Param("Mass").Precision = 0 'Set the precision of the parameter

oDoc.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, Parameter.Param("Mass"))
oDoc.ComponentDefinition.BOMQuantity.BaseUnits = "g"

'-----Update the document.-----
 iLogicVb.UpdateWhenDone = True

creggo
Enthusiast
Enthusiast

Perfect! Thank you @JhoelForshav 👍