Get the layout an entity belongs to

By Adam Nagy

I'm migrating my LISP project to ARX. In LISP I can use (entget) to find the layout name at group code 410. How can I do the same in ARX?

Solution

You need to get the owner block of the entity and from there you can get to the layout object.

static void ArxProject_GetLayout(void)

{

  ads_name name;

  ads_point pt;

  if (acedEntSel(L"Select an entity\n", name, pt) != RTNORM)

    return;

 

  AcDbObjectId id;

  acdbGetObjectId(id, name);

 

  AcDbEntityPointer ptrEnt(id, AcDb::kForRead);

  if (ptrEnt.openStatus() != Acad::eOk)

    return;

 

  AcDbBlockTableRecordPointer ptrBTR(ptrEnt->ownerId(), AcDb::kForRead);

  if (ptrBTR.openStatus() != Acad::eOk)

    return;

 

  AcDbObjectPointer<AcDbLayout> ptrLayout(ptrBTR->getLayoutId(), AcDb::kForRead);

  if (ptrLayout.openStatus() != Acad::eOk)

    return;

 

  const ACHAR* layoutName;

  ptrLayout->getLayoutName(layoutName);

 

  acutPrintf(L"The layout the selected entity belongs to is %s", layoutName);

}


Comments

One response to “Get the layout an entity belongs to”

  1. Thanks for yet another helpful post!

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading