Add commands to ACAD, modify external DWG files, and add the complete ARX code of extended data to all lines...

Source: Internet
Author: User
# Include

# Include// Acaderrorstatustext

# Include

 

# Include // Acdbcircle

# Include

 

# Include // Asdblarray

 

/*

* Register an application for xdata

*

* In:

* Acdbdatabase * PDB: Database

* Const char * pappname: Application name

* Adesk: Boolean exclude:

* If exclude = adesk: ktrue, then xdata associated

* This acdbregapptablerecord will not be saved when

* Drawing is saved as a release 12 (R12) drawing.

* If exclude = adesk: kfalse, the data will be saved

* During a saveasr12 operation.

*/

ACAD: errorstatus

RegisterApp (AcDbDatabase * pDb, const char * pAppName, Adesk: Boolean exclude =

 

Adesk: kFalse)

{

AcDbRegAppTable * pAppTable;

Acad: ErrorStatus es;

 

// Get the RegAppTable

If (es = pDb-> getRegAppTable (pAppTable, AcDb: kForWrite ))! = Acad: eOk)

Return es;

 

// If RegAppTable has application already-fine

If (pAppTable-> has (pAppName ))

{

PAppTable-> close ();

Return Acad: eOk;

}

 

AcDbRegAppTableRecord * pAppTableRecord = new AcDbRegAppTableRecord ();

PAppTableRecord-> setExcludeFromSaveAsR12 (exclude );

PAppTableRecord-> setName (pAppName );

 

If (es = pAppTable-> add (pAppTableRecord ))! = Acad: eOk)

{

Delete pAppTableRecord;

PAppTable-> close ();

Return es;

}

PAppTableRecord-> close ();

PAppTable-> close ();

Return es;

}

 

/*

* Add to all lines in model space a point as xData

*/

Acad: ErrorStatus

AddXDataToAllLines (AcDbDatabase * pDb, const char * pAppName)

{

AcDbBlockTable * pBlockTable;

AcDbBlockTableRecord * pModelSpace;

Acad: ErrorStatus es;

 

If (es = pDb-> getBlockTable (pBlockTable, AcDb: kForRead ))! = Acad: eOk)

Return es;

 

If (es = pBlockTable-> getAt (ACDB_MODEL_SPACE, pModelSpace, AcDb: kForRead ))

! =

Acad: eOk)

{

PBlockTable-> close ();

Return es;

}

PBlockTable-> close ();

 

AcDbBlockTableRecordIterator * pIter;

If (es = pModelSpace-> newIterator (pIter ))! = Acad: eOk)

{

PModelSpace-> close ();

Return es;

}

 

AcDbEntity * pEnt;

AcDbLine * pLine;

For (;! PIter-> done (); pIter-> step ())

{

If (pIter-> getEntity (pEnt, AcDb: kForRead )! = Acad: eOk)

Continue;

PLine = AcDbLine: cast (pEnt );

If (pLine)

{

Struct resbuf * xdata;

AcGePoint3d pntToAttach = pLine-> startPoint ();

Xdata =

Ads_buildlist (1001, pAppName, 1011, asDblArray (pntToAttach), 0 );

PLine-> upgradeOpen ();

If (es = pLine-> setXData (xdata ))! = Acad: eOk)

{

Ads_printf ("/nsetXData failed: es =

% S ", acadErrorStatusText (es ));

}

Ads_relrb (xdata );

}

PEnt-> close ();

}

Delete pIter;

Return Acad: eOk;

}

 

Void addXDataToExternalDb ()

{

Acad: ErrorStatus es;

Char * filename = "c: // temp // test. dwg ";

Char * appName = "AcDcApp ";

 

AcDbDatabase * pDb = new AcDbDatabase (Adesk: kFalse );

 

If (es = pDb-> readDwgFile (filename ))! = Acad: eOk)

{

Ads_printf ("/nreadDwgFile failed for % s: es =

% S ", filename, acadErrorStatusText (es ));

Return;

}

 

If (es = registerApp (pDb, appName ))! = Acad: eOk)

Ads_printf ("/nregisterApp failed: es = % s", acadErrorStatusText (es ));

AddXDataToAllLines (pDb, appName );

 

PDb-> saveAs ("c: // temp // test2.dwg ");

Delete pDb;

}

 

Void initApp ()

{

AcedRegCmds-> addCommand ("TEST ",

"Addx ",

"Addx ",

ACRX_CMD_MODAL,

& AddXDataToExternalDb );

}

 

Void unloadApp ()

{

Acedregcmds-> removegroup ("test ");

}

 

Extern "C" acrx: appretcode acrxentrypoint (acrx: appmsgcode MSG, void * P)

{

Switch (MSG ){

Case acrx: kinitappmsg:

Acrxunlockapplication (P );

Initapp ();

Break;

Case acrx: kunloadappmsg:

Unloadapp ();

Break;

Default:

Break;

}

Return acrx: kretok;

}

 

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.