Issue
How to open a drawing and save it to another location without displaying it in the Acad window ?
Solution
You can use AcDbDatabase::readDwgFile() and AcDbDatabase::saveAs() to accomplish this. When you do saveAs(), you can specify any local or mapped network drive and directory as you desire, given that you have write-access to the destination and the file is not opened by AutoCAD or any other application. If the file exists, saveAs() will overwrite it quietly without any warning if no one else is operating on it. Therefore, precaution must be taken so that data is not mistakenly lost.
The code snippet of an ARX below assumes a drawing "c:tempIn.dwg" exists. It reads the dwg, adds one circle and save as to a new drawing silently.
// save as silently
static void mySaveAs()
{
AcDbDatabase* pDb = new AcDbDatabase(Adesk::kFalse);
Acad::ErrorStatus es =
pDb->readDwgFile(L"c:\temp\In.dwg");
assert(es == Acad::eOk);
// get the block table
AcDbBlockTable *pBlockTable;
es = pDb->getBlockTable(pBlockTable,
AcDb::kForRead);
if (es != Acad::eOk)
{
return;
}
// get model space
AcDbBlockTableRecord *pBlockTableRec;
es = pBlockTable->
getAt(ACDB_MODEL_SPACE, pBlockTableRec,
AcDb::kForWrite);
if (es != Acad::eOk)
{
pBlockTable->close();
return;
}
pBlockTable->close();
// create a new entity
AcDbCircle *pCircle =
new AcDbCircle(AcGePoint3d(0,0,0),
AcGeVector3d(0,0,1),100);
// add the new entity to the model space
AcDbObjectId objId;
pBlockTableRec->appendAcDbEntity(objId, pCircle);
// close the entity
pCircle->close();
// close the model space block
pBlockTableRec->close();
// save as to the new drawing
es = pDb->saveAs(L"c:\temp\Out.dwg");
assert(es == Acad::eOk);
delete pDb;
}

Leave a Reply to draganst61@open.telekom.rsCancel reply