BOM

BOM

grobnik
Collaborator Collaborator
1,212 Views
1 Reply
Message 1 of 2

BOM

grobnik
Collaborator
Collaborator

Dear All, I read a lot of past post about Mechanical BOM extraction and so on, but most of them are written in C# or VB.NET or are related to past product dated 2012,and older. I have Autocad Mechanical 2018, and I found a way to access to part reference object and related BOM typical of Mechanical version. But my issue is related how to insert a new part reference inside my modelspace and attach to a specific object or geometry trough VBA code. Here below I tried a simple code to retrive part reference properties: 

Sub Bill()
    'Managers to extract/parse AutoCAD drawing information
    Dim symBB As McadSymbolBBMgr
    Dim bomMGR As McadBOMMgr
    Dim BOM As McadBOM
    Dim bomITEM As McadBOMItem
    Dim name As String
    Dim BOMbit As String
    Dim data As Variant


    'Defines the bill of materials managers for extraction
    Set symBB = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
    Set bomMGR = symBB.bomMGR

'Tests for BOM with the name "MAIN" in drawing, "MAIN" is default when no title border is selected
    If bomMGR.BOMTableExists(ThisDrawing.ModelSpace) Then
        Set BOM = bomMGR.GetBOMTable(ThisDrawing.ModelSpace, "MAIN")
    Else
        ThisDrawing.Utility.Prompt "No Usable Parts List"
        End
    End If

    For Each bomITEM In BOM.Items
        data = bomITEM.data
        For i = LBound(data) To UBound(data)
            'data(i, 0) is the what the general name of column
            'data(i, 1) is the value in the cell
            If data(i, 0) = "MATERIAL" Then
                data(i, 1) = "CHANGE THIS VALUE"
            End If
        Next
    Next
End Sub

Above code working fine, but it's retrive already defined part reference, but I'm not able to find a way to insert a new part reference in a specific point, and as second issue, I'm not able to find coordinates of part reference found. Is there somewhere documentation about BOM and VBA ? Thank you for help

0 Likes
1,213 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Searching for other stuff, I found this one: https://narkive.com/ppZnPOJN.4

It seems to fit the first question what you're looking for:

Dim pt As Variant
pt = ThisDrawing.Utility.GetPoint(, "Location for ampartref: ")
pt = ThisDrawing.Utility.TranslateCoordinates(pt, acUCS, acWorld, False)
Dim mpartref As McadPartReference
Set mpartref = ThisDrawing.ModelSpace.AddCustomObject("AcmPartRef")
mpartref.Origin = pt

 

0 Likes