《用ObjectARX开发AutoCAD2000应用程序配套源码老虎工作室.doc》由会员分享,可在线阅读,更多相关《用ObjectARX开发AutoCAD2000应用程序配套源码老虎工作室.doc(26页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流用ObjectARX开发AutoCAD2000应用程序配套源码老虎工作室.精品文档.老虎工作室实例exam03 画直线 获取用户输入点exam04a 打开已存在文件建立浏览器对象ID数组获取当前块表指针常事务处理普通快(改变部分实体属性)exam04b 交互选择实体 扩展数据加入 调用扩展数据exam05a 创建新块表记录 创建一带属性快 创建一属性实体 遍历块中实体exam06a 获取用户选择集 建立组,并向其中加入选择集实体 遍历并改变组实体exam06b 向字典对象中加入扩展集 调用扩展集数据exam07 建立基于MFC的对话框 拾取点
2、exam08 建一基于AcdbObject的派生类 应用类向字典加入数据并提取exam09 建一基于拖动的类 实现拖动创建椭圆exam10a 建一临时数据库反映器exam10b 建派生于AcdbObject的派生类 建一有名对象词典纪录 将反映器对象加入词典纪录中 用addPersistanReactor附着实体exam13 派生于AcdbEntity画一自定义网格exam14 判断实体类型交互选择实体转化为AcGe对象求实体交点exam032exam04a2exam04b4exam05a7exam06a11exam06b13exam0715exam0820exam0923exam10a25e
3、xam10b26exam1329exam1432exam03 #include #include #include #include #include #include #include Acad:ErrorStatus newLine();void addLineCommand()/BEGIN_LEVEL_ADVANCED if (newLine()=Acad:eOk) acutPrintf(Successn); else acutPrintf(Failedn);/END_LEVEL_ADVANCEDAcad:ErrorStatus postToDatabase(/*in*/AcDbEnti
4、ty* pEnt,/*out*/AcDbObjectId& idObj)Acad:ErrorStatus es;AcDbBlockTable*pBlockTable;AcDbBlockTableRecord* pSpaceRecord;/确定当前有正在工作的数据库 if (acdbHostApplicationServices()-workingDatabase()=NULL) return Acad:eNoDatabase; /获得当前图形的指针 /获得图形的块表,打开准备读取数据 if (es = acdbHostApplicationServices()-workingDatabase(
5、)-getBlockTable(pBlockTable, AcDb:kForRead)=Acad:eOk)/获得建模空间的记录,打开准备写数据 if (es = pBlockTable-getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb:kForWrite)=Acad:eOk) /添加实体指针到建模空间后关闭指针和建模空间记录 if (es = pSpaceRecord-appendAcDbEntity(idObj, pEnt)=Acad:eOk) pEnt-close(); pSpaceRecord-close();/关闭块表 pBlockTable-clo
6、se();/返回状态信息return es;Acad: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)throw retval;catch (
7、int e)if (e = RTCAN) /判断输入错误程序中断return Acad:eUserBreak;if (e = RTERROR) /判断无效输入return Acad: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;
8、 AcDbObjectId id; /定义对象IDreturn 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,addl
9、ine,ACRX_CMD_MODAL,addLineCommand); break; case AcRx:kUnloadAppMsg: /当应用程序卸载后,为防止AUOTCAD调用此命令,产生不必要的 /错误,移走命令组 acedRegCmds-removeGroup(EXAM03); break; return AcRx:kRetOK;exam04a#include #include #include #include #include #include #include #include #include #include voidrefEdit() AcDbObjectId transI
10、d; AcDbDatabase* pDb; char *fname; struct resbuf *rb; rb = acutNewRb(RTSTR); int stat = acedGetFileD(Pick a drawing, NULL, dwg, 0, rb); if (stat != RTNORM) | (rb = NULL) acutPrintf(nYou must pick a drawing file.); return; fname = (char*)acad_malloc(strlen(rb-resval.rstring) + 1); strcpy(fname, rb-re
11、sval.rstring); acutRelRb(rb); pDb = new AcDbDatabase(Adesk:kFalse); if (pDb-readDwgFile(fname) != Acad:eOk) acutPrintf(nSorry, that draing is probably already open.); return; AcDbBlockTable *pBlockTable; pDb-getSymbolTable(pBlockTable, AcDb:kForRead); AcDbBlockTableRecord *pOtherMsBtr; pBlockTable-g
12、etAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb:kForRead); pBlockTable-close(); AcDbBlockTableRecordIterator *pIter; pOtherMsBtr-newIterator(pIter); AcDbObjectIdArray objIdArray; for (pIter-start(); !pIter-done(); pIter-step() AcDbEntity *pEntity; pIter-getEntity(pEntity, AcDb:kForRead); if (pEntity-isKind
13、Of(AcDbCircle:desc() objIdArray.append(pEntity-objectId(); pEntity-close(); delete pIter; pOtherMsBtr-close(); if (objIdArray.isEmpty() acad_free(fname); acutPrintf(nYou must pick a drawing file that contains circles.); return; AcDbBlockTable *pThisBlockTable; acdbHostApplicationServices()-workingDa
14、tabase() -getSymbolTable(pThisBlockTable, AcDb:kForRead); AcDbBlockTableRecord *pThisMsBtr; pThisBlockTable-getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb:kForWrite); pThisBlockTable-close(); AcDbObjectId id = pThisMsBtr-objectId(); pThisMsBtr-close(); AcDbIdMapping errorMap; acapLongTransactionManagerPtr
15、()-checkOut(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-start(); !pWorkSetIter-done(); pWorkSetIter-st
16、ep() AcDbEntity *pEntity; acdbOpenAcDbEntity(pEntity, pWorkSetIter-objectId(), AcDb:kForWrite); pEntity-setColorIndex(colorIndex);(AcDbCircle*)pEntity)-setRadius(radius); pEntity-close(); delete pWorkSetIter; pObj-close(); char str132; acedGetString(0, nSee the new colors and radius. Press return to
17、 back, str); acapLongTransactionManagerPtr()-checkIn(transId, errorMap); pDb-saveAs(fname); delete pDb; pDb = NULL; acad_free(fname);voidinitApp() acedRegCmds-addCommand(EXAM04A, LONGTRANS, LONGTRANS, ACRX_CMD_MODAL, refEdit);void unloadApp() acedRegCmds-removeGroup(EXAM04A);extern C AcRx:AppRetCode
18、 acrxEntryPoint(AcRx:AppMsgCode msg, void* appId) switch (msg) case AcRx:kInitAppMsg: acrxDynamicLinker-unlockApplication(appId); acrxDynamicLinker-registerAppMDIAware(appId); initApp(); break; case AcRx:kUnloadAppMsg: unloadApp(); break; case AcRx:kLoadDwgMsg: break; case AcRx:kUnloadDwgMsg: break;
19、 case AcRx:kInvkSubrMsg: break; default: return AcRx:kRetOK;exam04b#include #include #include #include #include #include #include #include acestext.hvoid printXdata();void addXdata();void printList(struct resbuf* pRb);AcDbObject* selectObject(AcDb:OpenMode openMode);void initApp();void unloadApp();e
20、xtern CAcRx:AppRetCode acrxEntryPoint(AcRx:AppMsgCode, void*);voidprintXdata() AcDbObject *pObj; if (pObj = selectObject(AcDb:kForRead) = NULL) return; char appname133; if (acedGetString(NULL, nEnter the desired Xdata application name: , appname) != RTNORM) return; struct resbuf *pRb; pRb = pObj-xDa
21、ta(appname); if (pRb != NULL) printList(pRb); acutRelRb(pRb); else acutPrintf(nNo xdata for this appname); pObj-close();void addXdata() AcDbObject* pObj = selectObject(AcDb:kForRead); if (!pObj) acutPrintf(Error selecting objectn); return; char appName132, resString200; appName0 = resString0 = 0; ac
22、edGetString(NULL, Enter application name: , appName); acedGetString(NULL, Enter string to be added: , resString); struct resbuf *pRb, *pTemp; pRb = pObj-xData(appName); if (pRb != NULL) for (pTemp = pRb; pTemp-rbnext != NULL; pTemp = pTemp-rbnext) else acdbRegApp(appName); pRb = acutNewRb(AcDb:kDxfR
23、egAppName); pTemp = pRb; pTemp-resval.rstring = (char*) malloc(strlen(appName) + 1); strcpy(pTemp-resval.rstring, appName); pTemp-rbnext = acutNewRb(AcDb:kDxfXdAsciiString); pTemp = pTemp-rbnext; pTemp-resval.rstring = (char*) malloc(strlen(resString) + 1); strcpy(pTemp-resval.rstring, resString); p
24、Obj-upgradeOpen(); pObj-setXData(pRb); pObj-close(); acutRelRb(pRb);voidprintList(struct resbuf* pRb) int rt, i; char buf133; for (i = 0;pRb != NULL;i+, pRb = pRb-rbnext) if (pRb-restype restype restype restype restype = 1071) rt = RTLONG; else rt = pRb-restype; switch (rt) case RTSHORT: if (pRb-res
25、type = RTSHORT) acutPrintf( RTSHORT : %dn, pRb-resval.rint); else acutPrintf(%d . %d)n, pRb-restype, pRb-resval.rint); break; case RTREAL: if (pRb-restype = RTREAL) acutPrintf(RTREAL : %0.3fn, pRb-resval.rreal); else acutPrintf(%d . %0.3f)n, pRb-restype, pRb-resval.rreal); break; case RTSTR: if (pRb
26、-restype = RTSTR) acutPrintf(RTSTR : %sn, pRb-resval.rstring); else acutPrintf(%d . %s)n, pRb-restype, pRb-resval.rstring); break; case RT3DPOINT: if (pRb-restype = RT3DPOINT) acutPrintf( RT3DPOINT : %0.3f, %0.3f, %0.3fn, pRb-resval.rpointX, pRb-resval.rpointY, pRb-resval.rpointZ); else acutPrintf(%
27、d %0.3f %0.3f %0.3f)n, pRb-restype, pRb-resval.rpointX, pRb-resval.rpointY, pRb-resval.rpointZ); break; case RTLONG: acutPrintf(RTLONG : %dln, pRb-resval.rlong); break; if (i = 23) & (pRb-rbnext != NULL) i = 0; acedGetString(0, Press to continue., buf);AcDbObject*selectObject(AcDb:OpenMode openMode)
28、 int ss; ads_name en; ads_point pt; ss = acedEntSel(nSelect an Entity: , en, pt); AcDbObjectId eId;if (ss!=RTNORM) acutPrintf(Selection error, Return Code=%dn,ss); return NULL; Acad:ErrorStatus retStat; retStat = acdbGetObjectId(eId, en); if (retStat != Acad:eOk) acutPrintf(nacdbGetObjectId failed);
29、 acutPrintf(nen=(%lx,%lx), retStat=%dn, en0, en1, eId); return NULL; AcDbObject* obj; if (retStat = acdbOpenObject(obj, eId, openMode) != Acad:eOk) acutPrintf(acdbOpenEntity failed: ename:(%lx,%lx), mode:%d retStat:%d, en0, en1, openMode, retStat); return NULL; return obj;voidinitApp() acedRegCmds-a
30、ddCommand(EXAM04B, PRINTX, PRINTX, ACRX_CMD_MODAL, printXdata); acedRegCmds-addCommand(EXAM04B, ADDXDATA, ADDXDATA, ACRX_CMD_MODAL, addXdata);voidunloadApp() acedRegCmds-removeGroup(EXAM04B);AcRx:AppRetCodeacrxEntryPoint(AcRx:AppMsgCode msg, void* appId) switch (msg) case AcRx:kInitAppMsg: acrxDynam
31、icLinker-unlockApplication(appId);acrxDynamicLinker-registerAppMDIAware(appId); initApp(); break; case AcRx:kUnloadAppMsg: unloadApp(); return AcRx:kRetOK;exam05a#include #include #include #include #include #include #include #include void printAll();void makeABlock();void createPolyline();void addBl
32、ockWithAttributes();void defineBlockWithAttributes(AcDbObjectId&, const AcGePoint3d&, double, double);void initApp();void unloadApp();extern C AcRx:AppRetCodeacrxEntryPoint(AcRx:AppMsgCode msg, void* appId);voidmakeABlock() AcDbBlockTableRecord *pBlockTableRec = new AcDbBlockTableRecord(); pBlockTab
33、leRec-setName(NO-ATTR); AcDbBlockTable *pBlockTable = NULL; acdbHostApplicationServices()-workingDatabase() -getSymbolTable(pBlockTable, AcDb:kForWrite); AcDbObjectId blockTableRecordId; pBlockTable-add(blockTableRecordId, pBlockTableRec); pBlockTable-close(); AcDbLine *pLine = new AcDbLine(); AcDbO
34、bjectId lineId; pLine-setStartPoint(AcGePoint3d(3, 3, 0); pLine-setEndPoint(AcGePoint3d(6, 6, 0); pLine-setColorIndex(3); pBlockTableRec-appendAcDbEntity(lineId, pLine); pLine-close(); pBlockTableRec-close();voiddefineBlockWithAttributes( AcDbObjectId& blockId, const AcGePoint3d& basePoint, double t
35、extHeight, double textAngle) int retCode = 0; AcDbBlockTable *pBlockTable = NULL; AcDbBlockTableRecord* pBlockRecord = new AcDbBlockTableRecord; AcDbObjectId entityId; pBlockRecord-setName(BLOCK-WITH-ATTR); pBlockRecord-setOrigin(basePoint); acdbHostApplicationServices()-workingDatabase() -getSymbolTable(pBlockTable, AcDb:kForWrite); pBlockTa