Get AutoCAD Mechanical Assembly Properties values

By Adam Nagy

It seems that GetPartAttribute and GetPartData do not retrieve the correct evaluated value for model space that contains the assembly data if it is based on an expression, e.g.: =IF(ISBLANK(PART:NAME),BLOCK:NAME,PART:NAME)


Assemblyproperties

The C++ API's AcmBOMManager has a function called getBomOverride which seems to retrieve in its currentValue parameter the correct value. Unfortunately, this does not seem to have an exact equivalent in the COM API, where you could pass in the model space object. 

If you have a .NET AddIn then you could access the C++ function from it like done here: http://adndevblog.typepad.com/aec/2013/09/call-c-api-functions-from-net-addin.html

So we need to create an ARX project with .NET and MFC support – you can use the ARX Wizard for that. Make sure all the include and library folders of the AutoCAD Mechanical SDK are set in the project and then can add the following in the project, e.g. in acrxEntryPoint.cpp:

// AcDbBlockTableRecordPointer

#include "dbobjptr.h"

 

// AutoCAD Mechanical

#include "acm.h"

#include "acmdef.h"

#include "bommgr.h"

 

// You also have to add these to the "Additional Dependencies"

// of the project:

// rxapi.lib;acge19.lib;ac1st19.lib;acdb19.lib;accore.lib;

// acad.lib;acgiapi.lib;acmsymbb.lib;

 

public ref class MixedManagedUtils

{

public

  static void AcmBOMManager_getBomOverride(

    System::String^ name,

System::String^% value)

  {

AcDbBlockTableRecordPointer ptrMS(

ACDB_MODEL_SPACE,

acdbHostApplicationServices()->workingDatabase(),

AcDb::kForRead);

 

if (ptrMS.openStatus() != Acad::eOk) { ASSERT(0); return; }

 

pin_ptr<const ACHAR> strName = PtrToStringChars(name);

 

ACHAR* strOrigValue = NULL; 

ACHAR* strOriData = NULL;

ACHAR* strCurValue = NULL;

ACHAR* strCurData = NULL;

 

Acm::BomOverrideType ordtype;

bool iseditable;

acmBomMgr->getBomOverride(ptrMS->objectId(), strName,

strOrigValue, strOriData, strCurValue, strCurData,

ordtype, iseditable);

 

value = gcnew System::String(strCurValue);

  }

};

Now you can use this mixed-managed dll from your AutoCAD .NET AddIn. Just have to add a reference to the compiled dll/assembly and you can call the utility function we wrote:

<CommandMethod("GETASSEMBLYPROPERTY")> _

Public Sub TESTSYMBBAUTO()

    Dim value As String = ""

    MixedManagedUtils.AcmBOMManager_getBomOverride("NAME", value)

    MsgBox(value)

End Sub

The utility dll needs to be loaded inside AutoCAD before you try to call its functions. There are multiple ways to load a .NET dll into AutoCAD, so you can pick the one you prefer: http://adndevblog.typepad.com/autocad/2012/04/load-additional-dlls.html

The utility ARX project is here:
Download MixedManagedUtils_2013-09-23  


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading