Author Topic: Using VB.Net to create a part reference and attach to an existing block  (Read 1595 times)

0 Members and 1 Guest are viewing this topic.

CeresCad

  • Mosquito
  • Posts: 1
Hi,

Is it possible to create a new part reference and attach it to a block in AutoCAD Mechanical 2022 using VB.net? What I am trying to do is grab a selected block reference, create a part reference and attach that to the selected block reference and then fill in custom part reference property fields.

So for instance, I would select a block (or multiple blocks) and then write a command that would take the block name (my companies part number) and then automate pulling information and populating the part reference property fields with a description, manufacturer and manufacturer part number based on the block name. I have added those custom properties [MFG, MFG_PN, Description] into the BOM/parts list within AutoCAD Mechanical, but I'm not sure how to access them since they won't be native properties of the part reference class.

I have looked into the Developer's Guide for AutoCAD Mechanical and see some of the VBA stuff, but I don't know exactly how to translate that information into VB.Net since ThisDrawing and .AddCustomObject are not supported in VB.Net.

ex from Acad Mech Dev Guide.

Set oSymBB = ThisDrawing.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
Set oPartRef = ThisDrawing.ModelSpace.AddCustomObject("AcmPartRef").

If anyone has worked with part references in VB.Net before I would greatly appreciate any guidance that they might impart. As I stated above, I'm specifically looking at creating a new part reference, attaching it to an existing block reference and accessing customized  Thanks, Ian.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8696
  • AKA Daniel
Seems like it should be possible.
Haven’t worked with mechanical for years  :mrgreen:
you can look in the C++ API for hints regarding object properties, or use the object browser in visual studio.
The documentation is sparse, I’d start by grinding through the samples. There’s a C++ sample for part ref, maybe you can use it as a guide