首页 用ObjectARX开发AutoCAD_2000应用程序_配套源码_老虎工作室

用ObjectARX开发AutoCAD_2000应用程序_配套源码_老虎工作室

举报
开通vip

用ObjectARX开发AutoCAD_2000应用程序_配套源码_老虎工作室用ObjectARX开发AutoCAD_2000应用程序_配套源码_老虎工作室 1 老虎工作室实例 exam06b 向字典对象中加入扩展集 exam03 画直线 调用扩展集数据 获取用户输入点 exam07 建立基于MFC的对话框 exam04a 打开已存在文件 拾取点 建立浏览器 exam08 建一基于AcdbObject的派生类 对象ID数组 应用类向字典加入数据并提取 获取当前块表指针 exam09 建一基于拖动的类 常事务处理普通快(改变部分实体 实现拖动创建椭圆 属性) exam10a...

用ObjectARX开发AutoCAD_2000应用程序_配套源码_老虎工作室
用ObjectARX开发AutoCAD_2000应用程序_配套源码_老虎工作室 1 老虎工作室实例 exam06b 向字典对象中加入扩展集 exam03 画直线 调用扩展集数据 获取用户输入点 exam07 建立基于MFC的对话框 exam04a 打开已存在文件 拾取点 建立浏览器 exam08 建一基于AcdbObject的派生类 对象ID数组 应用类向字典加入数据并提取 获取当前块表指针 exam09 建一基于拖动的类 常事务处理普通快(改变部分实体 实现拖动创建椭圆 属性) exam10a 建一临时数据库反映器 exam04b 交互选择实体 exam10b 建派生于AcdbObject的派生类 扩展数据加入 建一有名对象词典纪录 调用扩展数据 将反映器对象加入词典纪录中 exam05a 创建新块表记录 用addPersistanReactor附着实体 创建一带属性快 exam13 派生于AcdbEntity画一自定义网格 创建一属性实体 exam14 判断实体类型 遍历块中实体 交互选择实体 exam06a 获取用户选择集 转化为AcGe对象 建立组,并向其中加入选择集实体 求实体交点 遍历并改变组实体 exam03 .............................................................................................................................................. 2 exam04a ............................................................................................................................................ 2 exam04b ............................................................................................................................................ 4 exam05a ............................................................................................................................................ 7 exam06a .......................................................................................................................................... 11 exam06b .......................................................................................................................................... 13 exam07 ............................................................................................................................................ 15 exam08 ............................................................................................................................................ 20 exam09 ............................................................................................................................................ 23 exam10a .......................................................................................................................................... 25 exam10b .......................................................................................................................................... 26 exam13 ............................................................................................................................................ 29 exam14 ............................................................................................................................................ 32 2 if ((es = pSpaceRecord->appendAcDbEntity(idObj, exam03 #include pEnt))==Acad::eOk) #include pEnt->close(); #include pSpaceRecord->close(); #include } #include //关闭块表 #include pBlockTable->close(); #include } Acad::ErrorStatus newLine(); //返回状态信息 return es; void addLineCommand() } { //{{BEGIN_LEVEL_ADVANCED Acad::ErrorStatus newLine() if (newLine()==Acad::eOk) { acutPrintf("Success\n"); else ads_point pt1, pt2;//定义两个ads_point的点 acutPrintf("Failed\n"); int retval; //{{END_LEVEL_ADVANCED } try { Acad::ErrorStatus //从用户处获得第一点 postToDatabase(/*[in]*/AcDbEntity* pEnt,/*[out]*/AcDbObjectId& idObj) if ((retval = acedGetPoint(NULL, "\nSelect lower left: ", pt1)) != RTNORM) { throw retval; Acad::ErrorStatus es; AcDbBlockTable* pBlockTable; //以第一点为基点, 从用户处获得第二点. AcDbBlockTableRecord* pSpaceRecord; if ((retval = acedGetPoint(pt1, "\nSelect upper right: ", //确定当前有正在工作的数据库 if (acdbHostApplicationServices()->workingDatabase()==NULL) pt2)) != RTNORM) return Acad::eNoDatabase; throw retval; //获得当前图形的指针 } //获得图形的块表,打开准备读取数据 if ((es = catch (int e) acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlo { ckTable, AcDb::kForRead))==Acad::eOk){ if (e == RTCAN) //获得建模空间的记录,打开准备写数据 //判断输入错误程序中断 return Acad::eUserBreak; if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, if (e == RTERROR) pSpaceRecord, AcDb::kForWrite))==Acad::eOk){ //判断无效输入 return Acad::eInvalidInput; //添加实体指针到建模空间后关闭指针和建模空间记录 } 2 exam04a #include // 将ads_point类型的点转换为AcGePoint3d类型之后创建直线 AcDbLine* pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2)); #include #include //如果创建直线出错,返回错误信息 if (!pLine) #include { #include acedAlert("Not enough memory to create a Line!"); return Acad::eOutOfMemory; #include } #include #include AcDbObjectId id; //定义对象ID return postToDatabase(pLine, id); #include } #include extern "C" AcRx::AppRetCode void acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) refEdit() { { switch (msg) { case AcRx::kInitAppMsg: AcDbObjectId transId; AcDbDatabase* pDb; acrxDynamicLinker->unlockApplication(pkt); char *fname; struct resbuf *rb; acrxDynamicLinker->registerAppMDIAware(pkt); rb = acutNewRb(RTSTR); int stat = acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb); //注册命令 if ((stat != RTNORM) || (rb == NULL)) { acedRegCmds->addCommand("EXAM03","addline","addline",ACRX_C acutPrintf("\nYou must pick a drawing file."); MD_MODAL,addLineCommand); return; } break; case AcRx::kUnloadAppMsg: fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1); strcpy(fname, rb->resval.rstring); //当应用程序卸载后,为防止AUOTCAD调用此命令,产生不必 acutRelRb(rb); 要的 //错误,移走命令组 pDb = new AcDbDatabase(Adesk::kFalse); acedRegCmds->removeGroup("EXAM03"); if (pDb->readDwgFile(fname) != Acad::eOk) { break; acutPrintf("\nSorry, that draing is probably already open."); } return; return AcRx::kRetOK; } } 3 AcDbBlockTable *pBlockTable; AcDbIdMapping errorMap; pDb->getSymbolTable(pBlockTable, AcDb::kForRead); acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, AcDbBlockTableRecord *pOtherMsBtr; errorMap); pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead); int colorIndex; pBlockTable->close(); double radius; acedGetInt("\nEnter color number to circles center line: ", AcDbBlockTableRecordIterator *pIter; &colorIndex); pOtherMsBtr->newIterator(pIter); acedGetReal("\nEnter circle radius: ",&radius); if (radius<=0) AcDbObjectIdArray objIdArray; { acutPrintf("\nError:Radius can't less than 0!"); for (pIter->start(); !pIter->done(); pIter->step()) { return; AcDbEntity *pEntity; } pIter->getEntity(pEntity, AcDb::kForRead); AcDbObject* pObj; if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk) if (pEntity->isKindOf(AcDbCircle::desc())) { { objIdArray.append(pEntity->objectId()); } AcDbLongTransaction* pLongTrans = pEntity->close(); AcDbLongTransaction::cast(pObj); } if (pLongTrans != NULL) delete pIter; { pOtherMsBtr->close(); AcDbLongTransWorkSetIterator* pWorkSetIter; if (objIdArray.isEmpty()) { pLongTrans->newWorkSetIterator(pWorkSetIter); acad_free(fname); acutPrintf("\nYou must pick a drawing file that contains for (pWorkSetIter->start(); !pWorkSetIter->done(); circles."); pWorkSetIter->step()) return; { } AcDbEntity *pEntity; acdbOpenAcDbEntity(pEntity, AcDbBlockTable *pThisBlockTable; pWorkSetIter->objectId(), AcDb::kForWrite); acdbHostApplicationServices()->workingDatabase() pEntity->setColorIndex(colorIndex); ->getSymbolTable(pThisBlockTable, AcDb::kForRead); ((AcDbCircle*)pEntity)->setRadius(radius); AcDbBlockTableRecord *pThisMsBtr; pEntity->close(); pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, } AcDb::kForWrite); delete pWorkSetIter; pThisBlockTable->close(); } pObj->close(); AcDbObjectId id = pThisMsBtr->objectId(); } pThisMsBtr->close(); char str[132]; acedGetString(0, "\nSee the new colors and radius. Press return to 4 back", str); break; acapLongTransactionManagerPtr()->checkIn(transId, errorMap); case AcRx::kUnloadDwgMsg: pDb->saveAs(fname); break; case AcRx::kInvkSubrMsg: delete pDb; pDb = NULL; break; default: acad_free(fname); ; } } return AcRx::kRetOK; void } initApp() { exam04b #include acedRegCmds->addCommand("EXAM04A", #include "LONGTRANS", #include "LONGTRANS", #include ACRX_CMD_MODAL, #include refEdit); #include #include } #include "acestext.h" void unloadApp() void printXdata(); { void addXdata(); acedRegCmds->removeGroup("EXAM04A"); void printList(struct resbuf* pRb); AcDbObject* selectObject(AcDb::OpenMode openMode); } void initApp(); void unloadApp(); extern "C" AcRx::AppRetCode extern "C" acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*); { switch (msg) { void case AcRx::kInitAppMsg: printXdata() acrxDynamicLinker->unlockApplication(appId); { acrxDynamicLinker->registerAppMDIAware(appId); AcDbObject *pObj; initApp(); if ((pObj = selectObject(AcDb::kForRead)) == NULL) { break; return; case AcRx::kUnloadAppMsg: } unloadApp(); break; char appname[133]; case AcRx::kLoadDwgMsg: if (acedGetString(NULL, 5 "\nEnter the desired Xdata application name: ", for (pTemp = pRb; pTemp->rbnext != NULL; appname) != RTNORM) pTemp = pTemp->rbnext) { { ; } return; } else { } acdbRegApp(appName); struct resbuf *pRb; pRb = acutNewRb(AcDb::kDxfRegAppName); pRb = pObj->xData(appname); pTemp = pRb; pTemp->resval.rstring if (pRb != NULL) { = (char*) malloc(strlen(appName) + 1); strcpy(pTemp->resval.rstring, appName); printList(pRb); } acutRelRb(pRb); pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString); } else { pTemp = pTemp->rbnext; acutPrintf("\nNo xdata for this appname"); pTemp->resval.rstring } = (char*) malloc(strlen(resString) + 1); pObj->close(); strcpy(pTemp->resval.rstring, resString); } pObj->upgradeOpen(); void pObj->setXData(pRb); addXdata() { pObj->close(); AcDbObject* pObj = selectObject(AcDb::kForRead); acutRelRb(pRb); if (!pObj) { } acutPrintf("Error selecting object\n"); return; void } printList(struct resbuf* pRb) { char appName[132], resString[200]; int rt, i; appName[0] = resString[0] = '\0'; char buf[133]; acedGetString(NULL, "Enter application name: ", for (i = 0;pRb != NULL;i++, pRb = pRb->rbnext) { appName); if (pRb->restype < 1010) { acedGetString(NULL, "Enter string to be added: ", rt = RTSTR; resString); } else if (pRb->restype < 1040) { rt = RT3DPOINT; } else if (pRb->restype < 1060) { struct resbuf *pRb, *pTemp; rt = RTREAL; } else if (pRb->restype < 1071) { pRb = pObj->xData(appName); rt = RTSHORT; } else if (pRb->restype == 1071) { if (pRb != NULL) { rt = RTLONG; } else { 6 rt = pRb->restype; pRb->resval.rpoint[X], } pRb->resval.rpoint[Y], pRb->resval.rpoint[Z]); switch (rt) { } case RTSHORT: break; if (pRb->restype == RTSHORT) { acutPrintf( case RTLONG: "RTSHORT : %d\n", pRb->resval.rint); acutPrintf("RTLONG : %dl\n", pRb->resval.rlong); } else { break; acutPrintf("(%d . %d)\n", pRb->restype, } pRb->resval.rint); }; if ((i == 23) && (pRb->rbnext != NULL)) { break; i = 0; acedGetString(0, case RTREAL: "Press to continue...", buf); if (pRb->restype == RTREAL) { } acutPrintf("RTREAL : %0.3f\n", } pRb->resval.rreal); } } else { acutPrintf("(%d . %0.3f)\n", pRb->restype, AcDbObject* pRb->resval.rreal); selectObject(AcDb::OpenMode openMode) }; { break; int ss; ads_name en; case RTSTR: ads_point pt; if (pRb->restype == RTSTR) { ss = acedEntSel("\nSelect an Entity: ", en, pt); acutPrintf("RTSTR : %s\n", pRb->resval.rstring); AcDbObjectId eId; } else { if (ss!=RTNORM) acutPrintf("(%d . \"%s\")\n", pRb->restype, { pRb->resval.rstring); acutPrintf("Selection error, Return Code==%d\n",ss); }; return NULL; break; } case RT3DPOINT: Acad::ErrorStatus retStat; if (pRb->restype == RT3DPOINT) { retStat = acdbGetObjectId(eId, en); acutPrintf( if (retStat != Acad::eOk) "RT3DPOINT : %0.3f, %0.3f, %0.3f\n", { pRb->resval.rpoint[X], acutPrintf("\nacdbGetObjectId failed"); pRb->resval.rpoint[Y], acutPrintf("\nen==(%lx,%lx), retStat==%d\n", pRb->resval.rpoint[Z]); en[0], en[1], eId); } else { return NULL; acutPrintf("(%d %0.3f %0.3f %0.3f)\n", } pRb->restype, 7 AcDbObject* obj; return AcRx::kRetOK; } if ((retStat = acdbOpenObject(obj, eId, openMode)) != Acad::eOk) exam05a { #include acutPrintf("acdbOpenEntity failed: ename:(%lx,%lx)," #include " mode:%d retStat:%d", en[0], en[1], #include openMode, retStat); #include return NULL; #include } #include return obj; #include } #include void printAll(); void void makeABlock(); initApp() void createPolyline(); { void addBlockWithAttributes(); acedRegCmds->addCommand("EXAM04B", void defineBlockWithAttributes(AcDbObjectId&, "PRINTX", "PRINTX", ACRX_CMD_MODAL, const AcGePoint3d&, double, double); printXdata); acedRegCmds->addCommand("EXAM04B", void initApp(); "ADDXDATA", "ADDXDATA", ACRX_CMD_MODAL, void unloadApp(); addXdata); extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* appId); } void void makeABlock() unloadApp() { { AcDbBlockTableRecord *pBlockTableRec acedRegCmds->removeGroup("EXAM04B"); = new AcDbBlockTableRecord(); } pBlockTableRec->setName("NO-ATTR"); AcRx::AppRetCode AcDbBlockTable *pBlockTable = NULL; acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) acdbHostApplicationServices()->workingDatabase() { ->getSymbolTable(pBlockTable, AcDb::kForWrite); switch (msg) { case AcRx::kInitAppMsg: AcDbObjectId blockTableRecordId; acrxDynamicLinker->unlockApplication(appId); pBlockTable->add(blockTableRecordId, pBlockTableRec); acrxDynamicLinker->registerAppMDIAware(appId); pBlockTable->close(); initApp(); break; AcDbLine *pLine = new AcDbLine(); case AcRx::kUnloadAppMsg: AcDbObjectId lineId; unloadApp(); } pLine->setStartPoint(AcGePoint3d(3, 3, 0)); 8 pLine->setEndPoint(AcGePoint3d(6, 6, 0)); pAttdef->setVerticalMode(AcDb::kTextBase); pLine->setColorIndex(3); pAttdef->setPrompt("Prompt"); pAttdef->setTextString("DEFAULT"); pBlockTableRec->appendAcDbEntity(lineId, pLine); pAttdef->setTag("Tag"); pLine->close(); pAttdef->setInvisible(Adesk::kFalse); pBlockTableRec->close(); pAttdef->setVerifiable(Adesk::kFalse); } pAttdef->setPreset(Adesk::kFalse); pAttdef->setConstant(Adesk::kFalse); void pAttdef->setFieldLength(25); defineBlockWithAttributes( AcDbObjectId& blockId, pBlockRecord->appendAcDbEntity(entityId, pAttdef); const AcGePoint3d& basePoint, double textHeight, AcDbAttributeDefinition *pAttdef2 double textAngle) = AcDbAttributeDefinition::cast(pAttdef->clone()); { int retCode = 0; AcGePoint3d tem ppt 关于艾滋病ppt课件精益管理ppt下载地图下载ppt可编辑假如ppt教学课件下载triz基础知识ppt (basePoint); AcDbBlockTable *pBlockTable = NULL; tempPt.y -= pAttdef2->height(); AcDbBlockTableRecord* pBlockRecord pAttdef2->setPosition(tempPt); = new AcDbBlockTableRecord; pAttdef2->setColorIndex(1); AcDbObjectId entityId; pAttdef2->setConstant(Adesk::kTrue); pBlockRecord->setName("BLOCK-WITH-ATTR"); pBlockRecord->appendAcDbEntity(entityId, pAttdef2); pBlockRecord->setOrigin(basePoint); pAttdef->close(); acdbHostApplicationServices()->workingDatabase() pAttdef2->close(); ->getSymbolTable(pBlockTable, AcDb::kForWrite); pBlockRecord->close(); pBlockTable->close(); pBlockTable->add(blockId, pBlockRecord); return; } AcDbCircle *pCircle = new AcDbCircle; pCircle->setCenter(basePoint); void pCircle->setRadius(textHeight * 4.0); addBlockWithAttributes() pCircle->setColorIndex(3); { AcGePoint3d basePoint; pBlockRecord->appendAcDbEntity(entityId, pCircle); if (acedGetPoint(NULL, "\nEnter insertion point: ", pCircle->close(); asDblArray(basePoint)) != RTNORM) return; AcDbAttributeDefinition *pAttdef = new AcDbAttributeDefinition; double textAngle; if (acedGetAngle(asDblArray(basePoint), pAttdef->setPosition(basePoint); "\nEnter rotation angle: ", &textAngle) != RTNORM) pAttdef->setHeight(textHeight); return; pAttdef->setRotation(textAngle); pAttdef->setHorizontalMode(AcDb::kTextLeft); double textHeight; 9 if (acedGetDist(asDblArray(basePoint), "\nEnter text height: ", &textHeight) != RTNORM) AcDbBlockTableRecordIterator *pIterator; return; pBlockDef->newIterator(pIterator); AcDbObjectId blockId; AcDbEntity *pEnt; defineBlockWithAttributes(blockId, basePoint, AcDbAttributeDefinition *pAttdef; textHeight, textAngle); for (pIterator->start(); !pIterator->done(); pIterator->step()) AcDbBlockReference *pBlkRef = new AcDbBlockReference; { pIterator->getEntity(pEnt, AcDb::kForRead); pBlkRef->setBlockTableRecord(blockId); pAttdef = AcDbAttributeDefinition::cast(pEnt); struct resbuf to, from; if (pAttdef != NULL && !pAttdef->isConstant()) { from.restype = RTSHORT; from.resval.rint = 1; //如果实体是属性定义,创建一属性实体 to.restype = RTSHORT; to.resval.rint = 0; AcDbAttribute *pAtt = new AcDbAttribute(); pAtt->setPropertiesFrom(pAttdef); AcGeVector3d normal(0.0, 0.0, 1.0); pAtt->setInvisible(pAttdef->isInvisible()); acedTrans(&(normal.x), &from, &to, Adesk::kTrue, &(normal.x)); basePoint = pAttdef->position(); basePoint += pBlkRef->position().asVector(); pBlkRef->setPosition(basePoint); pAtt->setPosition(basePoint); pBlkRef->setRotation(0.0); pAtt->setHeight(pAttdef->height()); pBlkRef->setNormal(normal); pAtt->setRotation(pAttdef->rotation()); AcDbBlockTable *pBlockTable; pAtt->setTag("Tag"); acdbHostApplicationServices()->workingDatabase() pAtt->setFieldLength(25); ->getSymbolTable(pBlockTable, AcDb::kForRead); char *pStr = pAttdef->tag(); AcDbBlockTableRecord *pBlockTableRecord; pAtt->setTag(pStr); pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, free(pStr); AcDb::kForWrite); pAtt->setFieldLength(pAttdef->fieldLength()); pBlockTable->close(); pAtt->setTextString("Assigned Attribute Value"); AcDbObjectId newEntId; pBlockTableRecord->appendAcDbEntity(newEntId, pBlkRef); AcDbObjectId attId; pBlockTableRecord->close(); pBlkRef->appendAttribute(attId, pAtt); AcDbBlockTableRecord *pBlockDef; pAtt->close(); acdbOpenObject(pBlockDef, blockId, AcDb::kForRead); } 10 pEnt->close(); pBlockTableRecord->newIterator(pBlockIterator); } delete pIterator; for (; !pBlockIterator->done(); pBlockDef->close(); pBlockIterator->step()) pBlkRef->close(); { } AcDbEntity *pEntity; pBlockIterator->getEntity(pEntity, AcDb::kForRead); void printAll() AcDbHandle objHandle; { pEntity->getAcDbHandle(objHandle); int rc; char blkName[50]; char handleStr[20]; rc = acedGetString(Adesk::kTrue, objHandle.getIntoAsciiBuffer(handleStr); "Enter Block Name : ", const char *pCname = pEntity->isA()->name(); blkName); acutPrintf("Object Id %lx, handle %s, class %s.\n", if (rc != RTNORM) pEntity->objectId(), handleStr, pCname); return; pEntity->close(); if (blkName[0] == '\0') { } if delete pBlockIterator; (acdbHostApplicationServices()->workingDatabase()->tilemode() pBlockTableRecord->close(); == Adesk::kFalse) { struct resbuf rb; acutPrintf("\n"); acedGetVar("cvport", &rb); } if (rb.resval.rint == 1) { strcpy(blkName, ACDB_PAPER_SPACE); void } else { createPolyline() strcpy(blkName, ACDB_MODEL_SPACE); { } AcGePoint3dArray ptArr; } else { ptArr.setLogicalLength(4); strcpy(blkName, ACDB_MODEL_SPACE); for (int i = 0; i < 4; i++) { } ptArr[i].set((double)(i/2), (double)(i%2), 0.0); } } AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() AcDb2dPolyline *pNewPline = new AcDb2dPolyline( ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDb::k2dSimplePoly, ptArr, 0.0, Adesk::kTrue); AcDbBlockTableRecord *pBlockTableRecord; pNewPline->setColorIndex(3); pBlockTable->getAt(blkName, pBlockTableRecord, AcDb::kForRead); AcDbBlockTable *pBlockTable; pBlockTable->close(); acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecordIterator *pBlockIterator; 11 AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, void AcDb::kForWrite); unloadApp() { pBlockTable->close(); acedRegCmds->removeGroup("EXAM05A"); } AcDbObjectId plineObjId; pBlockTableRecord->appendAcDbEntity(plineObjId, extern "C" AcRx::AppRetCode pNewPline); acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) { pBlockTableRecord->close(); switch (msg) { case AcRx::kInitAppMsg: pNewPline->setLayer("0"); acrxDynamicLinker->unlockApplication(appId); acrxDynamicLinker->registerAppMDIAware(appId); pNewPline->close(); initApp(); } break; case AcRx::kUnloadAppMsg: void unloadApp(); initApp() } { return AcRx::kRetOK; acedRegCmds->addCommand("EXAM05A", } "MAKEABLOCK", "MAKEABLOCK", exam06a ACRX_CMD_MODAL, #include makeABlock); #include #include acedRegCmds->addCommand("EXAM05A", #include "CREATEPOLY", #include "CREATEPOLY", #include ACRX_CMD_MODAL, #include createPolyline); #include #include acedRegCmds->addCommand("EXAM05A", #include "ADDBLKWITHATT", "ADDBLKWITHATT", void groups(); ACRX_CMD_MODAL, void makeGroup(AcDbObjectId groupId); addBlockWithAttributes); void removeAllButLines(AcDbObjectId groupId); void initApp(); acedRegCmds->addCommand("EXAM05A", void unloadApp(); "PRINTALL", extern "C" "PRINTALL", AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*); ACRX_CMD_MODAL, printAll); void } groups() 12 { AcDbGroup *pGroup; AcDbGroup *pGroup = new AcDbGroup("grouptest"); acdbOpenObject(pGroup, groupId, AcDb::kForWrite); AcDbDictionary *pGroupDict; AcDbGroupIterator *pIter = pGroup->newIterator(); acdbHostApplicationServices()->workingDatabase() AcDbObject *pObj; ->getGroupDictionary(pGroupDict, AcDb::kForWrite); for (; !pIter->done(); pIter->next()) { pIter->getObject(pObj, AcDb::kForRead); AcDbObjectId groupId; pGroupDict->setAt("EXAM06A_GROUPTEST", pGroup, groupId); if (!pObj->isKindOf(AcDbLine::desc())) { pGroupDict->close(); pObj->close(); pGroup->close(); pGroup->remove(pIter->objectId()); } else { makeGroup(groupId); pObj->close(); removeAllButLines(groupId); } } } delete pIter; void makeGroup(AcDbObjectId groupId) pGroup->setColorIndex(1); { ads_name sset; pGroup->close(); int err = acedSSGet(NULL, NULL, NULL, NULL, sset); } if (err != RTNORM) { return; void } initApp() { AcDbGroup *pGroup; acedRegCmds->addCommand("EXAM06A", acdbOpenObject(pGroup, groupId, AcDb::kForWrite); "GROUPTST","GROUPTST", ACRX_CMD_MODAL, groups); } long i, length; ads_name ename; void AcDbObjectId entId; unloadApp() acedSSLength(sset, &length); { for (i = 0; i < length; i++) { acedRegCmds->removeGroup("EXAM06A"); acedSSName(sset, i, ename); } acdbGetObjectId(entId, ename); pGroup->append(entId); } AcRx::AppRetCode pGroup->close(); acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) acedSSFree(sset); { } switch (msg) { case AcRx::kInitAppMsg: void acrxDynamicLinker->unlockApplication(appId); removeAllButLines(AcDbObjectId groupId) acrxDynamicLinker->registerAppMDIAware(appId); { initApp(); 13 break; pDict->close(); case AcRx::kUnloadAppMsg: unloadApp(); struct resbuf *pHead; } ads_point testpt = {1.0, 2.0, 0.0}; return AcRx::kRetOK; pHead = acutBuildList(AcDb::kDxfText, } "This is a test Xrecord list", AcDb::kDxfXCoord, testpt, AcDb::kDxfReal, 3.14159, exam06b #include AcDb::kDxfAngle, 3.14159, #include AcDb::kDxfColor, 1, #include AcDb::kDxfInt16, 180, #include 0); #include #include pXrec->setFromRbChain(*pHead); #include #include acutRelRb(pHead); pXrec->close(); void createXrecord(); } void listXrecord(); void printList(struct resbuf* pBuf); void void initApp(); listXrecord() void unloadApp(); { extern "C" AcDbDictionary *pNamedobj; AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*); acdbHostApplicationServices()->workingDatabase() ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead); void createXrecord() AcDbDictionary *pDict; { pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict, AcDbDictionary *pNamedobj, *pDict; AcDb::kForRead); acdbHostApplicationServices()->workingDatabase() pNamedobj->close(); ->getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite); AcDbXrecord *pXrec; if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict, pDict->getAt("XREC1", (AcDbObject*&) pXrec, AcDb::kForWrite) == Acad::eKeyNotFound) AcDb::kForRead); { pDict->close(); pDict = new AcDbDictionary; AcDbObjectId DictId; struct resbuf *pRbList; pNamedobj->setAt("ASDK_DICT", pDict, DictId); pXrec->rbChain(&pRbList); } pXrec->close(); pNamedobj->close(); printList(pRbList); AcDbXrecord *pXrec = new AcDbXrecord; acutRelRb(pRbList); AcDbObjectId xrecObjId; } pDict->setAt("XREC1", pXrec, xrecObjId); 14 void if (pBuf->restype == RTREAL) printList(struct resbuf* pBuf) acutPrintf( { "RTREAL : %0.3f\n", pBuf->resval.rreal); int rt, i; else char buf[133]; acutPrintf("(%d . %0.3f)\n", pBuf->restype, pBuf->resval.rreal); for (i = 0;pBuf != NULL;i++, pBuf = pBuf->rbnext) { break; if (pBuf->restype < 0) case RTSTR: rt = pBuf->restype; if (pBuf->restype == RTSTR) else if (pBuf->restype < 10) acutPrintf( rt = RTSTR; "RTSTR : %s\n", pBuf->resval.rstring); else if (pBuf->restype < 38) else rt = RT3DPOINT; acutPrintf("(%d . \"%s\")\n", else if (pBuf->restype < 60) pBuf->restype, pBuf->resval.rstring); rt = RTREAL; break; else if (pBuf->restype < 80) case RT3DPOINT: rt = RTSHORT; if (pBuf->restype == RT3DPOINT) else if (pBuf->restype < 100) acutPrintf( rt = RTLONG; "RT3DPOINT : %0.3f, %0.3f, %0.3f\n", else if (pBuf->restype < 106) pBuf->resval.rpoint[X], rt = RTSTR; pBuf->resval.rpoint[Y], else if (pBuf->restype < 148) pBuf->resval.rpoint[Z]); rt = RTREAL; else else if (pBuf->restype < 290) acutPrintf("(%d %0.3f %0.3f %0.3f)\n", rt = RTSHORT; pBuf->restype, else if (pBuf->restype < 320) pBuf->resval.rpoint[X], rt = RTSTR; pBuf->resval.rpoint[Y], else if (pBuf->restype < 370) pBuf->resval.rpoint[Z]); rt = RTENAME; break; else if (pBuf->restype < 999) case RTLONG: rt = RT3DPOINT; acutPrintf("RTLONG : %dl\n", pBuf->resval.rlong); else break; rt = pBuf->restype; case -1: case RTENAME: switch (rt) { acutPrintf("(%d . )\n", case RTSHORT: pBuf->restype, pBuf->resval.rlname[0]); if (pBuf->restype == RTSHORT) break; acutPrintf( case -3: "RTSHORT : %d\n", pBuf->resval.rint); acutPrintf("(-3)\n"); else } acutPrintf("(%d . %d)\n", pBuf->restype, pBuf->resval.rint); if ((i == 23) && (pBuf->rbnext != NULL)) { break; i = 0; case RTREAL: acedGetString(0, 15 "Press to continue...", buf); #ifdef _DEBUG } #define new DEBUG_NEW } #undef THIS_FILE return; static char THIS_FILE[] = __FILE__; } #endif void ///////////////////////////////////////////////////////////////////////////// initApp() // MyExam07Dlg dialog { acedRegCmds->addCommand("EXAM06B", "CREATE", "CREATE", ACRX_CMD_MODAL, MyExam07Dlg::MyExam07Dlg(CWnd* pParent /*=NULL*/) createXrecord); : CAcUiDialog(MyExam07Dlg::IDD, pParent) acedRegCmds->addCommand("EXAM06B", { "LISTXREC", "LISTXREC", ACRX_CMD_MODAL, //{{AFX_DATA_INIT(MyExam07Dlg) listXrecord); // NOTE: the ClassWizard will add member initialization } here //}}AFX_DATA_INIT void } unloadApp() { acedRegCmds->removeGroup("EXAM06B"); void MyExam07Dlg::DoDataExchange(CDataExchange* pDX) } { CAcUiDialog::DoDataExchange(pDX); AcRx::AppRetCode //{{AFX_DATA_MAP(MyExam07Dlg) acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) DDX_Control(pDX, IDC_COMBO_REGAPPS, { m_ctrlRegAppComboBox); switch (msg) { DDX_Control(pDX, IDC_LIST_BLOCKS, m_ctrlBlockListBox); case AcRx::kInitAppMsg: DDX_Control(pDX, IDC_EDIT_ZPT, m_ctrlZPtEdit); acrxDynamicLinker->unlockApplication(appId); DDX_Control(pDX, IDC_EDIT_YPT, m_ctrlYPtEdit); acrxDynamicLinker->registerAppMDIAware(appId); DDX_Control(pDX, IDC_EDIT_XPT, m_ctrlXPtEdit); initApp(); DDX_Control(pDX, IDC_EDIT_ANGLE, m_ctrlAngleEdit); break; DDX_Control(pDX, IDC_BUTTON_POINT, m_ctrlPickButton); case AcRx::kUnloadAppMsg: DDX_Control(pDX, IDC_BUTTON_ANGLE, unloadApp(); m_ctrlAngleButton); } //}}AFX_DATA_MAP return AcRx::kRetOK; } } exam07 BEGIN_MESSAGE_MAP(MyExam07Dlg, CAcUiDialog) //{{AFX_MSG_MAP(MyExam07Dlg) MyExam07Dlg.cpp #include "stdafx.h" ON_BN_CLICKED(IDC_BUTTON_ANGLE, OnButtonAngle) #include "MyExam07Dlg.h" ON_BN_CLICKED(IDC_BUTTON_POINT, OnButtonPoint) #include "exam07.h" ON_CBN_KILLFOCUS(IDC_COMBO_REGAPPS, OnKillfocusComboRegapps) 16 ON_EN_KILLFOCUS(IDC_EDIT_ANGLE, SetControlProperty(dlgSizeInfo, numberofentries); OnKillfocusEditAngle) ON_EN_KILLFOCUS(IDC_EDIT_XPT, OnKillfocusEditXpt) m_ctrlXPtEdit.SetRange(-50.0, 50.0); ON_EN_KILLFOCUS(IDC_EDIT_YPT, OnKillfocusEditYpt) m_ctrlYPtEdit.SetRange(-50.0, 50.0); ON_EN_KILLFOCUS(IDC_EDIT_ZPT, OnKillfocusEditZpt) m_ctrlZPtEdit.SetRange(-50.0, 50.0); //}}AFX_MSG_MAP END_MESSAGE_MAP() m_ctrlAngleEdit.SetRange(0.0, 90.0 /*(PI/2.0)*/); ///////////////////////////////////////////////////////////////////////////// SetWindowText("AcUiDialog Sample"); // MyExam07Dlg message handlers m_ctrlPickButton.AutoLoad(); BOOL MyExam07Dlg::OnInitDialog() m_ctrlAngleButton.AutoLoad(); { if (!GetDialogData("ANGLE", m_strAngle)) SetDialogName("exam07:MyExam07Dlg"); m_strAngle = "0.0"; CAcUiDialog::OnInitDialog(); if (!GetDialogData("POINTX", m_strXPt)) DLGCTLINFO dlgSizeInfo[]= { m_strXPt = "0.0"; { IDC_STATIC_GROUP1, ELASTICX, 20 }, if (!GetDialogData("POINTY", m_strYPt)) { IDC_STATIC_GROUP1, ELASTICY, 100 }, m_strYPt = "0.0"; { IDC_EDIT_XPT,ELASTICX, 20 }, if (!GetDialogData("POINTZ", m_strZPt)) { IDC_EDIT_YPT,ELASTICX, 20 }, m_strZPt = "0.0"; { IDC_EDIT_ZPT,ELASTICX, 20 }, DisplayPoint(); { IDC_EDIT_ANGLE, ELASTICX, 20 }, DisplayAngle(); { IDC_STATIC_GROUP2, MOVEX, 20 }, DisplayBlocks(); { IDC_STATIC_GROUP2, ELASTICY, 100 }, DisplayRegApps(); { IDC_STATIC_GROUP2, ELASTICX, 80 }, return TRUE; { IDC_LIST_BLOCKS, MOVEX, 20 }, } { IDC_LIST_BLOCKS, ELASTICY, 100 }, { IDC_STATIC_TEXT2,MOVEX, 20 }, void MyExam07Dlg::DisplayPoint() { IDC_STATIC_TEXT2,MOVEY, 100 }, { { IDC_LIST_BLOCKS, ELASTICX, 80 }, m_ctrlXPtEdit.SetWindowText(m_strXPt); { IDC_STATIC_TEXT2,ELASTICX, 80 }, m_ctrlXPtEdit.Convert(); { IDC_STATIC_GROUP3, MOVEY, 100 }, m_ctrlYPtEdit.SetWindowText(m_strYPt); { IDC_STATIC_GROUP3, ELASTICX, 20 }, m_ctrlYPtEdit.Convert(); { IDC_COMBO_REGAPPS, MOVEY, 100 }, m_ctrlZPtEdit.SetWindowText(m_strZPt); { IDC_COMBO_REGAPPS, ELASTICX, 20 }, m_ctrlZPtEdit.Convert(); { IDC_STATIC_TEXT3,MOVEY, 100 }, } { IDC_STATIC_TEXT3,ELASTICX, 20 }, { IDOK,MOVEX, 100 }, bool MyExam07Dlg::ValidatePoint() { IDCANCEL, MOVEX, 100 }, { }; if (!m_ctrlXPtEdit.Validate()) return false; const DWORD numberofentries = if (!m_ctrlYPtEdit.Validate()) sizeof dlgSizeInfo / sizeof DLGCTLINFO; return false; 17 if (!m_ctrlZPtEdit.Validate()) return false; void MyExam07Dlg::DisplayRegApps() return true; { } AcDbRegAppTable *pRegAppTable; acdbHostApplicationServices()->workingDatabase() void MyExam07Dlg::DisplayAngle() ->getSymbolTable(pRegAppTable, AcDb::kForRead); { m_ctrlAngleEdit.SetWindowText(m_strAngle); char *pName; m_ctrlAngleEdit.Convert(); AcDbRegAppTableIterator *pItr; } if (pRegAppTable->newIterator(pItr) == Acad::eOk) { bool MyExam07Dlg::ValidateAngle() while (!pItr->done()) { { if (!m_ctrlAngleEdit.Validate()) AcDbRegAppTableRecord *pRecord; return false; if (pItr->getRecord(pRecord, AcDb::kForRead) return true; == Acad::eOk) } { pRecord->getName(pName); void MyExam07Dlg::DisplayBlocks() m_ctrlRegAppComboBox.InsertString(-1, { pName); AcDbBlockTable *pBlockTable; pRecord->close(); acdbHostApplicationServices()->workingDatabase() } ->getSymbolTable(pBlockTable, AcDb::kForRead); pItr->step(); } char *pName; } AcDbBlockTableIterator *pBTItr; pRegAppTable->close(); if (pBlockTable->newIterator(pBTItr) == Acad::eOk) } { while (!pBTItr->done()) void MyExam07Dlg::OnButtonAngle() { { AcDbBlockTableRecord *pRecord; BeginEditorCommand(); if (pBTItr->getRecord(pRecord, AcDb::kForRead) == Acad::eOk) ads_point pt; { acdbDisToF(m_strXPt, -1, &pt[X]); pRecord->getName(pName); acdbDisToF(m_strYPt, -1, &pt[Y]); m_ctrlBlockListBox.InsertString(-1, acdbDisToF(m_strZPt, -1, &pt[Z]); pName); double angle; pRecord->close(); } if (acedGetAngle(pt, "\nPick an angle: ", &angle) == RTNORM) { pBTItr->step(); } CompleteEditorCommand(); } pBlockTable->close(); m_strAngle.Format("%g", angle*(180.0/PI)); } DisplayAngle(); 18 } void MyExam07Dlg::OnKillfocusEditZpt() else { { m_ctrlZPtEdit.Convert(); CancelEditorCommand(); m_ctrlZPtEdit.GetWindowText(m_strZPt); } } } void MyExam07Dlg::OnKillfocusComboRegapps() void MyExam07Dlg::OnButtonPoint() { { CString strFromEdit; m_ctrlRegAppComboBox.GetWindowText(strFromEdit); BeginEditorCommand(); if (m_ctrlRegAppComboBox.FindString(-1, strFromEdit) == ads_point pt; CB_ERR) if (acdbRegApp(strFromEdit) == RTNORM) if (acedGetPoint(NULL, "\nPick a point: ", pt) == RTNORM) { CompleteEditorCommand(); m_ctrlRegAppComboBox.AddString(strFromEdit); m_strXPt.Format("%g", pt[X]); } m_strYPt.Format("%g", pt[Y]); m_strZPt.Format("%g", pt[Z]); void MyExam07Dlg::OnOK() DisplayPoint(); { } if (!ValidatePoint()) else { { AfxMessageBox("Sorry, Point out of desired range."); CancelEditorCommand(); m_ctrlXPtEdit.SetFocus(); } return; } } if (!ValidateAngle()) void MyExam07Dlg::OnKillfocusEditAngle() { { AfxMessageBox("Sorry, Angle out of desired range."); m_ctrlAngleEdit.Convert(); m_ctrlAngleEdit.SetFocus(); m_ctrlAngleEdit.GetWindowText(m_strAngle); return; } } void MyExam07Dlg::OnKillfocusEditXpt() SetDialogData("ANGLE", m_strAngle); { SetDialogData("POINTX", m_strXPt); m_ctrlXPtEdit.Convert(); SetDialogData("POINTY", m_strYPt); m_ctrlXPtEdit.GetWindowText(m_strXPt); SetDialogData("POINTZ", m_strZPt); } CAcUiDialog::OnOK(); } void MyExam07Dlg::OnKillfocusEditYpt() exam07.cpp { #include "stdafx.h" m_ctrlYPtEdit.Convert(); #include "exam07.h" m_ctrlYPtEdit.GetWindowText(m_strYPt); } #include "MyExam07Dlg.h" #include "AcExtensionModule.h" 19 { #ifdef _DEBUG theArxDLL.AttachInstance(hInstance); #define new DEBUG_NEW } #undef THIS_FILE else if (dwReason == DLL_PROCESS_DETACH) static char THIS_FILE[] = __FILE__; { #endif theArxDLL.DetachInstance(); extern "C" HWND adsw_acadMainWnd(); } return 1; // ok } AC_IMPLEMENT_EXTENSION_MODULE(theArxDLL); extern "C" AcRx::AppRetCode acrxEntryPoint( void dialogCreate() AcRx::AppMsgCode msg, void* appId) { { // Modal switch( msg ) MyExam07Dlg dlg(CWnd::FromHandle(adsw_acadMainWnd())); { int nReturnValue = dlg.DoModal(); case AcRx::kInitAppMsg: } acrxDynamicLinker->unlockApplication(appId); acrxDynamicLinker->registerAppMDIAware(appId); static void initApp() initApp(); { break; CAcModuleResourceOverride resOverride; case AcRx::kUnloadAppMsg: acedRegCmds->addCommand( unloadApp(); "EXAM07", break; "ACUISAMPLE", case AcRx::kInitDialogMsg: "ACUISAMPLE", break; ACRX_CMD_MODAL, default: dialogCreate, break; NULL, } -1, return AcRx::kRetOK; theArxDLL.ModuleResourceInstance()); } } MyExam07Dlg.h #include "resource.h" static void unloadApp() #include { #include acedRegCmds->removeGroup("EXAM07"); #include } #include #include extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) class MyExam07Dlg : public CAcUiDialog { { UNREFERENCED_PARAMETER(lpReserved); // Construction public: if (dwReason == DLL_PROCESS_ATTACH) MyExam07Dlg(CWnd* pParent = NULL); // standard 20 constructor virtual void OnOK(); afx_msg void OnKillfocusComboRegapps(); void DisplayPoint(); afx_msg void OnKillfocusEditAngle(); bool ValidatePoint(); afx_msg void OnKillfocusEditXpt(); void DisplayAngle(); afx_msg void OnKillfocusEditYpt(); bool ValidateAngle(); afx_msg void OnKillfocusEditZpt(); void DisplayBlocks(); //}}AFX_MSG void DisplayRegApps(); DECLARE_MESSAGE_MAP() }; CString m_strAngle; CString m_strXPt; exam08 CString m_strYPt; #include CString m_strZPt; #include #include // Dialog Data #include //{{AFX_DATA(MyExam07Dlg) #include enum { IDD = IDD_DIALOG1 }; #include CAcUiSymbolComboBox m_ctrlRegAppComboBox; CAcUiListBox m_ctrlBlockListBox; void createDictionary(); CAcUiPickButton m_ctrlPickButton; void iterateDictionary(); CAcUiPickButton m_ctrlAngleButton; void initApp(); CAcUiAngleEdit m_ctrlAngleEdit; void unloadApp(); CAcUiNumericEdit m_ctrlXPtEdit; extern "C" CAcUiNumericEdit m_ctrlYPtEdit; AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*); CAcUiNumericEdit m_ctrlZPtEdit; //}}AFX_DATA //下面是对类的定义 class AsdkMyClass : public AcDbObject { // Overrides public: // ClassWizard generated virtual function overrides ACRX_DECLARE_MEMBERS(AsdkMyClass); //{{AFX_VIRTUAL(MyExam07Dlg) AsdkMyClass(): mIntval(0) {}; protected: AsdkMyClass(const Adesk::Int16& val): mIntval(val) {}; virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support Acad::ErrorStatus getData (Adesk::Int16&); //}}AFX_VIRTUAL Acad::ErrorStatus setData (Adesk::Int16); // Implementation virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler*); protected: virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler*) const; // Generated message map functions virtual Acad::ErrorStatus dxfInFields (AcDbDxfFiler*); //{{AFX_MSG(MyExam07Dlg) virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler*) virtual BOOL OnInitDialog(); const; afx_msg void OnButtonAngle(); private: afx_msg void OnButtonPoint(); Adesk::Int16 mIntval; 21 }; if (pFiler->filerType() == AcDb::kWblockCloneFiler) ACRX_DXF_DEFINE_MEMBERS(AsdkMyClass, AcDbObject, pFiler->writeHardPointerId((AcDbHardPointerId)ownerId()); AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, pFiler->writeItem(mIntval); 0, return pFiler->filerStatus(); ASDKMYCLASS, SAMP2); } Acad::ErrorStatus Acad::ErrorStatus AsdkMyClass::getData(Adesk::Int16& val) AsdkMyClass::dxfInFields(AcDbDxfFiler* pFiler) { { assertReadEnabled(); assertWriteEnabled(); val = mIntval; return Acad::eOk; Acad::ErrorStatus es; } if ((es = AcDbObject::dxfInFields(pFiler)) != Acad::eOk) Acad::ErrorStatus { AsdkMyClass::setData(Adesk::Int16 val) return es; { } assertWriteEnabled(); mIntval = val; if (!pFiler->atSubclassData("AsdkMyClass")) { return Acad::eOk; return Acad::eBadDxfSequence; } } Acad::ErrorStatus struct resbuf inbuf; AsdkMyClass::dwgInFields(AcDbDwgFiler* pFiler) while (es == Acad::eOk) { { if ((es = pFiler->readItem(&inbuf)) == Acad::eOk) { assertWriteEnabled(); if (inbuf.restype == AcDb::kDxfInt16) { mIntval = inbuf.resval.rint; AcDbObject::dwgInFields(pFiler); } } if (pFiler->filerType() == AcDb::kWblockCloneFiler) { } AcDbHardPointerId id; return pFiler->filerStatus(); pFiler->readItem(&id); } } pFiler->readItem(&mIntval); Acad::ErrorStatus return pFiler->filerStatus(); AsdkMyClass::dxfOutFields(AcDbDxfFiler* pFiler) const } { assertReadEnabled(); Acad::ErrorStatus AsdkMyClass::dwgOutFields(AcDbDwgFiler* pFiler) const AcDbObject::dxfOutFields(pFiler); { pFiler->writeItem(AcDb::kDxfSubclass, "AsdkMyClass"); assertReadEnabled(); pFiler->writeItem(AcDb::kDxfInt16, mIntval); return pFiler->filerStatus(); AcDbObject::dwgOutFields(pFiler); } 22 void AcDbDictionaryIterator* pDictIter= pDict->newIterator(); createDictionary() { AsdkMyClass *pMyCl; AcDbDictionary *pNamedobj; Adesk::Int16 val; acdbHostApplicationServices()->workingDatabase()-> for (; !pDictIter->done(); pDictIter->next()) { getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite); pDictIter->getObject((AcDbObject*&)pMyCl, AcDbDictionary *pDict; AcDb::kForRead); if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict, pMyCl->getData(val); AcDb::kForWrite) == Acad::eKeyNotFound) pMyCl->close(); { acutPrintf("\nintval is: %d", val); pDict = new AcDbDictionary; } AcDbObjectId DictId; delete pDictIter; pNamedobj->setAt("ASDK_DICT", pDict, DictId); pDict->close(); } } pNamedobj->close(); void if (pDict) { initApp() AsdkMyClass *pObj1 = new AsdkMyClass(1); { AsdkMyClass *pObj2 = new AsdkMyClass(2); acedRegCmds->addCommand("EXAM08", "CREATE", "CREATE", ACRX_CMD_MODAL, AcDbObjectId rId1, rId2; createDictionary); pDict->setAt("OBJ1", pObj1, rId1); pDict->setAt("OBJ2", pObj2, rId2); acedRegCmds->addCommand("EXAM08", "ITERATE", "ITERATE", ACRX_CMD_MODAL, pObj1->close(); iterateDictionary); pObj2->close(); pDict->close(); AsdkMyClass::rxInit(); } acrxBuildClassHierarchy(); } } void void iterateDictionary() unloadApp() { { AcDbDictionary *pNamedobj; acedRegCmds->removeGroup("EXAM08"); acdbHostApplicationServices()->workingDatabase() ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead); deleteAcRxClass(AsdkMyClass::desc()); } AcDbDictionary *pDict; pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict, AcRx::AppRetCode AcDb::kForRead); acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) { pNamedobj->close(); switch (msg) { 23 case AcRx::kInitAppMsg: acrxDynamicLinker->unlockApplication(appId); void acrxDynamicLinker->registerAppMDIAware(appId); AsdkEllipseJig::doIt() initApp(); { break; mpEllipse = new AcDbEllipse; case AcRx::kUnloadAppMsg: setDispPrompt("\nEllipse major axis: "); unloadApp(); AcEdJig::DragStatus stat = drag(); } return AcRx::kRetOK; } mPromptCounter++; setDispPrompt("\nEllipse minor axis: "); exam09 #include stat = drag(); #include #include #include append(); #include } #include AcEdJig::DragStatus AsdkEllipseJig::sampler() class AsdkEllipseJig : public AcEdJig { { DragStatus stat; public: AsdkEllipseJig(const AcGePoint3d&, const AcGeVector3d&); setUserInputControls((UserInputControls) void doIt(); (AcEdJig::kAccept3dCoordinates virtual DragStatus sampler(); | AcEdJig::kNoNegativeResponseAccepted virtual Adesk::Boolean update(); | AcEdJig::kNoZeroResponseAccepted)); virtual AcDbEntity* entity() const; if (mPromptCounter == 0) { private: AcDbEllipse *mpEllipse; static AcGePoint3d axisPointTemp; AcGePoint3d mCenterPt, mAxisPt; stat = acquirePoint(mAxisPt, mCenterPt); AcGeVector3d mMajorAxis, mNormal; if (axisPointTemp != mAxisPt) double mRadiusRatio; axisPointTemp = mAxisPt; int mPromptCounter; else if (stat == AcEdJig::kNormal) }; return AcEdJig::kNoChange; } AsdkEllipseJig::AsdkEllipseJig( else if (mPromptCounter == 1) { const AcGePoint3d& pt, const AcGeVector3d& normal) static double radiusRatioTemp = -1; : mCenterPt(pt), stat = acquireDist(mRadiusRatio, mCenterPt); mNormal(normal), if (radiusRatioTemp != mRadiusRatio) mRadiusRatio(0.00001), radiusRatioTemp = mRadiusRatio; mPromptCounter(0) else if (stat == AcEdJig::kNormal) { } return AcEdJig::kNoChange; 24 } acedTrans(asDblArray(tempPt), &rbFrom, &rbTo, return stat; Adesk::kFalse, asDblArray(tempPt)); } AcGeVector3d x = Adesk::Boolean acdbHostApplicationServices()->workingDatabase() AsdkEllipseJig::update() ->ucsxdir(); { AcGeVector3d y = switch (mPromptCounter) { acdbHostApplicationServices()->workingDatabase() case 0: ->ucsydir(); AcGeVector3d normalVec = x.crossProduct(y); mMajorAxis = mAxisPt - mCenterPt; normalVec.normalize(); break; case 1: AsdkEllipseJig *pJig = new AsdkEllipseJig(tempPt, normalVec); mRadiusRatio = mRadiusRatio / mMajorAxis.length(); break; pJig->doIt(); } delete pJig; mpEllipse->set(mCenterPt, mNormal, mMajorAxis, } mRadiusRatio); void return Adesk::kTrue; initApp() } { acedRegCmds->addCommand("EXAM09", AcDbEntity* "VELLIPSE", "VELLIPSE", ACRX_CMD_MODAL, AsdkEllipseJig::entity() const createEllipse); { } return mpEllipse; } void unloadApp() void { createEllipse() acedRegCmds->removeGroup("EXAM09"); { } AcGePoint3d tempPt; struct resbuf rbFrom, rbTo; extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) acedGetPoint(NULL, "\nEllipse center point: ", { asDblArray(tempPt)); switch (msg) { case AcRx::kInitAppMsg: rbFrom.restype = RTSHORT; acrxDynamicLinker->unlockApplication(appId); rbFrom.resval.rint = 1; // from UCS acrxDynamicLinker->registerAppMDIAware(appId); rbTo.restype = RTSHORT; initApp(); rbTo.resval.rint = 0; // to WCS break; case AcRx::kUnloadAppMsg: 25 unloadApp(); MyDbReactor::objectAppended(const AcDbDatabase* db, } const AcDbObject* pObj) return AcRx::kRetOK; { } printDbEvent(pObj, "objectAppended"); acutPrintf(" Db==%lx\n", (long) db); exam10a #include "rxobject.h" gEntAcc++; #include "rxregsvc.h" acutPrintf("Entity Count = %d\n", gEntAcc); #include "rxdlinkr.h" } #include "rxditer.h" #include "aced.h" #include "dbmain.h" void #include "dbdict.h" MyDbReactor::objectModified(const AcDbDatabase* db, #include "dbidmap.h" const AcDbObject* pObj) #include "dbapserv.h" { #include "adslib.h" printDbEvent(pObj, "objectModified"); acutPrintf(" Db==%lx\n", (long) db); void printDbEvent(const AcDbObject*, const char* eventStr); } void printObj(const AcDbObject* pObj); void watchDb(); void void clearReactors(); MyDbReactor::objectErased(const AcDbDatabase* db, extern "C" const AcDbObject* pObj, Adesk::Boolean pErased) AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*); { if (pErased) { class MyDbReactor; printDbEvent(pObj, "objectErased"); gEntAcc--; long gEntAcc = 0; } else { MyDbReactor *gpDbr = NULL; printDbEvent(pObj, "object(Un)erased"); gEntAcc++; class MyDbReactor : public AcDbDatabaseReactor } { acutPrintf(" Db==%lx\n", (long) db); public: acutPrintf("Entity Count = %d\n", gEntAcc); } virtual void objectAppended(const AcDbDatabase* dwg, const AcDbObject* dbObj); void virtual void objectModified(const AcDbDatabase* dwg, printDbEvent(const AcDbObject* pObj, const char* pEvent) const AcDbObject* dbObj); { acutPrintf(" Event: AcDbDatabaseReactor::%s ", pEvent); virtual void objectErased(const AcDbDatabase* dwg, printObj(pObj); const AcDbObject* dbObj, Adesk::Boolean pErased); } }; void void printObj(const AcDbObject* pObj) 26 { if (pObj == NULL) { AcRx::AppRetCode acutPrintf("(NULL)"); acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) return; { } switch (msg) { case AcRx::kInitAppMsg: AcDbHandle objHand; acrxDynamicLinker->unlockApplication(appId); char handbuf[17]; acrxDynamicLinker->registerAppNotMDIAware(appId); acedRegCmds->addCommand("EXAM10A", pObj->getAcDbHandle(objHand); "WATCH", objHand.getIntoAsciiBuffer(handbuf); "WATCH", ACRX_CMD_TRANSPARENT, acutPrintf( watchDb); "\n (class==%s, handle==%s, id==%lx, db==%lx)", pObj->isA()->name(), handbuf, acedRegCmds->addCommand("EXAM10A", pObj->objectId().asOldId(), pObj->database()); "CLEAR", } "CLEAR", ACRX_CMD_TRANSPARENT, clearReactors); void break; watchDb() case AcRx::kUnloadAppMsg: { clearReactors(); if (gpDbr == NULL) { acedRegCmds->removeGroup("EXAM10A"); gpDbr = new MyDbReactor(); break; } } return AcRx::kRetOK; acdbHostApplicationServices()->workingDatabase()->addReactor(gpDbr); } acutPrintf( exam10b " Added Database Reactor to " "acdbHostApplicationServices()->workingDatabase().\n"); #include } #include #include #include void #include clearReactors() #include { #include if (acdbHostApplicationServices()->workingDatabase() != NULL) { void assocLines(); acdbHostApplicationServices()->workingDatabase()->removeReactor(gpDvoid addToModelSpace(AcDbObjectId&, AcDbEntity*); br); void initApp(void); delete gpDbr; void unloadApp(void); gpDbr = NULL; extern "C" } AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*); } 27 class MyObjectNotify : public AcDbObject p = pLine2->startPoint(); { q = pLine2->endPoint(); public: v = q-p; ACRX_DECLARE_MEMBERS(MyObjectNotify); v = len * mFactor * v.normal(); MyObjectNotify() {}; pLine2->setEndPoint(p+v); void eLinkage(AcDbObjectId i, double f=1.0) pLine2->close(); {mId=i; mFactor=f; }; } void modified(const AcDbObject*); } Acad::ErrorStatus dwgInFields(AcDbDwgFiler*); Acad::ErrorStatus dwgOutFields(AcDbDwgFiler*) const; Acad::ErrorStatus dxfInFields(AcDbDxfFiler*); Acad::ErrorStatus Acad::ErrorStatus dxfOutFields(AcDbDxfFiler*) const; MyObjectNotify::dwgInFields(AcDbDwgFiler* filer) { private: assertWriteEnabled(); AcDbObjectId mId; AcDbObject::dwgInFields(filer); double mFactor; filer->readItem(&mFactor); }; filer->readItem((AcDbSoftPointerId*) &mId); return filer->filerStatus(); ACRX_DXF_DEFINE_MEMBERS(MyObjectNotify, AcDbObject, } AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 0, MYOBJECTMODIFY, exam10b); Acad::ErrorStatus void MyObjectNotify::dwgOutFields(AcDbDwgFiler* filer) const MyObjectNotify::modified(const AcDbObject* pObj) { { assertReadEnabled(); AcDbLine *pLine = AcDbLine::cast(pObj); AcDbObject::dwgOutFields(filer); if (!pLine) { filer->writeItem(mFactor); const char* cstr = pObj->isA()->name(); filer->writeItem((AcDbSoftPointerId&)mId); acutPrintf("This is a %s.\n", cstr); return filer->filerStatus(); acutPrintf("I only work with lines. Sorry.\n"); } return; } acutPrintf("\nReactor attached to %lx calling %lx.\n", Acad::ErrorStatus pLine->objectId(), mId); MyObjectNotify::dxfInFields(AcDbDxfFiler* filer) { AcDbLine *pLine2; assertWriteEnabled(); if (acdbOpenObject((AcDbObject*&)pLine2, mId, AcDb::kForWrite) == Acad::eOk) Acad::ErrorStatus es; { if ((es = AcDbObject::dxfInFields(filer)) AcGePoint3d p = pLine->startPoint(); != Acad::eOk) AcGePoint3d q = pLine->endPoint(); { AcGeVector3d v = q-p; return es; double len = v.length(); } 28 if(!filer->atSubclassData("MyObjectNotify")) { pLineA->setDatabaseDefaults(pDb); return Acad::eBadDxfSequence; pLineA->setStartPoint(AcGePoint3d(1, 1, 0)); } pLineA->setEndPoint(AcGePoint3d(2, 1, 0)); addToModelSpace(aId, pLineA); struct resbuf rbIn; ads_printf( "Line A is %lx from 1,1 to 2,1.\n", while (es == Acad::eOk) { pLineA->objectId()); if ((es = filer->readItem(&rbIn)) == Acad::eOk) { if (rbIn.restype == AcDb::kDxfReal) { mFactor = rbIn.resval.rreal; AcDbLine *pLineB = new AcDbLine; } else if (rbIn.restype pLineB->setDatabaseDefaults(pDb); == AcDb::kDxfSoftPointerId) pLineB->setStartPoint(AcGePoint3d(1, 2, 0)); { pLineB->setEndPoint(AcGePoint3d(2, 2, 0)); acdbGetObjectId(mId, rbIn.resval.rlname); addToModelSpace(bId, pLineB); } else { return(filer->pushBackItem()); ads_printf("Line B is %lx from 1,2 to 2,2.\n", } pLineB->objectId()); } } AcDbDictionary *pNamedObj; return filer->filerStatus(); AcDbDictionary *pNameList; } pDb->getNamedObjectsDictionary(pNamedObj, AcDb::kForWrite); if (pNamedObj->getAt("ASDK_DICT", Acad::ErrorStatus (AcDbObject*&)pNameList, AcDb::kForWrite) MyObjectNotify::dxfOutFields(AcDbDxfFiler* filer) const == Acad::eKeyNotFound) { { assertReadEnabled(); pNameList = new AcDbDictionary; AcDbObject::dxfOutFields(filer); AcDbObjectId DictId; filer->writeItem(AcDb::kDxfSubclass, pNamedObj->setAt("ASDK_DICT", pNameList, DictId); "MyObjectNotify"); } filer->writeItem(AcDb::kDxfReal, mFactor); pNamedObj->close(); filer->writeItem(AcDb::kDxfSoftPointerId, mId); return filer->filerStatus(); MyObjectNotify *pObj = new MyObjectNotify(); } pObj->eLinkage(bId); AcDbObjectId objId; void if ((pNameList->getAt("object_to_notify_A", objId)) assocLines() == Acad::eKeyNotFound) { { AcDbDatabase *pDb = pNameList->setAt("object_to_notify_A", pObj, objId); acdbHostApplicationServices()->workingDatabase(); pObj->close(); AcDbObjectId aId, bId; } else { delete pObj; AcDbLine *pLineA = new AcDbLine; ads_printf("object_to_notify_A already exists\n"); 29 } initApp() { pLineA->addPersistentReactor(objId); acedRegCmds->addCommand("EXAM10B", "ALINES", pLineA->close(); "ALINES", ACRX_CMD_MODAL, assocLines); pObj = new MyObjectNotify(); MyObjectNotify::rxInit(); pObj->eLinkage(aId); acrxBuildClassHierarchy(); } if ((pNameList->getAt("object_to_notify_B", objId)) == Acad::eKeyNotFound) { void pNameList->setAt("object_to_notify_B", pObj, objId); unloadApp() pObj->close(); { } else { acedRegCmds->removeGroup("EXAM10B"); delete pObj; ads_printf("object_to_notify_B already exists\n"); deleteAcRxClass(MyObjectNotify::desc()); } } pNameList->close(); pLineB->addPersistentReactor(objId); AcRx::AppRetCode pLineB->close(); acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) } { switch (msg) { void case AcRx::kInitAppMsg: addToModelSpace(AcDbObjectId &objId, AcDbEntity* pEntity) acrxDynamicLinker->unlockApplication(appId); { acrxDynamicLinker->registerAppMDIAware(appId); AcDbBlockTable *pBlockTable; initApp(); AcDbBlockTableRecord *pSpaceRecord; break; case AcRx::kUnloadAppMsg: acdbHostApplicationServices()->workingDatabase() unloadApp(); ->getSymbolTable(pBlockTable, AcDb::kForRead); } return AcRx::kRetOK; pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, } AcDb::kForWrite); exam13 pBlockTable->close(); #include "aced.h" pSpaceRecord->appendAcDbEntity(objId, pEntity); #include "dbsymtb.h" pSpaceRecord->close(); #include "dbapserv.h" #include "acgi.h" return; #include "acedads.h" } #include "adslib.h" static const Adesk::UInt16 kColorByBlock = 0; void static const Adesk::UInt16 kRed = 1; 30 static const Adesk::UInt16 kYellow = 2; int numCols; static const Adesk::UInt16 kGreen = 3; static const Adesk::UInt16 kCyan = 4; result=acedGetInt("\nPlease Input Row Number: ", &numRows); static const Adesk::UInt16 kBlue = 5; if (result!=RTNORM) static const Adesk::UInt16 kMagenta = 6; { static const Adesk::UInt16 kWhite = 7; acutPrintf("\nInput Failed!"); static const Adesk::UInt16 kColorByLayer = 256; return Adesk::kFalse; } if (numRows<=0||numRows>10) class MyMesh: public AcDbEntity { { acutPrintf("\nInvalid Input!"); public: return Adesk::kFalse; ACRX_DECLARE_MEMBERS(MyMesh); } MyMesh(); ~MyMesh(); result=acedGetInt("\nPlease Input Col Number: ", &numCols); virtual Adesk::Boolean worldDraw(AcGiWorldDraw *); if (result!=RTNORM) Acad::ErrorStatus transformBy(const AcGeMatrix3d &); { }; acutPrintf("\nInput Failed!"); return Adesk::kFalse; ACRX_DXF_DEFINE_MEMBERS(MyMesh, AcDbEntity, } AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 0,\ if (numCols<=0||numCols>10) EXAM13, exam13); { acutPrintf("\nInvalid Input!"); return Adesk::kFalse; MyMesh::MyMesh() } { } AcGePoint3d *pVerts = new AcGePoint3d[numRows * numCols]; MyMesh::~MyMesh() { for (k = 0, i = 0; i < (Adesk::UInt32)numRows; i++) } { for (j = 0; j < (Adesk::UInt32)numCols; j++, k++) Acad::ErrorStatus { MyMesh::transformBy(const AcGeMatrix3d &xfm) pVerts[k].x = (double)(j+100); { pVerts[k].y = (double)(i+100); return Acad::eOk; pVerts[k].z = 0.; } } } Adesk::Boolean MyMesh::worldDraw(AcGiWorldDraw* pW) AcGiEdgeData edgeInfo; { Adesk::UInt32 numRowEdges = numRows * (numCols - 1); Adesk::UInt32 i, j, k; Adesk::UInt32 numColEdges = (numRows - 1) * numCols; int result; Adesk::UInt32 numEdges = numRowEdges + numColEdges; int numRows; short *pEdgeColorArray = new short[numEdges]; 31 es = acdbHostApplicationServices()->workingDatabase() for (i = 0; i < numEdges; i++) ->getSymbolTable(pBlockTable, AcDb::kForRead); { if (es != Acad::eOk) pEdgeColorArray[i] = (short)(i%7+1); return; } edgeInfo.setColors(pEdgeColorArray); AcDbBlockTableRecord *pBlock; es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlock, Adesk::UInt32 numFaces = (numRows - 1) AcDb::kForWrite); * (numCols - 1); if (es != Acad::eOk) Adesk::UInt8 *pFaceVisArray = return; new Adesk::UInt8[numFaces]; short *pFaceColorArray = new short[numFaces]; AcDbObjectId objId; AcGiFaceData faceInfo; MyMesh *pNewObj = new MyMesh; faceInfo.setVisibility(pFaceVisArray); es = pBlock->appendAcDbEntity(objId, pNewObj); if (es != Acad::eOk) for (i = 0; i < numFaces; i++) { { delete pNewObj; pFaceVisArray[i] = return; i ? kAcGiVisible : kAcGiInvisible; } pFaceColorArray[i] = (short)(i + 1); } es = pBlock->close(); faceInfo.setColors(pFaceColorArray); if (es != Acad::eOk) acrx_abort("\nUnable to close block table record"); pW->subEntityTraits().setFillType(kAcGiFillAlways); pW->geometry().mesh(numRows, numCols, pVerts, NULL, es = pBlockTable->close(); &faceInfo); if (es != Acad::eOk) acrx_abort("\nUnable to close block table"); pW->subEntityTraits().setFillType(kAcGiFillNever); pW->geometry().mesh(numRows, numCols, pVerts, es = pNewObj->close(); &edgeInfo); if (es != Acad::eOk) acrx_abort("\nUnable to close new entity"); delete [] pVerts; } delete [] pEdgeColorArray; delete [] pFaceColorArray; static void delete [] pFaceVisArray; initApp() { return Adesk::kTrue; MyMesh::rxInit(); } acrxBuildClassHierarchy(); static void acedRegCmds->addCommand("EXAM13", addMyMeshObject() "MAKEMESH", { "MAKEMESH", Acad::ErrorStatus es; ACRX_CMD_TRANSPARENT, AcDbBlockTable *pBlockTable; addMyMeshObject); 32 } acdbOpenObject(ent,entId,AcDb::kForRead); extern "C" AcRx::AppRetCode if (ent->isKindOf(AcDbLine::desc())) acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) { { type=1; switch (msg) { } case AcRx::kInitAppMsg: if (ent->isKindOf(AcDbCircle::desc())) acrxDynamicLinker->unlockApplication(appId); { acrxDynamicLinker->registerAppMDIAware(appId); type=2; initApp(); } break; case AcRx::kUnloadAppMsg: ent->close(); acedRegCmds->removeGroup("EXAM13"); return type; deleteAcRxClass(MyMesh::desc()); } } return AcRx::kRetOK; // } void GetIntersectPoint() { exam14 #include ads_name adsent1,adsent2; #include ads_point pt1,pt2; #include int ret; #include Adesk::Boolean ret2; #include int type1,type2; #include #include AcDbEntity *ent1; #include AcDbObjectId ent1Id; #include "math.h" #include "stdio.h" ret=acedEntSel(NULL,adsent1,pt1); if (ret == RTCAN) int GetObjectType(ads_name &name); { void GetIntersectPoint(); acedPrompt("\nUser Cancelled!"); void initApp(); return; void unloadApp(); } extern "C" if (ret == RTERROR) AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode, void*); { acedPrompt("\nSelect Error!"); // return; int GetObjectType(ads_name &name) } { int type=0; acdbGetObjectId(ent1Id,adsent1); AcDbEntity *ent; acdbOpenObject(ent1,ent1Id,AcDb::kForRead); AcDbObjectId entId; type1=GetObjectType(adsent1); acdbGetObjectId(entId,name); if(type1==0) 33 { { acedPrompt("\nPlease Select a Line or Circle!"); case 1: return; lineSeg1.set(((AcDbLine*)ent1)->startPoint(), } ((AcDbLine*)ent1)->endPoint()); break; acedPrompt("\nSelect Second Line"); case 2: ret=acedEntSel(NULL,adsent2,pt2); cir1.set(((AcDbCircle*)ent1)->center(), ((AcDbCircle*)ent1)->normal(), if (ret == RTCAN) ((AcDbCircle*)ent1)->radius()); { break; acedPrompt("\nUser Cancelled!"); } return; } int intNumber=1; if (ret == RTERROR) { switch (type2) acedPrompt("\nSelect Error!"); { return; case 1: } lineSeg2.set(((AcDbLine*)ent2)->startPoint(), ((AcDbLine*)ent2)->endPoint()); AcDbEntity *ent2; if (type1==1) AcDbObjectId ent2Id; { acdbGetObjectId(ent2Id,adsent2); ret2=lineSeg2.intersectWith(lineSeg1,intersectPoint1); intNumber=1; } if (ent2Id==ent1Id) else { { acedPrompt("\nMultiple Object Selected!"); ret2=cir1.intersectWith( return; lineSeg2,intNumber,intersectPoint1, } intersectPoint2); } acdbOpenObject(ent2,ent2Id,AcDb::kForRead); break; type2=GetObjectType(adsent2); case 2: if(type2==0) cir2.set(((AcDbCircle*)ent2)->center(), { ((AcDbCircle*)ent2)->normal(), acedPrompt("\nPlease Select a Line Circle or Arc!"); ((AcDbCircle*)ent2)->radius()); return; if (type1==1) } { ret2=cir2.intersectWith( AcGePoint3d intersectPoint1,intersectPoint2; lineSeg1,intNumber,intersectPoint1, AcGeLineSeg3d lineSeg1,lineSeg2; intersectPoint2); AcGeCircArc3d cir1,cir2; } else switch (type1) { 34 ret2=cir2.intersectWith( { cir1,intNumber,intersectPoint1, acedRegCmds->addCommand("EXAM14", intersectPoint2); "INTP","INTP", } ACRX_CMD_MODAL, break; GetIntersectPoint); } acedPrompt("Use intp to calculate two lines' intersection point!"); if (ret2 == Adesk::kTrue) } { acedPrompt("\nIntersectPoint calculated!\n"); // char text[50]; void sprintf(text,"X=%f, Y=%f, Z=%f",intersectPoint1.x, unloadApp() intersectPoint1.y,intersectPoint1.z); { acedPrompt(text); acedRegCmds->removeGroup("EXAM14"); if (intNumber==2) } { sprintf(text,"X=%f, Y=%f, Z=%f",intersectPoint2.x, // ARX entry point intersectPoint2.y,intersectPoint2.z); // acedPrompt(text); AcRx::AppRetCode } acrxEntryPoint(AcRx::AppMsgCode msg, void* appId) } { else switch (msg) { { case AcRx::kInitAppMsg: acedPrompt("\nLines Have No Intersectpoint!"); acrxDynamicLinker->unlockApplication(appId); } acrxDynamicLinker->registerAppMDIAware(appId); initApp(); ent1->close(); break; ent2->close(); case AcRx::kUnloadAppMsg: } unloadApp(); } // return AcRx::kRetOK; void } initApp()
本文档为【用ObjectARX开发AutoCAD_2000应用程序_配套源码_老虎工作室】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_079973
暂无简介~
格式:doc
大小:172KB
软件:Word
页数:69
分类:互联网
上传时间:2017-12-07
浏览量:168