1、exam09 23exam10a 25exam10b 26exam13 29exam14 32exam03 #include rxdlinkr.haced.hdbents.hgeassign.hdbsymtb.hdbapserv.hAcad:ErrorStatus newLine();void addLineCommand()/BEGIN_LEVEL_ADVANCED if (newLine()=Acad:eOk) acutPrintf(Successn); elseFailedn/END_LEVEL_ADVANCEDErrorStatus postToDatabase(/*in*/AcDbE
2、ntity* pEnt,/*out*/AcDbObjectId& idObj) Acad:ErrorStatus es; AcDbBlockTable* pBlockTable; AcDbBlockTableRecord* pSpaceRecord; /确定当前有正在工作的数据库 if (acdbHostApplicationServices()-workingDatabase()=NULL) return Acad:eNoDatabase; /获得当前图形的指针 /获得图形的块表,打开准备读取数据 if (es = acdbHostApplicationServices()-workingD
3、atabase()-getBlockTable(pBlockTable, AcDb:kForRead)=Acad:eOk) /获得建模空间的记录,打开准备写数据 if (es = pBlockTable-getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb:kForWrite)=Acad: /添加实体指针到建模空间后关闭指针和建模空间记录 if (es = pSpaceRecord-appendAcDbEntity(idObj, pEnt)=Acad: pEnt-close(); pSpaceRecord- /关闭块表 pBlockTable- /返回状态信息
4、return es;ErrorStatus newLine() ads_point pt1, pt2;/定义两个ads_point的点 int retval; try /从用户处获得第一点 if (retval = acedGetPoint(NULL, nSelect lower left: , pt1) != RTNORM) throw retval; /以第一点为基点, 从用户处获得第二点. if (retval = acedGetPoint(pt1, nSelect upper right:, pt2) != RTNORM) catch (int e) if (e = RTCAN) /判
5、断输入错误程序中断 return Acad:eUserBreak; if (e = RTERROR) /判断无效输入eInvalidInput;/ 将ads_point类型的点转换为AcGePoint3d类型之后创建直线 AcDbLine* pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2);/如果创建直线出错,返回错误信息 if (!pLine) acedAlert(Not enough memory to create a Line! return Acad:eOutOfMemory; AcDbObjectId id; /定义对象ID retur
6、n postToDatabase(pLine, id);extern C AcRx:AppRetCode acrxEntryPoint(AcRx:AppMsgCode msg, void* pkt) switch (msg) case AcRx:kInitAppMsg: acrxDynamicLinker-unlockApplication(pkt); acrxDynamicLinker-registerAppMDIAware(pkt); /注册命令 acedRegCmds-addCommand(EXAM03,addline,ACRX_CMD_MODAL,addLineCommand); br
7、eak;kUnloadAppMsg: /当应用程序卸载后,为防止AUOTCAD调用此命令,产生不必要的 /错误,移走命令组removeGroup( return AcRx:kRetOK;exam04a#include dbidmap.hlngtrans.hdbltrans.hdbmain.hvoidrefEdit() AcDbObjectId transId; AcDbDatabase* pDb; char *fname; struct resbuf *rb; rb = acutNewRb(RTSTR); int stat = acedGetFileD(Pick a drawing, NULL
8、, dwg, 0, rb); if (stat != RTNORM) | (rb = NULL) nYou must pick a drawing file. return; fname = (char*)acad_malloc(strlen(rb-resval.rstring) + 1); strcpy(fname, rb-resval.rstring); acutRelRb(rb); pDb = new AcDbDatabase(Adesk:kFalse); if (pDb-readDwgFile(fname) != Acad:eOk) nSorry, that draing is pro
9、bably already open. AcDbBlockTable *pBlockTable; pDb-getSymbolTable(pBlockTable, AcDb:kForRead); AcDbBlockTableRecord *pOtherMsBtr;getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb: AcDbBlockTableRecordIterator *pIter; pOtherMsBtr-newIterator(pIter); AcDbObjectIdArray objIdArray; for (pIter-start(); !pIter-
10、done(); pIter-step() AcDbEntity *pEntity;getEntity(pEntity, AcDb: if (pEntity-isKindOf(AcDbCircle:desc() objIdArray.append(pEntity-objectId(); pEntity- delete pIter; if (objIdArray.isEmpty() acad_free(fname);nYou must pick a drawing file that contains circles. AcDbBlockTable *pThisBlockTable; acdbHo
11、stApplicationServices()-workingDatabase() -getSymbolTable(pThisBlockTable, AcDb: AcDbBlockTableRecord *pThisMsBtr; pThisBlockTable-getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb:kForWrite); AcDbObjectId id = pThisMsBtr-objectId(); pThisMsBtr- AcDbIdMapping errorMap; acapLongTransactionManagerPtr()-checkOu
12、t(transId, objIdArray, id, errorMap); int colorIndex; double radius; acedGetInt(nEnter color number to circles center line:, &colorIndex); acedGetReal(nEnter circle radius:,&radius); if (radiusnewWorkSetIterator(pWorkSetIter); for (pWorkSetIter-pWorkSetIter- pWorkSetIter-step() acdbOpenAcDbEntity(pE
13、ntity, pWorkSetIter-objectId(), AcDb: pEntity-setColorIndex(colorIndex); (AcDbCircle*)pEntity)-setRadius(radius); delete pWorkSetIter; pObj- char str132; acedGetString(0, nSee the new colors and radius. Press return to back, str);checkIn(transId, errorMap);saveAs(fname); delete pDb; pDb = NULL;initA
14、pp()EXAM04A, LONGTRANS ACRX_CMD_MODAL, refEdit);void unloadApp()AppMsgCode msg, void* appId)unlockApplication(appId);registerAppMDIAware(appId); initApp(); unloadApp();kLoadDwgMsg:kUnloadDwgMsg:kInvkSubrMsg: default: ;exam04bstdlib.hstring.hrxobject.h#include acestext.hvoid printXdata();void addXdat
15、a();void printList(struct resbuf* pRb);AcDbObject* selectObject(AcDb:OpenMode openMode);void initApp();void unloadApp();AcRx:AppRetCode acrxEntryPoint(AcRx:AppMsgCode, void*);printXdata() AcDbObject *pObj; if (pObj = selectObject(AcDb:kForRead) = NULL) char appname133; if (acedGetString(NULL,nEnter
16、the desired Xdata application name:, appname) ! struct resbuf *pRb; pRb = pObj-xData(appname); if (pRb != NULL) printList(pRb); acutRelRb(pRb); else nNo xdata for this appnamevoid addXdata() AcDbObject* pObj = selectObject(AcDb:pObj) Error selecting objectn char appName132, resString200; appName0 =
17、resString0 = 0; acedGetString(NULL, Enter application name: appName);Enter string to be added: resString); struct resbuf *pRb, *pTemp;xData(appName); for (pTemp = pRb; pTemp-rbnext != NULL; pTemp = pTemp-rbnext) ; acdbRegApp(appName); pRb = acutNewRb(AcDb:kDxfRegAppName); pTemp = pRb;resval.rstring
18、= (char*) malloc(strlen(appName) + 1); strcpy(pTemp-resval.rstring, appName);rbnext = acutNewRb(AcDb:kDxfXdAsciiString);rbnext; = (char*) malloc(strlen(resString) + 1);resval.rstring, resString);upgradeOpen();setXData(pRb);printList(struct resbuf* pRb) int rt, i; char buf133; for (i = 0;pRb !i+, pRb
19、 = pRb-rbnext) if (pRb-restype 1040) rt = RT3DPOINT; 1060) rt = RTREAL; 1071) rt = RTSHORT;restype = 1071) rt = RTLONG; rt = pRb-restype; switch (rt) case RTSHORT:restype = RTSHORT) acutPrintf(RTSHORT : %dn, pRb-resval.rint);(%d . %d)nrestype, pRb- ; case RTREAL:restype = RTREAL) RTREAL : %0.3fnresval.rreal);(%d . %0.3f)n case RTSTR:restype = RTSTR) RTSTR : %sn(%d . %s)n case RT3DPOINT:restype = RT3DPOINT) RT3DPOINT : %0.3f, %0.3f, %0.3fnresval.rpointX,resval.rpointY,resval.rpointZ);(%d %0.3f %0.3f %0.3f)nresval.rpointX
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1