Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ObjectARX -> How to get attribute information from inserted block

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
479 Views, 2 Replies

ObjectARX -> How to get attribute information from inserted block

I know how to insert a block with attribute information, but having trouble
to do it reversely.
I tried the following codes, Is it in right track? What is wrong and what to
do next?
Very appreciated for your help!
Joe

void CTest::GetAttribute(ads_name ent) {
AcDbObjectId id;
acdbGetObjectId(id, ent);

AcDbEntity *pEnt;
acdbOpenObject(pEnt, id, AcDb::kForRead);
if ((CString)pEnt->isA()->name() == "AcDbBlockReference") {
AcDbBlockReference *pBR;
pBR = AcDbBlockReference::cast(pEnt); // error -> undefined
AcDbBlockReference
AcDbObjectIterator *pI;
pI = pBR->attributeIterator();
pBR->close();

for (pI->start(); !pI->done(); pI->step()) {

}
delete pI;
}
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

If I understand correctly, you want to select a block and then get to the attribute tag...Maybe try using acedNEntSelP or acedEntSel

retCode = acedEntSel("\nPick the Block:", ent, Pt)
switch(retCode)
{...}
acdbGetObjectId(eid, ent);
acdbOpenAcDbEntity(pEnt, eId, AcDb::kForRead);
//cast to see if its a block
//then create a attribute iterator

I am currently fighting with this and trying to get it to work...hope this is kind of what you are looking for.

jason
Message 3 of 3
Anonymous
in reply to: Anonymous

Thanks. I figured it out,
size=2>no cast is needed.

Check the following code, it
works!

Joe

 

 

retCode = acedEntSel("\nPick the Block:", ent, Pt)
switch(retCode)

{...}
acdbGetObjectId(eid, ent);
CTest *myTest =  new
CTest;

CString tagValue = myTest->GetAttribute(eid, "Tag:");

face=Arial size=2>...

 

// input -> block id and attribute tag
fileld

// output -> attribute tag value

CString CTest::GetAttribute(AcDbObjectId id,
CString ta) {
 AcDbBlockReference *pBR;
 acdbOpenObject(pBR, id,
AcDb::kForRead);

 

 AcDbObjectIterator *it;
 it =
pBR->attributeIterator();
 pBR->close();

 

 AcDbAttribute *pA;
 CString s1,
s2;
 for (it->start(); !it->done(); it->step()) {
 
acdbOpenObject(pA, it->objectId(), AcDb::kForRead);
  s1 =
pA->tag();
  if (s1 == ta)
   s2 =
pA->textString();
  pA->close();
 }
 delete
it;

 

 return s2;
}

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
If
I understand correctly, you want to select a block and then get to the
attribute tag...Maybe try using acedNEntSelP or acedEntSel

retCode = acedEntSel("\nPick the Block:", ent, Pt)
switch(retCode)

{...}
acdbGetObjectId(eid, ent);
acdbOpenAcDbEntity(pEnt, eId,
AcDb::kForRead);
//cast to see if its a block
//then create a
attribute iterator

I am currently fighting with this and trying to get it to work...hope this
is kind of what you are looking for.

jason

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost