getBlockReferenceIds and layouts

getBlockReferenceIds and layouts

Anonymous
Not applicable
589 Views
5 Replies
Message 1 of 6

getBlockReferenceIds and layouts

Anonymous
Not applicable
The subject line kinda sums it up, in my app I need to gather block
REFernces in the current layout only. Thought I had the answer, not.
Seems I can find them in either all layouts or none. Does anyone know
how to accomplish this? I posted my function below, hope the mail
program hasnt mangled beyond comprehension.
Thanks for any pointers
Perry



//////////////////////////////////////////////////////////////////////
// Get block reference ID's for the block 'TBREVISION'
// In the current layout only.
// Note, this gets block REF's not block DEF's!
//////////////////////////////////////////////////////////////////////

Acad::ErrorStatus CRevision::GetRevBlockIds(AcDbObjectIdArray& refEnts)
{
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable = NULL;
AcDbBlockTableRecord *pBlkTableRecord;
AcDbObjectId blkID;

const char *currentLayoutName =
acdbHostApplicationServices()->layoutManager()->findActiveLayout(Adesk::kTrue);
AcDbLayout *pcurrentLayout =
acdbHostApplicationServices()->layoutManager()->findLayoutNamed(currentLayoutName,Adesk::kFalse);
AcDbObjectId pLayoutBlkId = pcurrentLayout->getBlockTableRecordId();
pCurDb = acdbHostApplicationServices()->workingDatabase();

if ((es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)) == Acad::eOk)
{
//See if the block DEF exists before looking for References, if it does...
if (pBlkTable->has("TBREVISION"))
{
//This code chunk finds refs in ALL layouts
pBlkTable->getAt("TBREVISION", blkID);
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord, blkID,
AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block.");

//This code chunk is supposed to find refs in ONLY the current
layout, but finds none.
/*
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord,
pLayoutBlkId, AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block.");
*/
pBlkTableRecord->close();
}
}
pBlkTable->close();
return es;
}
0 Likes
590 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Well, right after posting this I thought "if getBlockReferenceIds wont
let me limit its action to a particular layout, then just get all the
ID's and pick through them and discard the ones you dont want".
Sounded reasonable, but I'm having trouble with that solution as well.
When iterating through the array of ID's Im getting an access violation
while attemping to get the name of an object.
Beint a budding Arx programmer I have had occasion to see lots of this
error. But after going through the trouble of creating different
variables for different ID's & table records AND completly seperating
my iterating code from the rest (and closing objects) I still get the
access violation.
Can someone tell me what I have done wrong here?
Should I just scrap this and do an SSGET type thing?
Thanks,
Perry


//////////////////////////////////////////////////////////////////////
// Get block reference ID's for the block 'TBREVISION'
// In the current layout only.
// Note, this gets block REF's not block DEF's!
//////////////////////////////////////////////////////////////////////
/*
How about just getting all the refs, then picking thru em
and keeping just the ones on the current layout?
Also, make this func more generic (pass in block name) and put
it in the utils file. Can use it for finding title blocks too
*/
Acad::ErrorStatus CRevision::GetRevBlockIds(AcDbObjectIdArray& refEnts)
{
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable = NULL;
AcDbBlockTableRecord *pBlkTableRecord;
AcDbObjectId blkID;
AcDbBlockTableRecord *pBlkTableRecord2;
AcDbObjectId blkID2;
char *pBlkName;
pCurDb = acdbHostApplicationServices()->workingDatabase();

if ((es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)) == Acad::eOk)
{
//See if the block DEF exists before looking for References, if it does...
if (pBlkTable->has("TBREVISION"))
{
pBlkTable->getAt("TBREVISION", blkID);
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord, blkID,
AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block
table record.");
pBlkTableRecord->close();
}
pBlkTable->close();
}

if (!refEnts.isEmpty())
{
pCurDb = acdbHostApplicationServices()->workingDatabase();

if ((es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)) == Acad::eOk)
{
for(int dLen = 0; dLen < refEnts.length(); dLen++)
{
blkID2 = refEnts.at(dLen);
if ( acdbOpenObject ((AcDbObject *&)pBlkTableRecord2, blkID2,
AcDb::kForRead) == Acad::eOk )
{
pBlkTableRecord2->getName(pBlkName); //Acess violation here
if ( strnicmp (pBlkName, "TBREVISION", 10) != 0 )
{
// remove this ID from the array
// gonna have to change this to a while loop
}
pBlkTableRecord2->close () ;
acdbFree (pBlkName) ;
}
}
pBlkTable->close();
}
}
return es;
}
0 Likes
Message 3 of 6

Anonymous
Not applicable
The name of the function is "getBlockReferenceIds", not
"getBlockTableRecordIds".

Is that a good enough hint?

How about:

AcDbBlockTableRecord -> BLOCK

AcDbBlockReference -> INSERT

