setting Base Quantity to m^2 with iLogic

setting Base Quantity to m^2 with iLogic

nathan_m_gardner
Enthusiast Enthusiast
174 Views
5 Replies
Message 1 of 6

setting Base Quantity to m^2 with iLogic

nathan_m_gardner
Enthusiast
Enthusiast

We model some parts that are purchased as 50mm thick rolls (insulation) and need to display the sq meter of the part. These parts vary in size and shape. To do this, we have used the parts volume and divided it by 50(the thickness of the insulation). The issue comes with setting this in the "Bill of Materials" tab under "Base Quantity".

The code is to create the parameters; however, we need to go into the parameter and change the units to "m" before we are able to select the parameter from the pull-down list under "Base Quantity". Once it is selected, close out of the Doc settings and go back to parameters and switch the units back to m^2. Then, back to "Base Quantity," verify the parameter is selected, then use the formula button to select the parameter again. This seems to be the only way to get this to work.

 

Disclosure:

I am not a coder, so I am sure there are several issues with the code below. Is there a better way to achieve the end goal?

 

Any suggestion would be greatly appreciated!

 

 

Two different codes to achieve this:(same issue with both)

1.

Parameter("VOL") = iProperties.Volume
Parameter("AREA_INS") = iProperties.Volume/50.0 mm

iProperties.Value("Custom","MATERIAL LIST DESCRIPTION") = "50mm BATTS"

 

 

 

2.

' Check if "VOL" exists
Dim found As Boolean = False
For Each param As Parameter In ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
    If param.Name = "VOL" Then
        found = True
        Exit For
    End If
Next

' Create VOL if missing, using unit string instead of enum
If Not found Then
    ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByValue("VOL", 1, "m^3")
End If

' Assign volume to VOL
VOL = iProperties.Volume

' Check if "AREA_INS" exists
Dim found2 As Boolean = False
For Each param As Parameter In ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
    If param.Name = "AREA_INS" Then
        found2 = True
        Exit For
    End If
Next

' Create AREA_INS if missing, using unit string instead of enum
If Not found2 Then
    ThisDoc.Document.ComponentDefinition.Parameters.UserParameters.AddByValue("AREA_INS", 1, "m^2")
End If

' Assign area to AREA_INS
AREA_INS = iProperties.Volume/50 mm


' Assign New Parameters
Parameter("VOL") = iProperties.Volume
Parameter("AREA_INS") = iProperties.Volume/50 mm

iProperties.Value("Custom","MATERIAL LIST DESCRIPTION") = "50mm BATTS"

 

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

Andrii_Humeniuk
Advisor
Advisor

Hi @nathan_m_gardner .
The following iLogic code is written using the Inventor API without using Snippets. It may seem overly complex to you, but it works reliably and solves your problem.

This code stops working if the part volume is 0, this exception allows you to add this code to the template and set the necessary event triggers.

Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
If oPDoc Is Nothing Then Exit Sub
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim dVOL As Double = oPDef.MassProperties.Volume
If dVOL = 0 Then Exit Sub
Dim oUsParams As UserParameters = oPDef.Parameters.UserParameters

Try
	oUsParams("VOL").Value = dVOL
Catch
	Dim oUsParam As UserParameter = oUsParams.AddByValue("VOL", dVOL, "m m m")
	oUsParam.ExposedAsProperty = True
	Call oPDef.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, oUsParam)
End Try

Try : oUsParams("AREA_INS").Value = dVOL / 5
Catch : oUsParams.AddByValue("AREA_INS", dVOL / 5, "m m")
End Try

Dim oCustom As PropertySet = oPDoc.PropertySets("Inventor User Defined Properties")
Try : oCustom("MATERIAL LIST DESCRIPTION").Value = "50mm BATTS"
Catch : oCustom.Add("MATERIAL LIST DESCRIPTION", "50mm BATTS") : End Try

 If you have any questions or problems, I'll be happy to help.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 6

nathan_m_gardner
Enthusiast
Enthusiast

Thank you I will give this a try

 

0 Likes
Message 4 of 6

nathan_m_gardner
Enthusiast
Enthusiast

I just gave this a try, and I have the same results. Both parameters are created and Visible in the Parameter window.

nathan_m_gardner_1-1754566723544.png

When I enter the Document settings>Bill of Materials, I can not select "AREA_INS" from the pull down.

nathan_m_gardner_0-1754566662595.png

If I select the parameter button, I can see all User parameters, including "AREA_INS". If I try to select "AREA_INS" nothing happens. The value does not change in the pulldown.

nathan_m_gardner_2-1754566767912.png

 

 

0 Likes
Message 5 of 6

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

There can only be one Base Quantity for each element, if you need to set the AREA_INS parameter then you need to use the following code:

Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, PartDocument)
If oPDoc Is Nothing Then Exit Sub
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim dVOL As Double = oPDef.MassProperties.Volume
If dVOL = 0 Then Exit Sub
Dim oUsParams As UserParameters = oPDef.Parameters.UserParameters

Try
	oUsParams("VOL").Value = dVOL
Catch
	Dim oUsParam As UserParameter = oUsParams.AddByValue("VOL", dVOL, "m m m")
End Try

Try
	oUsParams("AREA_INS").Value = dVOL / 5
Catch
	Dim oUsParam As UserParameter = oUsParams.AddByValue("AREA_INS", dVOL / 5, "m m")
	oUsParam.ExposedAsProperty = True
	oUsParam.Units = "m"
	Call oPDef.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, oUsParam)
	oUsParam.Units = "m m"
End Try
Dim oCustom As PropertySet = oPDoc.PropertySets("Inventor User Defined Properties")
iProperties.Value("Custom","MATERIAL LIST DESCRIPTION") = "50mm BATTS"

Also in inventor there is a problem with setting area as the base unit, but it is not impossible. This topic describes a method that allows this.

In the code, I implemented this capability by converting the unit of measurement to length and then to area.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 6 of 6

nathan_m_gardner
Enthusiast
Enthusiast

Yes, I understand there can be only one. This one works great. Thank you very much.

0 Likes