newer 发表于 2021-1-7 19:44:35

从外部DWG拷贝块定义到当前图形

问题:
I'm trying to copy a block definition from one drawing to the current drawing
using the wblock function
but the function is returning eFileInternalErr error. What am I doing wrong?


解答:
The wblock function is meant for writing out database contents. What you are
trying to do is the opposite, i.e. reading the contents of an external file
into the current database. You should be using theinsert function for this.

The code snippet below shows how to use one of the overloaded insert functions
to copy a block definition from an external file to the current database.




void AdskCopyBlockDef()
{
   struct resbuf *rb;
   char *fname;
   AcDbObjectId blockId;
    rb = acutNewRb(RTSTR);
Acad::ErrorStatus es;


    acedGetFileD("Pick drawing containing block def", NULL, "dwg", 0, rb);
if(acutNewString(rb->resval.rstring,fname) != Acad::eOk ){
acutPrintf("\nString memory allocation failed");
      acutRelRb(rb);
return;
}
    acutRelRb(rb);


    AcDbDatabase *pSourceDb = new AcDbDatabase(Adesk::kFalse);
   pSourceDb->readDwgFile(fname);



   char SourceBlockdefName;
acedGetString(0,"Enter block def. name in source DWG: ",SourceBlockdefName);


   char DestBlockdefName;
acedGetString(0,"Enter destination block def. name: ",DestBlockdefName);



   //Get current database
AcDbDatabase *pCurDb = acdbHostApplicationServices()->workingDatabase();



//Insert the chosen block definition
    es = pCurDb -> insert(blockId,SourceBlockdefName,DestBlockdefName,pSourceDb) ;
if (es != Acad::eOk){
acutPrintf("\nBlock Def copyfailed. Error: %d",es);
return;
}

acutDelString(fname);
}




Note: This insert() function seems to create two block definiitions: the source
and the named copy, with the original being as in the external drawing, but
the copy being empty. This behaviour, which has also been observed in AutoCAD
2004, has been logged as a change request for further investigation.

页: [1]
查看完整版本: 从外部DWG拷贝块定义到当前图形