Autocad 2016 for MAC - read dynamic block properties

Autocad 2016 for MAC - read dynamic block properties

Anonymous
Not applicable
742 Views
2 Replies
Message 1 of 3

Autocad 2016 for MAC - read dynamic block properties

Anonymous
Not applicable

Hi,

 

I'm trying to read the dynamic block properties of a dynamic block.

 

I'm sure the block is a dynamic block, but the helper methods tell me it's not: (I have verified this with MdgDbg on Windows)

 

ads_name ssname;

    

    acedSSGet(NULL, NULL, NULL, NULL, ssname);

    

    Adesk::Int32 length = 0;

    

    acedSSLength(ssname, &length);

    

    ads_name ent;

    AcDbObjectId id = AcDbObjectId::kNull;

    

    for (long i = 0; i < length; i++) {

        if (acedSSName(ssname, i, ent) != RTNORM) continue;

        

        if (acdbGetObjectId(id, ent) != Acad::eOk) continue;

        

        AcDbEntity* pEnt = NULL;

        

        if (acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite) != Acad::eOk) continue;

    

        AcDbBlockReference* block = AcDbBlockReference::cast(pEnt);

        

        if (AcDbDynBlockReference::isDynamicBlock(id)) {

            acutPrintf(_T("\nID is dynamic block"));

        }

        

        if (AcDbDynBlockReference::isDynamicBlock(block->objectId())) {

            acutPrintf(_T("\nObject ID is dynamic block"));

        }

        

        if (AcDbDynBlockReference::isDynamicBlock(block->blockTableRecord())) {

            acutPrintf(_T("\nBlock Table Record is dynamic block"));

        }

}



According to the docu I need to pass the blockTableRecord object id.

 

Does anyone have an idea what the issue could be?

Thanks

BR

0 Likes
Accepted solutions (1)
743 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

Another issue was, that I couldn't retrieve the block properties, this was solved just now:

if (acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead) != Acad::eOk) continue;

makes this work at least.

 

So any idea why the check won't work?

0 Likes
Message 3 of 3

tbrammer
Advisor
Advisor
Accepted solution

I use this function to determine whether a block is dynamic. It takes the objectId of a BREF or a BTR to test:

 

bool isDynamicBlock(const AcDbObjectId &objId)
{
	AcDbObject	   *pObj;
	AcDbBlockReference *pBref;
	AcDbBlockTableRecord *pBTR;
	Acad::ErrorStatus es;
	AcDbObjectId blockTableRecordId;
	bool bIsBref=false, 
	     bIsDynamic = false;

	// Is objId a BREF or a BTR?
	es = acdbOpenObject(pObj, objId, AcDb::kForRead);
	if (es==Acad::eOk)
	{	
		if (pBref = AcDbBlockReference::cast(pObj))
		{
			blockTableRecordId = pBref->blockTableRecord();
			bIsBref = true;

			AcDbDynBlockReference dynBlockRef(pBref);
			// dynBlockRef.isDynamicBlock(); is not enough
			// It only returns true if the original source block is referenced!
			AcDbObjectId  dynBTRid = dynBlockRef.dynamicBlockTableRecord();
			if (!dynBTRid.isNull())
				bIsDynamic = AcDbDynBlockReference::isDynamicBlock(dynBTRid);
		}
		else if (pBTR = AcDbBlockTableRecord::cast(pObj))
		{
			blockTableRecordId = objId;
			bIsBref = false;
		}
		pObj->close();

		if (!bIsDynamic)
			bIsDynamic = AcDbDynBlockReference::isDynamicBlock(blockTableRecordId);
	}

	return bIsDynamic;
}

 I haven't tried it on a MAC. But it should work the same.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.