Edit Part BOM Base Quantity

Edit Part BOM Base Quantity

pball
Mentor Mentor
1,392 Views
4 Replies
Message 1 of 5

Edit Part BOM Base Quantity

pball
Mentor
Mentor

There is an interesting thread on the general Inventor forum about setting a part to a partial quantity. So instead of having a part be qty 1 it could be qty .1, which would allow items that come in packs to display pack quantities on drawings. There is actually a work around to enable this, but it's pretty clunky and I'd like to automate it. I tried copying the work around in VBA but I'm stuck at the last step which seems to require manually opening the parameters dialog from the BOM tab in the Document Settings.

 

Here is part 1 and part 2 of Johnson's work around, unfortunately the last step in his second post is the point I'm stuck at.

 

The code can properly set the Base quantity but the unit quantity won't update. I tried toggling the export option on the user parameter but that didn't seem effect it. Opening the parameter dialog from this Documents dialog and simply closing it forces the Unit Quantity to update. Do note opening the parameter dialog normally does not cause the Unit Quantity to update, some how opening it from the Document Settings dialog is what appears to trigger the update. So unless that can be emulated via the API somehow this might not be possible.

image.png

 

Public Sub bomqty()
    Dim oPart As PartDocument
    Set oPart = ThisApplication.ActiveEditDocument
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPart.ComponentDefinition

    Dim Qty As Double
    temp = InputBox("Enter the Qty", "Quantity", "1")

    If Not IsNumeric(temp) Then
        MsgBox ("Please enter a number")
        Exit Sub
    Else
        Qty = temp
    End If
    
    On Error Resume Next
    
    If Qty = 1 Then
        Call oCompDef.BOMQuantity.SetBaseQuantity(kEachBOMQuantity)
        oCompDef.Parameters.UserParameters.Item("qty").Delete
    Else
        Dim oUserParam As UserParameter
        Set oUserParam = oCompDef.Parameters.UserParameters.Item("qty")
        
        'update qty param if exist
        oUserParam.Value = Qty * 2.54
        oUserParam.Units = "in"
        
        'create qty param if not exists
        If (Err.Number <> 0) Then Set oUserParam = oCompDef.Parameters.UserParameters.AddByValue("qty", Qty * 2.54, "in")
        
        'set qty param as base quantity
        Call oCompDef.BOMQuantity.SetBaseQuantity(kParameterBOMQuantity, oUserParam)
        
        'change qty param units and update value
        oUserParam.Units = "ul"
        oUserParam.Value = Qty
                
        oUserParam.ExposedAsProperty = True
        oPart.Update
    End If
End Sub

Also there is at least one Idea post to officially add partial qty for parts. Please vote if you like the idea. Part unit quantity ability to enter fractional or decimal for the quantity 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
1,393 Views
4 Replies
Replies (4)
Message 2 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @pball ,

 

hmmm... its really close, but I'm not sure if we can replicate that "sneaky" workaround that Johnson mentioned on the other thread.

 

I took your code and sort of boiled it down to make a quick and dirty ilogic example for testing, and I pretty much ended up where you were, in that it creates the parameter and changes the parameter units to "ul" but we just can't get it to accept ul for the BOMQuantity.Base unit

 

In the workaround, clicking the edit parameter button and then just closing the parameter dialog without doing anything seems to "catch" the unit mismatch and reset it, but thus far I've not been able to replicate that.

 

not sure if it helps, but here is my attempt

 

Dim oPart As PartDocument
oPart = ThisApplication.ActiveEditDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oPart.ComponentDefinition

Dim Qty As Double
Qty = 0.5

'delete it to make sure we can create it again for testing
Try
oCompDef.Parameters.UserParameters.Item("qty").Delete
Catch
End Try

'create qty param
Dim oUserParam As UserParameter
oUserParam = oCompDef.Parameters.UserParameters.AddByValue("qty", Qty * 2.54, "in")

'qty param as base quantity
Call oCompDef.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, oUserParam)

'change qty param units and update value
oUserParam.Units = "ul"
oUserParam.Expression = Qty 

Try 'try nothing ul
oCompDef.BOMQuantity.BaseUnits = "ul"	
Catch  
End Try

Try 'try nothing 
oCompDef.BOMQuantity.BaseUnits = ""	
Catch 	
End Try

Try 'try space 
oCompDef.BOMQuantity.BaseUnits = " "
Catch 	
End Try

oPart.Update

'MsgBox("BOMQuantity.BaseUnits: " & vbLf & oCompDef.BOMQuantity.BaseUnits)

'open doc settings
Dim oCommandMgr As CommandManager 
oCommandMgr = ThisApplication.CommandManager 
oControlDef = oCommandMgr.ControlDefinitions.Item("AppDocumentSettingsCmd")
Call oControlDef.Execute2(False) 

EESignature

0 Likes
Message 3 of 5

Maxim-CADman77
Advisor
Advisor

Couple days ago I was searching the forum for some keyword like 'keypress' and saw a thread (Curtis participated) where somebody (i believe @MjDeck) posted the code to open the Inventor dialog at particular tab (if not mistaken it was about iProperty) (it was about BOM Editor).
Unfortunately I can't find the thread now but
I wonder If that code applicable to DocumentSettings Dialog and also if it then possible to additionally emulate pressing that 'Unit-updating' button?

UPDATE #1:

Here is that post !

 

UPDATE #2:

It was decided that this approach is not applicable because DocumentSettings Dialog (unlike BOM editor dialog) is modal.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 5

Maxim-CADman77
Advisor
Advisor

It seems impossible to get TabControl of DocumentSettings dialog by name (there is no value)

MaximAnatoljevich_0-1692605280297.png

Instead of

Dim tabControl = element.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.AutomationIdProperty, "tabControl1")

Some ID reference, Advanced Mode etc should be used, but I don't know the right syntax 😞

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 5

Maxim-CADman77
Advisor
Advisor

This is probably of no help ... but ... just in case:
I've set up Event Watcher (component of SDK DevTools) to log all DocumentEvent on Parameters button press and it logged "OnChangeSelectSet" event:

MaximCADman77_0-1695111325339.png

 

 

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes