AutoCAD Mechanical Forum
Welcome to Autodesk’s AutoCAD Mechanical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Mechanical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert Part Reference (VBA)

1 REPLY 1
Reply
Message 1 of 2
pfabio
458 Views, 1 Reply

Insert Part Reference (VBA)

In my VBA macro I want insert a new part reference. Which command I must use? Have you an example? Thanks

Best regards

Note: I use Autocad Mechanical 2004 DX
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: pfabio

Below is a VBA example, which shows how to insert part reference and set
part reference attributes. You will have to reference to "Autodesk SymBBAuto
2.0 Type Library".

Sub createPartReference()
Dim oAcApp As AcadApplication
Dim oAcUtil As AcadUtility
Set oAcApp = GetObject(, "AutoCAD.Application")
Set oAcUtil = oAcApp.ActiveDocument.Utility

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

Dim oSymbb As McadSymbolBBMgr
Set oSymbb =
ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
Dim oBommgr As McadBOMMgr
Set oBommgr = oSymbb.BOMMgr

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) = "Comp1"

oBommgr.SetPartData oPartref, pdata
ThisDrawing.Application.Update
End Sub

---
Kar Poh
Developer
Manufacturing Solutions Division
Autodesk, Inc.

wrote in message news:4878834@discussion.autodesk.com...
In my VBA macro I want insert a new part reference. Which command I must
use? Have you an example? Thanks

Best regards

Note: I use Autocad Mechanical 2004 DX

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

Post to forums  

Autodesk Design & Make Report

”Boost