How to INSERT in ARX (ZT)

xiaoxiao2021-03-06  56

In practice, the external graphics file source.dwg is often inserted into another graphic or in the current graphics. To insert it into the current graphic DEST.DWG as an example.

In order to insert a source.dwg into the Dest.dwg, first find this file. We can use a variety of basic technologies and corresponding rules to retrieve the Source you want to insert from your machine or PDM database. DWG, returning a character strike SFileName represents the entire file and its path.

Then create an empty database PNEWDB to read Source.dwg.

ACDBDATABASE * PNEWDB = New ACDBDATABASE (ADESK :: KFALSE);

/ / Here you must use Adesk :: Kfalse

ACDOCMANAGER-> LOCKDocument (ACDOCMANAGER-> Curdocument ()); // If you don't need LockDocument, you can don't need LockDocument.

ES = pnewdb-> readdwgfile (sfilename, _sh_denyno, false); if (es! = acad :: eok) {acutprintf ("/ nthe file% s cannot be open), sfilename); Return;}

In this way, Source.dwg is expressed by PNEWDB. We use PDB to represent the current database ACDBDATABASE * PDB; PDB = ACDBHOSTAPPLICVICES () -> WorkingDatabase ();

Now we use insert to insert the database. Insert has two usage, one is direct insert, the element entity in the Source.dwg is dispersed into the PDB-> INSERT in the PDB (ACGEMATRIX3D :: Kidentity, PNewDB); // Here, it is assumed that there is no change in Source.dwg. If we end the program here, we can see that Source.dwg has been inserted, but not a piece.

Another insert method is required to be inserted into a tile, and the Attribute of the tile is also obtained from the Source.dwg. This method is to do a lot of work. First run insert ()

CString PblockName = "TestBlock"; ACDBOBJECTID BLOCKID; IF ((ES = PDB-> INSERT (block) == acad :: eok) {acutprintf ("/ ninsert ok / n");} else {AFXMessageBox ("INSERT FAILED"; delete pnewdb; return;

/ / This BLCOKID is generated after INSERT running. It represents a block table records ACDBBLOCKRecord ID. PBLockName is a record name, set its value before INSERT run. If we end the program here, we can't see any Things, because Source is not truly inserted. We have to do something, first, create an ACDBBLOCKRECORD, pointing it to the ACDBBLockRecord represented by the BlockID, and then add this ACDBBBLockReference to the graphic database represented by the PDB. AcdbBlockReference * PBLKRef = new AcDbBlockReference; pBlkRef-> setBlockTableRecord (blockId); // point blockId; pBlkRef-> setPosition (Pt); // set position pBlkRef-> setRotation (angle); // set angle pBlkRef-> setScaleFactors (XrefScale); / / Set an enlargement ratio

AcDbBlockTable * pBlockTable; pDb-> getSymbolTable (pBlockTable, AcDb :: kForRead); AcDbBlockTableRecord * pBlockTableRecord; pBlockTable-> getAt (ACDB_MODEL_SPACE, pBlockTableRecord, AcDb :: kForWrite); pBlockTable-> close (); AcDbObjectId newEntId; pBlockTableRecord-> appendAcDbEntity (newInd, PBLKREF); pblocktableRecord-> close ();

If we end the program here, we will see that Source.dwg in the current graph has been inserted as a tile. But there is no Source.dwg defined in the tile. So we have to work. The following things are simple. .

ACDBBLOCKTABLERECORD * PBLOCKDEF; ACDBOPENOBJECT (PBLOCKDEF, Blockid, ACDB :: Kforread);

AcDbBlockTableRecordIterator * pIterator; pBlockDef-> newIterator (pIterator); AcGePoint3d basePoint; AcDbEntity * pEnt; AcDbAttributeDefinition * pAttdef; for (pIterator-> start ();! PIterator-> done (); pIterator-> step ()) // will All Attibute in Source.dwg Traverse {Pitrator-> GetEntity (Pent, ACDB :: Kforread); PATTDEF = ACDBATRIBUTEDEFINITION :: Cast (pent); if (Pattdef! = null&&! pattdef-> isconstant ()) {ACDBATRIBUTE * Patt = new acdbattribute (); Patt-> setPropertiesFrom (Pattdef); Patt-> setInvisible (Pattdef-> isinvisible ()); basepoint = pattdef-> position (); basepoint = pblkref-> position (). Asvector ); Patt-> setPosition; Patt-> setHeight (Pattdef-> height ()); patt-> sarotation ()); Patt-> settag ("tag"); Patt-> setfieldLength (25); char * pstr = pattdef-> tag (); Patt-> settag (PSTR); Acutdelstring (PSTR); Patt-> setfieldLength (Pattdef-> FieldLength ()); Patt-> setTextString ("-");

ACDBOBJECTID ATTID; PBLKREF-> appendattribute (attid, patt); Patt-> Close ();} Pent-> Close (); // use pent ... pattdef might be null} delete Piterator;

转载请注明原文地址:https://www.9cbs.com/read-108558.html

New Post(0)