Accessing Base Quantity in Part File using iLogic

Accessing Base Quantity in Part File using iLogic

amarinXG8V6
Advocate Advocate
532 Views
5 Replies
Message 1 of 6

Accessing Base Quantity in Part File using iLogic

amarinXG8V6
Advocate
Advocate

I would like to access the Base Quantity in an iLogic rule and set it to another parameter. When I run the code below I get an error on line 5. Could I get some feedback on what I'm doing wrong here? Thank you in advance!

 

amarinXG8V6_0-1677610310830.png

amarinXG8V6_1-1677610337364.png

 

0 Likes
Accepted solutions (1)
533 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Here you go.  I don't know what type of parameter that blue parameter represents, but it would need to be text/String, because the BaseUnits property is a String value.

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oOtherParam As Inventor.Parameter = oCompDef.Parameters.Item("Base Quantity")
oCompDef.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, oOtherParam)

 

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

WCrihfield
Mentor
Mentor

Sorry about the initial confusion.  The BOMQuantity object is located just under the ComponentDefinition, and it has several methods & properties.  I initially misread the post and though you said 'Base Units'.  There is also a property for Unit Quantity.  But there are two methods for getting, and one method for setting the current setting/value for the 'Base Quantity'.  The GetBaseQuantity method requires you to first create the two types of variables, then input them into the method, then the method will set their values.  The second variable will only get a value if the quantity type is based on a parameter, instead of Each.  Then the SetBaseQuantity method requires you to specify which type of quantity you are setting, then if it is parameter based, it wants you to input the parameter object.  If supplying a parameter object, it must be a numerical one, with something like length, volume, or mass type value.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 6

amarinXG8V6
Advocate
Advocate

Hi @WCrihfield ,

 

Thank you for the response. I looked through the links you provided for how to get and set the BOM quantity but I'm having a hard time formulating the syntax. I have the Base Quantity on this specific part pointing to a parameter named G_L. I would like to write the iLogic code so that it instead points to a different parameter called NominalBOMLength.

 

What is the proper syntax to do that?

 

amarinXG8V6_0-1677614833216.png

 

amarinXG8V6_1-1677615013235.png

 

Thank you,

Alex

0 Likes
Message 5 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

try this:

Dim doc As PartDocument = ThisDoc.Document
Dim def As PartComponentDefinition = doc.ComponentDefinition

Dim parameter = def.Parameters.Item("NominalBOMLength")

def.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, parameter)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 6 of 6

amarinXG8V6
Advocate
Advocate
Thank you so much! This worked great.
0 Likes