by Fenton Webb
If you want to be able to prevent certain entities from being saved out to a DWG file, or rather, exclude certain entities from a DWG Save operation you can use an AcEdEditorReactor to do the job…
Here’s some code which shows how you might do it…
// not MDI aware, use CDocData for MSI document aware global vars static AcDbObjectIdArray gEntityIdsNotToSave; // test command void test() { ads_name ss,ename; // select some entities to "not" save if (ads_ssget(NULL,NULL,NULL,NULL,ss) != RTNORM) return; // if the selection was successful long len; // get the total number of items selected in the selection set ads_sslength(ss,&len); AcDbObjectId id; // now loop through them all for (long i=0; iaddReactor(this); } ~NoSave() { acedEditor->removeReactor(this); } virtual void beginSave(AcDbDatabase* pDwg, const TCHAR* pIntendedName); virtual void saveComplete(AcDbDatabase* pDwg, const TCHAR* pActualName); void HideEntities(Adesk::Boolean hide) { // make sure we have some entities to "not" save if (gEntityIdsNotToSave.length() == 0) return; // do a quick check if we are saving the database of interest bool bTheOne = gEntityIdsNotToSave[0].database() == pDwg; // if not the one if (!bTheOne) return; // otherwise loop our entities and erase them for (int i=0; ierase(hide); } // make sure that the graphics pipeline is updated // because AutoCAD isn't expecting the display list to have // changed at this point actrTransactionManager->flushGraphics(); acedUpdateDisplay(); } }; // beginSave:erase the entities in question so they don't get saved void NoSave::beginSave(AcDbDatabase* pDwg, const TCHAR* pIntendedName) { HideEntities(true); } // saveComplete: restore the entities by un-erasing them void NoSave::saveComplete(AcDbDatabase* pDwg, const TCHAR* pActualName) { HideEntities(false); } // create global instance of the editor reactor static NoSave g_noSave;

Leave a Reply