




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、老虎工作室实例exam03 画直线 获取用户输入点exam04a 打开已存在文件建立浏览器对象ID数组获取当前块表指针常事务处理普通快(改变部分实体属性)exam04b 交互选择实体 扩展数据加入 调用扩展数据exam05a 创建新块表记录 创建一带属性快 创建一属性实体 遍历块中实体exam06a 获取用户选择集 建立组,并向其中加入选择集实体 遍历并改变组实体exam06b 向字典对象中加入扩展集 调用扩展集数据exam07 建立基于MFC的对话框 拾取点exam08 建一基于AcdbObject的派生类 应用类向字典加入数据并提取exam09 建一基于拖动的类 实现拖动创建椭圆exam1
2、0a 建一临时数据库反映器exam10b 建派生于AcdbObject的派生类 建一有名对象词典纪录 将反映器对象加入词典纪录中 用addPersistanReactor附着实体exam13 派生于AcdbEntity画一自定义网格exam14 判断实体类型交互选择实体转化为AcGe对象求实体交点exam032exam04a2exam04b4exam05a7exam06a11exam06b13exam0715exam0820exam0923exam10a25exam10b26exam1329exam1432exam03 #include <adslib.h> #include &l
3、t;rxdlinkr.h> #include <aced.h> #include <dbents.h> #include <geassign.h> #include <dbsymtb.h> #include <dbapserv.h>Acad:ErrorStatus newLine();void addLineCommand()/BEGIN_LEVEL_ADVANCED if (newLine()=Acad:eOk) acutPrintf("Successn"); else acutPrintf("F
4、ailedn");/END_LEVEL_ADVANCEDAcad:ErrorStatus postToDatabase(/*in*/AcDbEntity* pEnt,/*out*/AcDbObjectId& idObj)Acad:ErrorStatus es;AcDbBlockTable*pBlockTable;AcDbBlockTableRecord* pSpaceRecord;/确定当前有正在工作的数据库 if (acdbHostApplicationServices()->workingDatabase()=NULL) return Acad:eNoDatabas
5、e; /获得当前图形的指针 /获得图形的块表,打开准备读取数据 if (es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb:kForRead)=Acad:eOk)/获得建模空间的记录,打开准备写数据 if (es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb:kForWrite)=Acad:eOk) /添加实体指针到建模空间后关闭指针和建模空间记录 if (es = pSpaceReco
6、rd->appendAcDbEntity(idObj, pEnt)=Acad:eOk) pEnt->close(); pSpaceRecord->close(); /关闭块表 pBlockTable->close(); /返回状态信息return es;Acad:ErrorStatus newLine()ads_point pt1, pt2;/定义两个ads_point的点int retval;try /从用户处获得第一点if (retval = acedGetPoint(NULL, "nSelect lower left: ", pt1) != R
7、TNORM) throw retval;/以第一点为基点, 从用户处获得第二点.if (retval = acedGetPoint(pt1, "nSelect upper right: ", pt2) != RTNORM)throw retval;catch (int e)if (e = RTCAN) /判断输入错误程序中断return Acad:eUserBreak;if (e = RTERROR) /判断无效输入return Acad:eInvalidInput;/ 将ads_point类型的点转换为AcGePoint3d类型之后创建直线AcDbLine* pLine
8、= new AcDbLine(asPnt3d(pt1), asPnt3d(pt2);/如果创建直线出错,返回错误信息if (!pLine)acedAlert("Not enough memory to create a Line!");return Acad:eOutOfMemory; AcDbObjectId id; /定义对象IDreturn postToDatabase(pLine, id);extern "C" AcRx:AppRetCode acrxEntryPoint(AcRx:AppMsgCode msg, void* pkt) switc
9、h (msg) case AcRx:kInitAppMsg: acrxDynamicLinker->unlockApplication(pkt); acrxDynamicLinker->registerAppMDIAware(pkt); /注册命令 acedRegCmds->addCommand("EXAM03","addline","addline",ACRX_CMD_MODAL,addLineCommand); break; case AcRx:kUnloadAppMsg: /当应用程序卸载后,为防止AUOTCA
10、D调用此命令,产生不必要的 /错误,移走命令组 acedRegCmds->removeGroup("EXAM03"); break; return AcRx:kRetOK;exam04a#include <rxregsvc.h>#include <aced.h>#include <dbidmap.h>#include <lngtrans.h>#include <dbltrans.h>#include <dbmain.h>#include <dbsymtb.h>#include <
11、dbents.h>#include <dbapserv.h>#include <adslib.h>voidrefEdit() AcDbObjectId transId; 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) acutPrint
12、f("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) acutPrintf("nSorry, that draing is probabl
13、y already open."); return; AcDbBlockTable *pBlockTable; pDb->getSymbolTable(pBlockTable, AcDb:kForRead); AcDbBlockTableRecord *pOtherMsBtr; pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb:kForRead); pBlockTable->close(); AcDbBlockTableRecordIterator *pIter; pOtherMsBtr->newIt
14、erator(pIter); AcDbObjectIdArray objIdArray; for (pIter->start(); !pIter->done(); pIter->step() AcDbEntity *pEntity; pIter->getEntity(pEntity, AcDb:kForRead); if (pEntity->isKindOf(AcDbCircle:desc() objIdArray.append(pEntity->objectId(); pEntity->close(); delete pIter; pOtherMsB
15、tr->close(); if (objIdArray.isEmpty() acad_free(fname); acutPrintf("nYou must pick a drawing file that contains circles."); return; AcDbBlockTable *pThisBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pThisBlockTable, AcDb:kForRead); AcDbBlockTableRec
16、ord *pThisMsBtr; pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb:kForWrite); pThisBlockTable->close(); AcDbObjectId id = pThisMsBtr->objectId(); pThisMsBtr->close(); AcDbIdMapping errorMap; acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, errorMap); int col
17、orIndex;double radius; acedGetInt("nEnter color number to circles center line: ", &colorIndex);acedGetReal("nEnter circle radius: ",&radius);if (radius<=0)acutPrintf("nError:Radius can't less than 0!");return; AcDbObject* pObj; if (acdbOpenObject(pObj, tr
18、ansId, AcDb:kForRead) = Acad:eOk) AcDbLongTransaction* pLongTrans = AcDbLongTransaction:cast(pObj); if (pLongTrans != NULL) AcDbLongTransWorkSetIterator* pWorkSetIter; pLongTrans->newWorkSetIterator(pWorkSetIter); for (pWorkSetIter->start(); !pWorkSetIter->done(); pWorkSetIter->step() Ac
19、DbEntity *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 radi
20、us. Press return to 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);v
21、oid unloadApp() acedRegCmds->removeGroup("EXAM04A");extern "C" AcRx:AppRetCode acrxEntryPoint(AcRx:AppMsgCode msg, void* appId) switch (msg) case AcRx:kInitAppMsg: acrxDynamicLinker->unlockApplication(appId); acrxDynamicLinker->registerAppMDIAware(appId); initApp(); brea
22、k; case AcRx:kUnloadAppMsg: unloadApp(); break; case AcRx:kLoadDwgMsg: break; case AcRx:kUnloadDwgMsg: break; case AcRx:kInvkSubrMsg: break; default: ; return AcRx:kRetOK;exam04b#include <stdlib.h>#include <string.h>#include <rxobject.h>#include <rxregsvc.h>#include <aced.
23、h>#include <dbsymtb.h>#include <adslib.h>#include "acestext.h"void printXdata();void addXdata();void printList(struct resbuf* pRb);AcDbObject* selectObject(AcDb:OpenMode openMode);void initApp();void unloadApp();extern "C"AcRx:AppRetCode acrxEntryPoint(AcRx:AppMsgC
24、ode, 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->xData(appname); if (pRb != NULL) prin
25、tList(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'
26、 acedGetString(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 acdbRe
27、gApp(appName); pRb = acutNewRb(AcDb:kDxfRegAppName); 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(strle
28、n(resString) + 1); strcpy(pTemp->resval.rstring, resString); pObj->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 < 1010) rt = RTSTR; else
29、if (pRb->restype < 1040) rt = RT3DPOINT; else if (pRb->restype < 1060) rt = RTREAL; else if (pRb->restype < 1071) rt = RTSHORT; else if (pRb->restype = 1071) rt = RTLONG; else rt = pRb->restype; switch (rt) case RTSHORT: if (pRb->restype = RTSHORT) acutPrintf( "RTSHOR
30、T : %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->r
31、esval.rreal); ; break; case RTSTR: if (pRb->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( "RT3DP
32、OINT : %0.3f, %0.3f, %0.3fn", pRb->resval.rpointX, pRb->resval.rpointY, pRb->resval.rpointZ); else acutPrintf("(%d %0.3f %0.3f %0.3f)n", pRb->restype, pRb->resval.rpointX, pRb->resval.rpointY, pRb->resval.rpointZ); break; case RTLONG: acutPrintf("RTLONG : %dl
33、n", pRb->resval.rlong); break; if (i = 23) && (pRb->rbnext != NULL) i = 0; acedGetString(0, "Press <ENTER> to continue.", buf); AcDbObject*selectObject(AcDb:OpenMode openMode) int ss; ads_name en; ads_point pt; ss = acedEntSel("nSelect an Entity: ", en, p
34、t); 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"); acutPrintf("nen=(%lx,%lx), retStat=%dn", en
35、0, 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->addCommand(&qu
36、ot;EXAM04B", "PRINTX", "PRINTX", ACRX_CMD_MODAL, printXdata); acedRegCmds->addCommand("EXAM04B", "ADDXDATA", "ADDXDATA", ACRX_CMD_MODAL, addXdata);voidunloadApp() acedRegCmds->removeGroup("EXAM04B");AcRx:AppRetCodeacrxEntryPoint(
37、AcRx:AppMsgCode msg, void* appId) switch (msg) case AcRx:kInitAppMsg: acrxDynamicLinker->unlockApplication(appId);acrxDynamicLinker->registerAppMDIAware(appId); initApp(); break; case AcRx:kUnloadAppMsg: unloadApp(); return AcRx:kRetOK;exam05a#include <string.h>#include <stdlib.h>#
38、include <aced.h>#include <dbents.h>#include <dbsymtb.h>#include <dbapserv.h>#include <geassign.h>#include <adscodes.h>void printAll();void makeABlock();void createPolyline();void addBlockWithAttributes();void defineBlockWithAttributes(AcDbObjectId&, const AcGe
39、Point3d&, double, double);void initApp();void unloadApp();extern "C" AcRx:AppRetCodeacrxEntryPoint(AcRx:AppMsgCode msg, void* appId);voidmakeABlock() AcDbBlockTableRecord *pBlockTableRec = new AcDbBlockTableRecord(); pBlockTableRec->setName("NO-ATTR"); AcDbBlockTable *pBlo
40、ckTable = NULL; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb:kForWrite); AcDbObjectId blockTableRecordId; pBlockTable->add(blockTableRecordId, pBlockTableRec); pBlockTable->close(); AcDbLine *pLine = new AcDbLine(); AcDbObjectId lineId; pLine->se
41、tStartPoint(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, doub
42、le textHeight, double textAngle) int retCode = 0; AcDbBlockTable *pBlockTable = NULL; AcDbBlockTableRecord* pBlockRecord = new AcDbBlockTableRecord; AcDbObjectId entityId; pBlockRecord->setName("BLOCK-WITH-ATTR"); pBlockRecord->setOrigin(basePoint); acdbHostApplicationServices()->
43、workingDatabase() ->getSymbolTable(pBlockTable, AcDb:kForWrite); pBlockTable->add(blockId, pBlockRecord); AcDbCircle *pCircle = new AcDbCircle; pCircle->setCenter(basePoint); pCircle->setRadius(textHeight * 4.0); pCircle->setColorIndex(3); pBlockRecord->appendAcDbEntity(entityId, p
44、Circle); pCircle->close(); AcDbAttributeDefinition *pAttdef = new AcDbAttributeDefinition; pAttdef->setPosition(basePoint); pAttdef->setHeight(textHeight); pAttdef->setRotation(textAngle); pAttdef->setHorizontalMode(AcDb:kTextLeft); pAttdef->setVerticalMode(AcDb:kTextBase); pAttdef
45、->setPrompt("Prompt"); pAttdef->setTextString("DEFAULT"); pAttdef->setTag("Tag"); pAttdef->setInvisible(Adesk:kFalse); pAttdef->setVerifiable(Adesk:kFalse); pAttdef->setPreset(Adesk:kFalse); pAttdef->setConstant(Adesk:kFalse); pAttdef->setFieldLe
46、ngth(25); pBlockRecord->appendAcDbEntity(entityId, pAttdef); AcDbAttributeDefinition *pAttdef2 = AcDbAttributeDefinition:cast(pAttdef->clone(); AcGePoint3d tempPt(basePoint); tempPt.y -= pAttdef2->height(); pAttdef2->setPosition(tempPt); pAttdef2->setColorIndex(1); pAttdef2->setCon
47、stant(Adesk:kTrue); pBlockRecord->appendAcDbEntity(entityId, pAttdef2); pAttdef->close(); pAttdef2->close(); pBlockRecord->close(); pBlockTable->close(); return;voidaddBlockWithAttributes() AcGePoint3d basePoint; if (acedGetPoint(NULL, "nEnter insertion point: ", asDblArray(
48、basePoint) != RTNORM) return; double textAngle; if (acedGetAngle(asDblArray(basePoint), "nEnter rotation angle: ", &textAngle) != RTNORM) return; double textHeight; if (acedGetDist(asDblArray(basePoint), "nEnter text height: ", &textHeight) != RTNORM) return; AcDbObjectId
49、 blockId; defineBlockWithAttributes(blockId, basePoint, textHeight, textAngle); AcDbBlockReference *pBlkRef = new AcDbBlockReference; pBlkRef->setBlockTableRecord(blockId); struct resbuf to, from; from.restype = RTSHORT; from.resval.rint = 1; to.restype = RTSHORT; to.resval.rint = 0; AcGeVector3d normal(0.0, 0.0, 1.0); acedTrans(&(normal.x), &from, &to
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 环境工程概论课件
- 《SOFIT评估》教学课件
- 动物医学产品介绍
- 勇敢牛牛创意美术课件
- 《QCC活动介绍》课件
- 主体工程安全管理与安全技术课件
- 2019-2025年教师资格之中学音乐学科知识与教学能力每日一练试卷A卷含答案
- 小白兔儿童画课件
- 幼儿园教育体系概述
- 可行性研究报告批复的材料
- 2025-2030中国供电行业深度发展研究与“十四五”企业投资战略规划报告
- 物品置换合同协议
- 心力衰竭试题及答案
- 公安治安管理培训
- 平面向量及其应用 章末题型归纳总结(基础篇)(10大题型)原卷版-2024-2025学年高一数学(人教A版必修第二册)
- 债权管理制度
- 运动营养学知到课后答案智慧树章节测试答案2025年春黑龙江冰雪体育职业学院
- 【基于改进杜邦分析法的中国东方航空公司财务分析(数据图表论文)13000字】
- 2025高级插花花艺师核心备考试题库及答案(浓缩300题)
- 光伏发电站施工规范完整版2025年
- 金氏五行升降中医方集
评论
0/150
提交评论