How to grab "Base Quantity" with iLogic

How to grab "Base Quantity" with iLogic

Andrew1307
Enthusiast Enthusiast
3,796 Views
5 Replies
Message 1 of 6

How to grab "Base Quantity" with iLogic

Andrew1307
Enthusiast
Enthusiast

In the process of implementing an ERP system and need to link the QTY of raw material used in parts to be exported. I have created two custom iProperties, MaterialStockCode & MaterialQTY, that are filled appropriately and then exported along with the BOM. I have my iLogic code that fills these in based on what type of part it is; sheet metal is extents area and outsourced laser cut is by each. Now I am trying to set this up for cut to length parts that come out of the content center, and custom shapes I put into content center. What I am noticing though is not all parts use the same G_L parameter as the Base Quantity.

 

So instead of trying to link a parameter to my custom MaterialQTY, what I want to do is grab what ever value is being used as "Base Quantity" and put that to MaterialQTY. But how do I grab that? In an inventor BOM its listed as BASE QTY. 

 

Screenshot 2016-02-04 13.27.47.png

0 Likes
Accepted solutions (2)
3,797 Views
5 Replies
Replies (5)
Message 2 of 6

rjay75
Collaborator
Collaborator

You're in luck as I just did this not to long ago.

 

SyntaxEditor Code Snippet

    If ThisDoc.Document.DocumentType = kPartDocumentObject Then    
        'See If the BOM Qty has been Overridden. If so use it.
        Dim qType As BOMQuantityTypeEnum
        Dim qQty As Object
        ThisDoc.Document.ComponentDefinition.BOMQuantity.GetBaseQuantity(qType, qQty)
        If qType = BOMQuantityTypeEnum.kParameterBOMQuantity Then
            Dim qParam As Parameter = qQty
            Dim dbUnits As String = uom.GetDatabaseUnitsFromExpression(qParam.Expression, qParam.Units)
            iProperties.Value("Custom","MAT_Qty") = uom.ConvertUnits(qParam.ModelValue, dbUnits, qParam.Units)
        End If
    End If
Message 3 of 6

Andrew1307
Enthusiast
Enthusiast

@rjay75 wrote:

You're in luck as I just did this not to long ago.

 

SyntaxEditor Code Snippet

    If ThisDoc.Document.DocumentType = kPartDocumentObject Then    
        'See If the BOM Qty has been Overridden. If so use it.
        Dim qType As BOMQuantityTypeEnum
        Dim qQty As Object
        ThisDoc.Document.ComponentDefinition.BOMQuantity.GetBaseQuantity(qType, qQty)
        If qType = BOMQuantityTypeEnum.kParameterBOMQuantity Then
            Dim qParam As Parameter = qQty
            Dim dbUnits As String = uom.GetDatabaseUnitsFromExpression(qParam.Expression, qParam.Units)
            iProperties.Value("Custom","MAT_Qty") = uom.ConvertUnits(qParam.ModelValue, dbUnits, qParam.Units)
        End If
    End If

Ok so 

ThisDoc.Document.ComponentDefinition.BOMQuantity.GetBaseQuantity(qType, qQty)

Gets the base quantity object and stores the values in qType and qQty

 

If qType = BOMQuantityTypeEnum.kParameterBOMQuantity Then

 Checks if the type is kParameterBOMQuantity... which means what exactly? If it is left as the defualt each then this would be false?

 

Dim dbUnits As String = uom.GetDatabaseUnitsFromExpression(qParam.Expression, qParam.Units)
            iProperties.Value("Custom","MAT_Qty") = uom.ConvertUnits(qParam.ModelValue, dbUnits, qParam.Units)

Here you are grabbing the units and then converting them somehow... I am not at all familar with this. Can you explain to me what is going on here?

 

Thanks a lot! 

0 Likes
Message 4 of 6

rjay75
Collaborator
Collaborator
Accepted solution

Yea it could use some more explanation.

 

 

SyntaxEditor Code Snippet

'Get the document UnitOfMeasure object to facilitate unit conversions
Dim
uom As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure

'Check to be sure we are on a part document
If ThisDoc.Document.DocumentType = kPartDocumentObject Then
'Initialize a variable for the type and to hold the BOMQuantity Object
Dim qType As BOMQuantityTypeEnum
Dim qQty As Object

'Get the type and quantity object
ThisDoc.Document.ComponentDefinition.BOMQuantity.GetBaseQuantity(qType, qQty)

'Determine what kind of Quantity type it is
'BOMQuantityTypeEnum.kParameterBOMQuantity : The qQty is the parameter that represents the BOM quantity value.
'BOMQuantityTypeEnum.kEachBOMQuantity : The qQty object is set to Nothing.
If qType = BOMQuantityTypeEnum.kParameterBOMQuantity Then

'Get the Parameter
Dim qParam As Parameter = qQty

'Determine what database units the parameter is set to using the UnitOfMeasure object.
Dim dbUnits As String = uom.GetDatabaseUnitsFromExpression(qParam.Expression, qParam.Units)

'qParam.ModelValue will be returned in database units, the value needs to be converted to desired output
'units. In this case it's output in the same units as the parameter is set to.
'The iProperty MAT_Qty is set as a numeric value to whatever the converted value is.
iProperties.Value("Custom","MAT_Qty") = uom.ConvertUnits(qParam.ModelValue, dbUnits, qParam.Units)

End If
End If

 

 

Message 5 of 6

Andrew1307
Enthusiast
Enthusiast

Perfect! Thank you so much. 

 

Further on to this can I use simlar code to set a part to each? ie. I take something from content center but make it a custom part, programically change it to each to line up with ERP. 

 

Also extract what the Base Unit is? (unit of measure)

0 Likes
Message 6 of 6

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

Hi Andrew,

 

Change Base Quantity to Each:

  Dim doc As PartDocument
  Set doc = ThisApplication.ActiveDocument
  
  Call doc.ComponentDefinition.BOMQuantity.SetBaseQuantity(kEachBOMQuantity)

Get Base Unit:

  Dim baseUnit As String
  baseUnit = doc.ComponentDefinition.BOMQuantity.BaseUnits

 

Cheers,



Adam Nagy
Autodesk Platform Services