Пример #1
0
bool CMakeBlkFile::SaveToFile()
{
	bool bRet = true;
	AcDbDatabase *pDwg = NULL; 
	Acad::ErrorStatus es;

	es = acdbHostApplicationServices()->workingDatabase()->wblock(pDwg, m_objIdArrs, m_insertPt/*, AcDb::kDrcIgnore*/);
	if (es == Acad::eOk)
	{
		AcDb::AcDbDwgVersion dwgVer = acdbHostApplicationServices()->workingDatabase()->originalFileVersion();
		es = pDwg->saveAs(m_strFileName,FALSE,dwgVer,0);
		if (es!=Acad::eOk)
		{
			bRet = false;
		}
	}
	if (pDwg != NULL)
	{
		delete pDwg;
		pDwg = NULL;
	}

	acTransactionManagerPtr()->queueForGraphicsFlush();
	acTransactionManagerPtr()->flushGraphics();//刷新
	acedUpdateDisplay();
	return bRet;
}
Пример #2
0
void createDatabase()
{
	// Create a new Database.
	AcDbDatabase *pDb = new AcDbDatabase();

	// Get the BlockTable.
	AcDbBlockTable *pBTable = NULL;
	pDb->getSymbolTable(pBTable, AcDb::kForRead);

	// Get the ModelSpace.
	AcDbBlockTableRecord *pRecord = NULL;
	pBTable->getAt(ACDB_MODEL_SPACE, pRecord, AcDb::kForWrite);
	pBTable->close();

	// Create a new Circle.
	AcDbCircle *pCircle1 = new AcDbCircle(AcGePoint3d(100,100,0),
		AcGeVector3d(0,0,1),
		50.0);
	// Create another new Circle.
	AcDbCircle *pCircle2 = new AcDbCircle(AcGePoint3d(200,200,0),
		AcGeVector3d(0,0,1),
		30.0);

	// Append Circle1 to ModelSpace
	pRecord->appendAcDbEntity(pCircle1);
	pCircle1->close();

	// Append Circle2 to ModelSpace
	pRecord->appendAcDbEntity(pCircle2);
	pCircle2->close();

	pRecord->close();

	// Save to file
	// MUST append a DWG file extension.
	acutPrintf(_T("\nSave file to \"d:\\temp\\testfile.dwg\"."));
	pDb->saveAs(_T("d:\\temp\\testfile.dwg"));

	delete pDb;
}
void

createDwg()

{

    AcDbDatabase *pDb = new AcDbDatabase();

  

    AcDbBlockTable *pBtbl;

    pDb->getSymbolTable(pBtbl, AcDb::kForRead);



    AcDbBlockTableRecord *pBtblRcd;

    pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,

        AcDb::kForWrite);

    pBtbl->close();



    AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1),

                                       AcGeVector3d(0,0,1),

                                       1.0),

               *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4),

                                       AcGeVector3d(0,0,1),

                                       2.0);



    pBtblRcd->appendAcDbEntity(pCir1);

    pCir1->close();

    

    pBtblRcd->appendAcDbEntity(pCir2);

    pCir2->close();

    pBtblRcd->close();



    // AcDbDatabase::saveAs() does NOT automatically

    // append a DWG file extension, so it

    // must be specified.

    //

    pDb->saveAs(_T("./test1.dwg"));

    delete pDb;

}
void
refEditApiExample()
{

    AcDbObjectId transId;
    AcDbDatabase* pDb;
    char *fname;
    struct resbuf *rb;

    // Get a dwg file from the user.
    //
    rb = acutNewRb(RTSTR);
    int stat = acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb);
    
    if ((stat != RTNORM) || (rb == NULL)) {
        acutPrintf("\nYou must pick a drawing file.");
        return;
    }

    fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);
    strcpy(fname, rb->resval.rstring);
    acutRelRb(rb);
    
    // Open the dwg file.
    //
    pDb = new AcDbDatabase(Adesk::kFalse);
    if (pDb->readDwgFile(fname) != Acad::eOk) {
        acutPrintf("\nSorry, that draing is probably already open.");
        return;
    }

    // Get the Block Table and then the model space record.
    //
    AcDbBlockTable *pBlockTable;
    pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
    AcDbBlockTableRecord *pOtherMsBtr;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead);
    pBlockTable->close();

    // Create an iterator.
    //
    AcDbBlockTableRecordIterator *pIter;
    pOtherMsBtr->newIterator(pIter);

    // Set up an object ID array.
    //
    AcDbObjectIdArray objIdArray;

    // Iterate over the model space BTR. Look specifically 
    // for lines and append their object ID to the array.
    //
    for (pIter->start(); !pIter->done(); pIter->step()) {
        AcDbEntity *pEntity;
        pIter->getEntity(pEntity, AcDb::kForRead);

        // Look for only AcDbLine objects and add them to the 
        // object ID array.
        //
        if (pEntity->isKindOf(AcDbLine::desc())) {
            objIdArray.append(pEntity->objectId());
        }
        pEntity->close();
    }
    delete pIter;
    pOtherMsBtr->close();

    if (objIdArray.isEmpty()) {
        acad_free(fname);
        acutPrintf("\nYou must pick a drawing file that contains lines.");
        return;
    }

    // Now get the current database and the object ID for the
    // current database's model space BTR.
    //
    AcDbBlockTable *pThisBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pThisBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pThisMsBtr;
    pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb::kForWrite);
    pThisBlockTable->close();
    
    AcDbObjectId id = pThisMsBtr->objectId();
    pThisMsBtr->close();


    // Create the long transaction. This will check all the entities 
    // out of the external database.
    //
    AcDbIdMapping errorMap;
    acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, errorMap);

    // Now modify the color of these entities.
    //
    int colorIndex;
    acedGetInt("\nEnter color number to change entities to: ", &colorIndex);
    AcDbObject* pObj;
    if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk) {

        // Get a pointer to the transaction.
        //
        AcDbLongTransaction* pLongTrans = AcDbLongTransaction::cast(pObj);
        if (pLongTrans != NULL) {

            // Get a work set iterator.
            //
            AcDbLongTransWorkSetIterator* pWorkSetIter;
            pLongTrans->newWorkSetIterator(pWorkSetIter);

            // Iterate over the entities in the work set and change the color.
            //
            for (pWorkSetIter->start(); !pWorkSetIter->done(); pWorkSetIter->step()) {
                AcDbEntity *pEntity;
                acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(), AcDb::kForWrite);
                pEntity->setColorIndex(colorIndex);
                pEntity->close();
            }
            delete pWorkSetIter;
        }
        pObj->close();
    }

    // Pause to see the change.
    //
    char str[132];
    acedGetString(0, "\nSee the new colors. Press return to check the object into the original database", str);

    // Check the entities back in to the original database.
    //
    acapLongTransactionManagerPtr()->checkIn(transId, errorMap);

    // Save the original database, since we have made changes.
    //
    pDb->saveAs(fname);

    // Close/Delete the database
    //
    delete pDb;
    pDb = NULL;

    acad_free(fname);
}