Create a new DWG

Source: Internet
Author: User

Bool cmaindlg: newdwg ()
{
ACAD: errorstatus st;
Acapdocument * pdoc = acdocmanager-> curdocument ();
St = acdocmanager-> lockdocument (pdoc );
If (st! = ACAD: Eok)
{
Acutprintf ("failed to lock the document ");
Return false;
}
Static char pdata [] = "Acad. DWT ";
St = acdocmanager-> appcontextnewdocument (const char *) pdata); // create a DWG
If (st! = ACAD: Eok)
{
Acutprintf ("failed to create document ");
Return false;
}
 
Acdocmanager-> unlockdocument (pdoc );

Return true;
}

 

 

Or set up in the background

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 ),
AcGeVector3d (0, 0, 1 ),
1.0 ),
* PCir2 = new AcDbCircle (AcGePoint3d (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 ("c: // test1.dwg ");
Delete pDb;
}

Void
ReadDwg ()
{
// Set constructor parameter to kFalse so that
// Database will be constructed empty. This way only
// What is read in will be in the database.
//
Acdbdatabase * PDB = new acdbdatabase (adesk: kfalse );

// The acdbdatabase: readdwgfile () function
// Automatically appends a DWG extension if it is not
// Specified in the filename parameter.
//
PDB-> readdwgfile ("test1.dwg ");

// Open the model space block table record.
//
Acdbblocktable * pblktbl;
PDB-> getsymboltable (pblktbl, ACDB: kforread );

Acdbblocktablerecord * pblktblrcd;
Pblktbl-> getat (acdb_model_space, pblktblrcd,
ACDB: kforread );
PBlkTbl-> close ();

AcDbBlockTableRecordIterator * pBlkTblRcdItr;
PBlkTblRcd-> newIterator (pBlkTblRcdItr );

AcDbEntity * pEnt;
For (pBlkTblRcdItr-> start ();! PBlkTblRcdItr-> done ();
PBlkTblRcdItr-> step ())
{
PBlkTblRcdItr-> getEntity (pEnt,
AcDb: kForRead );
AcutPrintf ("classname: % s/n ",
(PEnt-> isA ()-> name ());
PEnt-> close ();
}
Pblktblrcd-> close ();
Delete pblktblrcditr;
Delete PDB;
}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.