INSERT fails on custom entity derived from AcDbBlockReference

INSERT fails on custom entity derived from AcDbBlockReference

Anonymous
Not applicable
484 Views
7 Replies
Message 1 of 8

INSERT fails on custom entity derived from AcDbBlockReference

Anonymous
Not applicable
I have a custom entity derived from AcDbBlockReference. I have created a drawing containing one or more of these custom entites and I want to insert that drawing into another drawing. Of course, since the block to which the custom entity is reference is required in the second drawing also, I have ensured that all the relevant blocks are available.

However, if I run the INSERT command and select the first drawing, it is consistently throwing up an "eWrongDatabase" error for each custom entity in the drawing. This error appears in the following code:

Acad::ErrorStatus CMyCustomEntity::setRefBlock(const char* pszRefBlock)
{
// Ensure that we are open for writing
assertWriteEnabled();

// Get the block id of the given name
Acad::ErrorStatus es;
AcDbBlockTable *pBT;
es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBT, AcDb::kForRead);

// Get the referenced block
AcDbObjectId objRefId;
es = pBT->getAt(m_pszRefBlock, objRefId);

// If it was not found, this is a serious error
if (es != Acad::eOk)
{
// Close the block table
pBT->close();

// Erase this equipment from the drawing
erase();

// Return the error status for further processing
return es;
}

// Close the block table
pBT->close();

// Set the reference to the block ID
if ((es = setBlockTableRecord(objRefId)) != Acad::eOk)
{
// --------------- This is the error that is appearing ---------------------
acutPrintf("\nError %d setting block reference to '%s'.\n", es, m_pszRefBlock);
erase();
return es;
}

// More code here
...
...
...
}

I have tried the objRefId.convertToRedirectedId() before calling setBlockTableRecord() but the error still persists. I should note here that this functionality was working perfectly in AutoCAD 2000/2002, but it is failing in AutoCAD 2006.
0 Likes
485 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
The "m_pszRefBlock" should read as "pszRefBlock". Excuse the error.
0 Likes
Message 3 of 8

Anonymous
Not applicable
Is your entity database resident at the time you call
setBlockTableRecord()? If it is database resident, does it reside in the
working database? My guess is that 2000/2002 accepted setting a BTR for a
non-DBR object, but newer versions consider that an error. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
0 Likes
Message 4 of 8

Anonymous
Not applicable
No, the entity is not explicitly made DBR by me. The INSERT command is supposed to do that right? The "setRefBlock" function is actually called from the custom entity's "dwgInFields" function so I guess the INSERT command is cloning the custom entity present in the first drawing, as it is supposed to.
0 Likes
Message 5 of 8

Anonymous
Not applicable
Could this be the problem? The custom entity sets is reference block as follows:

acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBT, AcDb::kForRead);
pBT->getAt(pszRefBlock, objRefId);
setBlockTableRecord(objRefId);

This works fine for entities created within the same drawing, but fails when I INSERT another drawing containing them. If I should do something else, what should it be? How will I know that this entity is being created by the INSERT command and not by myself? And how to get the database pointer of the source database during INSERT?
0 Likes
Message 6 of 8

Anonymous
Not applicable
> If I should do something else, what should it be?

You should let the cloning mechanism handle this by calling
AcDbBlockReference::dwgOutFields() from your object's dwgOutFields(), and
AcDbBlockReference::dwgInFields() from your dwgInFields(). Nothing else
should be necessary. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
0 Likes
Message 7 of 8

Anonymous
Not applicable
It turns out that in 2006, the INSERT mechanism does not import the block reference into the working drawing until the custom entity is made database resident. Replacing acdbHostApplicationServices()->workingDatabase() with AcDbObject::database() solved the problem.

Thanks for the help.
0 Likes
Message 8 of 8

Anonymous
Not applicable
Anyone who knows how I can read geometry information from a AcDbBlockReference?
0 Likes