利用ObjectDBX技术在当前图形中插入其他未打开图形中的图块
张帆老师讲过在vba中的实现方式,不知在objectarx中怎么实现? 怎么没人回答? readDwgFile(),取得实体ID,然后clone对象.<PRE class=prog_in_0>void</PRE><PRE class=prog_in_0>cloneSameOwnerObjects()</PRE><PRE class=prog_in_0>{</PRE><PRE class=prog_in_0> // Step 1:Obtain the set of objects to be <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>cloned</FONT>.</PRE><PRE class=prog_in_0> ads_name sset;</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> if (acedSSGet(NULL, NULL, NULL, NULL, sset) != RTNORM) {</PRE><PRE class=prog_in_0> acutPrintf("\nNothing selected");</PRE><PRE class=prog_in_0> return;</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // Step 2: Add obtained object IDs to list of objects</PRE><PRE class=prog_in_0> // to be <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>cloned</FONT>.</PRE><PRE class=prog_in_0> long length;</PRE><PRE class=prog_in_0> acedSSLength(sset, &length);</PRE><PRE class=prog_in_0> AcDbObjectIdArrayobjList;</PRE><PRE class=prog_in_0> AcDbObjectId ownerId = AcDbObjectId::kNull;</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> for (int i = 0; i < length; i++) {</PRE><PRE class=prog_in_0> ads_name ent;</PRE><PRE class=prog_in_0> acedSSName(sset, i, ent);</PRE><PRE class=prog_in_0> AcDbObjectId objId;</PRE><PRE class=prog_in_0> acdbGetObjectId(objId, ent);</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // Check to be sure this has the same owner as the first</PRE><PRE class=prog_in_0> // object.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> AcDbObject *pObj;</PRE><PRE class=prog_in_0> acdbOpenObject(pObj, objId, AcDb::kForRead);</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> if (pObj->ownerId() == ownerId)</PRE><PRE class=prog_in_0> objList.append(objId);</PRE><PRE class=prog_in_0> else if (i == 0) {</PRE><PRE class=prog_in_0> ownerId = pObj->ownerId();</PRE><PRE class=prog_in_0> objList.append(objId);</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0> pObj->close();</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> acedSSFree(sset);</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // Step 3: Get the object ID of the desired owner for</PRE><PRE class=prog_in_0> // the <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>cloned</FONT> objects.We'll use model space for</PRE><PRE class=prog_in_0> // this example.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> AcDbBlockTable *pBlockTable;</PRE><PRE class=prog_in_0> acdbHostApplicationServices()->workingDatabase()</PRE><PRE class=prog_in_0> ->getSymbolTable(pBlockTable, AcDb::kForRead);</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> AcDbObjectIdmodelSpaceId;</PRE><PRE class=prog_in_0> pBlockTable->getAt(ACDB_MODEL_SPACE, modelSpaceId);</PRE><PRE class=prog_in_0> pBlockTable->close();</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // Step 4:Create a new ID map.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> AcDbIdMapping idMap;</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // Step 5: Call deepCloneObjects().</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> acdbHostApplicationServices()->workingDatabase()</PRE><PRE class=prog_in_0> ->deepCloneObjects(objList, modelSpaceId, idMap);</PRE><PRE class=prog_in_0></PRE><PRE class=prog_in_0> // Now we can go through the ID map and do whatever we'd</PRE><PRE class=prog_in_0> // like to the original and/or <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>clone</FONT> objects.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> // For this example, we'll print out the object IDs of</PRE><PRE class=prog_in_0> // the new objects resulting from the <FONT style="BACKGROUND-COLOR: #0a246a" color=#ffffff>cloning</FONT> process.</PRE><PRE class=prog_in_0> //</PRE><PRE class=prog_in_0> AcDbIdMappingIter iter(idMap);</PRE><PRE class=prog_in_0> for (iter.start(); !iter.done(); iter.next()) {</PRE><PRE class=prog_in_0> AcDbIdPair idPair;</PRE><PRE class=prog_in_0> iter.getMap(idPair);</PRE><PRE class=prog_in_0> if (!idPair.isCloned())</PRE><PRE class=prog_in_0> continue;</PRE><PRE class=prog_in_0> acutPrintf("\nObjectId is: %Ld",</PRE><PRE class=prog_in_0> idPair.value().asOldId());</PRE><PRE class=prog_in_0> }</PRE><PRE class=prog_in_end_0>}</PRE> 谢谢,我先看看,学习学习
页:
[1]