error using insert function

error using insert function

Anonymous
Not applicable
392 Views
3 Replies
Message 1 of 4

error using insert function

Anonymous
Not applicable
When I try to execute next code I obtain "Error inserting a block"
Debugging it I see ErrorStatus code "eHandleInUse".

Anyone can help me?
----------------------------------------------------------------------------
-------------------------------------------------
AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse, Adesk::kTrue) ;
pDwg->readDwgFile ("c:\\myfile.dwg") ;

//----- Put it into a block table record of the current database
AcDbObjectId id ;
Acad::ErrorStatus es =
acdbHostApplicationServices()->workingDatabase()->insert (id, "myfile",
pDwg, Adesk::kTrue) ;

if ( es != Acad::eOk ) // here I obtain eHandleInUse
acutPrintf ("\nError inserting a block.") ;
delete pDwg ;

----------------------------------------------------------------------------
-------------------------------------------------

Thanks in advance!
Luis.
0 Likes
393 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
hi,

your code is okay! i inserted a block in the current database.
no failure in that!

regards
chris
0 Likes
Message 3 of 4

Anonymous
Not applicable
by the way, i've just looked for such a code-snipped.

thank you for that
chris
0 Likes
Message 4 of 4

Anonymous
Not applicable
I solved error. I was using modeless dialog and toolbars for insert block
(needed proper document locking from application context).

Next code runs properly:
-------------------------------------------------------------------
Acad::ErrorStatus es;
AcApDocument *pDoc = acDocManager->curDocument();

acDocManager->lockDocument(pDoc, AcAp::kWrite);

AcDbDatabase *pDwg =new AcDbDatabase (Adesk::kFalse) ;
es = pDwg->readDwgFile ("c:\\myfile.dwg") ;

//----- Put it into a block table record of the current database
AcDbObjectId id ;
es = acdbHostApplicationServices()->workingDatabase()->insert (id,
"myfile", pDwg, Adesk::kFalse) ;

delete pDwg ;

acDocManager->unlockDocument(pDoc);
-------------------------------------------------------------------

Thank you.

Luis.
0 Likes