Take another look at your code.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"perry" wrote in message news:4879516@discussion.autodesk.com...
Beint a budding Arx programmer I have had occasion to see lots of this
error. But after going through the trouble of creating different
variables for different ID's & table records AND completly seperating
my iterating code from the rest (and closing objects) I still get the
access violation.
Can someone tell me what I have done wrong here?
Should I just scrap this and do an SSGET type thing?
Thanks,
Perry


//////////////////////////////////////////////////////////////////////
// Get block reference ID's for the block 'TBREVISION'
// In the current layout only.
// Note, this gets block REF's not block DEF's!
//////////////////////////////////////////////////////////////////////
/*
How about just getting all the refs, then picking thru em
and keeping just the ones on the current layout?
Also, make this func more generic (pass in block name) and put
it in the utils file. Can use it for finding title blocks too
*/
Acad::ErrorStatus CRevision::GetRevBlockIds(AcDbObjectIdArray& refEnts)
{
Acad::ErrorStatus es;
AcDbDatabase *pCurDb;
AcDbBlockTable *pBlkTable = NULL;
AcDbBlockTableRecord *pBlkTableRecord;
AcDbObjectId blkID;
AcDbBlockTableRecord *pBlkTableRecord2;
AcDbObjectId blkID2;
char *pBlkName;
pCurDb = acdbHostApplicationServices()->workingDatabase();

if ((es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)) == Acad::eOk)
{
//See if the block DEF exists before looking for References, if it does...
if (pBlkTable->has("TBREVISION"))
{
pBlkTable->getAt("TBREVISION", blkID);
if ((es = acdbOpenObject((AcDbObject *&)pBlkTableRecord, blkID,
AcDb::kForRead)) == Acad::eOk)
{
es = pBlkTableRecord->getBlockReferenceIds(refEnts);
if (es != Acad::eOk)
{
acutPrintf("\nCRevision::GetRevBlockIds Couldnt get block refs");
return es;
}
}
else
acutPrintf("\nERROR: CRevision::GetRevBlockIds couldnt open block
table record.");
pBlkTableRecord->close();
}
pBlkTable->close();
}

if (!refEnts.isEmpty())
{
pCurDb = acdbHostApplicationServices()->workingDatabase();

if ((es = pCurDb->getBlockTable(pBlkTable, AcDb::kForRead)) == Acad::eOk)
{
for(int dLen = 0; dLen < refEnts.length(); dLen++)
{
blkID2 = refEnts.at(dLen);
if ( acdbOpenObject ((AcDbObject *&)pBlkTableRecord2, blkID2,
AcDb::kForRead) == Acad::eOk )
{
pBlkTableRecord2->getName(pBlkName); //Acess violation here
if ( strnicmp (pBlkName, "TBREVISION", 10) != 0 )
{
// remove this ID from the array
// gonna have to change this to a while loop
}
pBlkTableRecord2->close () ;
acdbFree (pBlkName) ;
}
}
pBlkTable->close();
}
}
return es;
}
0 Likes
Message 4 of 6

Anonymous
Not applicable
Tony Tanzillo wrote:
> The name of the function is "getBlockReferenceIds", not
> "getBlockTableRecordIds".
>
> Is that a good enough hint?
>
> How about:
>
> AcDbBlockTableRecord -> BLOCK
>
> AcDbBlockReference -> INSERT
>
> Take another look at your code.
>
>

"getBlockTableRecordIds" I dont see this anywhere in my code, neither can my compiler find it.
"AcDbBlockTableRecord" I am aware that this is a BLOCK (definition).
"AcDbBlockReference" I am aware that this is a INSERT (reference).
Thanks so much
Perry
0 Likes
Message 5 of 6

Anonymous
Not applicable
perry schrieb:
[...]

try:

pBlkName = NULL;
> pBlkTableRecord2->getName(pBlkName); //Acess violation here
> if ( strnicmp (pBlkName, "TBREVISION", 10) != 0 )
[...]

Arnold
0 Likes
Message 6 of 6

Anonymous
Not applicable
Okay, I guess you couldn't find it.

The array returned by getBlockReferenceIds contain Object Ids
of AcDbBlockReferences, not AcDbBlockTableRecords.

Again, look at your code.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

"perry" wrote in message news:4879578@discussion.autodesk.com...
Tony Tanzillo wrote:
> The name of the function is "getBlockReferenceIds", not
> "getBlockTableRecordIds".
>
> Is that a good enough hint?
>
> How about:
>
> AcDbBlockTableRecord -> BLOCK
>
> AcDbBlockReference -> INSERT
>
> Take another look at your code.
>
>

"getBlockTableRecordIds" I dont see this anywhere in my code, neither can my compiler find it.
"AcDbBlockTableRecord" I am aware that this is a BLOCK (definition).
"AcDbBlockReference" I am aware that this is a INSERT (reference).
Thanks so much
Perry
0 Likes