09/23/2013

Get AutoCAD Mechanical Assembly Properties values

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)

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.

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;

publicrefclass MixedManagedUtils

{

public:

staticvoid 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:

Comments

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)

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.

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;

publicrefclass MixedManagedUtils

{

public:

staticvoid 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: