VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ACADM Parts List not updating with new PartRef

0 REPLIES 0
Reply
Message 1 of 1
markhoward2
322 Views, 0 Replies

ACADM Parts List not updating with new PartRef

I could use a second opinion, or guiding light. I'm trying to create a PartRef and insert it into any existing block. For whatever reason, I can do this manually with AMPARTREF and "BLOCK" option. When I do it via VBA, the Parts List does not update. If I insert ouside of block, maybe free or attached, it updates. If I insert it inside, then close and re-open the drawing it will update if I insert the same block I just attached a PartRef to. If I explode the block it will count that one in the Parts List.

 

As a secondary problem, inserting outside but attached, I cannot seem to get the same 'pick' to fill the object for that attachment. I can't grasp the difference between 'Object and IMcadObject.

 

Thanks for any insight in advance!

 

Public Sub PartRefInBlockRef()

'Get symbol Manager
    Dim oSymBBMgr As McadSymbolBBMgr
    Set oSymBBMgr = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
    'Set oSymBBMgr = Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")

'Get BOM Manager
    Dim oBOMMgr As McadBOMMgr
    Set oBOMMgr = oSymBBMgr.bommgr
    
'Get standard manager
    Dim stdMgr As McadStandardMgr
    Set stdMgr = oSymBBMgr.StandardMgr
    
'Get current standard
    Dim currentStd As McadStandard
    Set currentStd = stdMgr.CurrentStandard
    
'Get BOM Standard
    Dim BOMStd As McadBOMStandard
    Set BOMStd = currentStd.BOMStandard

'Get all BOM visible columns from BOM standard
    Dim BOMcol As McadColumnDefinitions
    Set BOMcol = BOMStd.Columns

'Select Block to insert PartRef in, and origin point
    'Dim acmApp As AcadmApplication
    'Set acmApp = ThisDrawing.Application.GetInterfaceObject("AcadmAuto.AcadmApplication")
    'Dim uti As McadUtility
    'Set uti = acmApp.ActiveDocument.Utility
    Dim oAcApp As AcadApplication
    Set oAcApp = GetObject(, "AutoCAD.Application")
    Dim oAcUtil As AcadUtility
    Set oAcUtil = oAcApp.ActiveDocument.Utility
    
    Dim pt As Variant
    Dim oBlockDef As AcadBlock
    Dim oBlockRef As AcadBlockReference
    Dim oObject As Object
    Dim object As IMcadObject
    Dim txtBname As String

    oAcUtil.GetEntity oObject, pt
    If TypeOf oObject Is AcadBlockReference Then
        Set oBlockRef = oObject
        Set oBlockDef = ThisDrawing.Blocks(oBlockRef.Name)
        'Set object = ???? 'can not use same pick to attach to block
        txtBname = oBlockDef.Name
        pt = oAcUtil.TranslateCoordinates(oBlockDef.Origin, acUCS, acWorld, False)
    Else
        Err.Raise 1, "PartRefToBlockRef", "Selected entity was NOT a block"
    End If

    Dim oPartRef As McadPartReference
    
'insert PartRef attached to block at block origin
    'Set oPartRef = ThisDrawing.ModelSpace.AddCustomObject("AcmPartRef")
    'oPartref.AttachGeometry object, pt 'can not use same pick to attach to block
'insert PartRef in block at block origin
    Set oPartRef = oBlockDef.AddCustomObject("AcmPartRef")
    oPartRef.Origin = pt

    Dim pdata(0 To 5, 0 To 1) As String
    pdata(0, 0) = "DESCR": pdata(0, 1) = "My Description"
    pdata(1, 0) = "STANDARD": pdata(1, 1) = "My Standard"
    pdata(2, 0) = "MATERIAL": pdata(2, 1) = "My Material"
    pdata(3, 0) = "NOTE": pdata(3, 1) = "My Note"
    pdata(4, 0) = "VENDOR": pdata(4, 1) = "My Vendor"
    pdata(5, 0) = "NAME": pdata(5, 1) = txtBname
    
    oBOMMgr.SetPartData oPartRef, pdata

End Sub
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost