用ObjectARX開發(fā)AutoCAD2000應(yīng)用程序配套源碼老虎工作室_第1頁
用ObjectARX開發(fā)AutoCAD2000應(yīng)用程序配套源碼老虎工作室_第2頁
用ObjectARX開發(fā)AutoCAD2000應(yīng)用程序配套源碼老虎工作室_第3頁
用ObjectARX開發(fā)AutoCAD2000應(yīng)用程序配套源碼老虎工作室_第4頁
用ObjectARX開發(fā)AutoCAD2000應(yīng)用程序配套源碼老虎工作室_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、老虎工作室實(shí)例exam03 畫直線 獲取用戶輸入點(diǎn)exam04a 打開已存在文件建立瀏覽器對象ID數(shù)組獲取當(dāng)前塊表指針常事務(wù)處理普通快(改變部分實(shí)體屬性)exam04b 交互選擇實(shí)體 擴(kuò)展數(shù)據(jù)加入 調(diào)用擴(kuò)展數(shù)據(jù)exam05a 創(chuàng)建新塊表記錄 創(chuàng)建一帶屬性快 創(chuàng)建一屬性實(shí)體 遍歷塊中實(shí)體exam06a 獲取用戶選擇集 建立組,并向其中加入選擇集實(shí)體 遍歷并改變組實(shí)體exam06b 向字典對象中加入擴(kuò)展集 調(diào)用擴(kuò)展集數(shù)據(jù)exam07 建立基于MFC的對話框 拾取點(diǎn)exam08 建一基于AcdbObject的派生類 應(yīng)用類向字典加入數(shù)據(jù)并提取exam09 建一基于拖動的類 實(shí)現(xiàn)拖動創(chuàng)建橢圓exam1

2、0a 建一臨時數(shù)據(jù)庫反映器exam10b 建派生于AcdbObject的派生類 建一有名對象詞典紀(jì)錄 將反映器對象加入詞典紀(jì)錄中 用addPersistanReactor附著實(shí)體exam13 派生于AcdbEntity畫一自定義網(wǎng)格exam14 判斷實(shí)體類型交互選擇實(shí)體轉(zhuǎn)化為AcGe對象求實(shí)體交點(diǎn)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;/確定當(dāng)前有正在工作的數(shù)據(jù)庫 if (acdbHostApplicationServices()->workingDatabase()=NULL) return Acad:eNoDatabas

5、e; /獲得當(dāng)前圖形的指針 /獲得圖形的塊表,打開準(zhǔn)備讀取數(shù)據(jù) if (es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb:kForRead)=Acad:eOk)/獲得建模空間的記錄,打開準(zhǔn)備寫數(shù)據(jù) if (es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb:kForWrite)=Acad:eOk) /添加實(shí)體指針到建模空間后關(guān)閉指針和建??臻g記錄 if (es = pSpaceReco

6、rd->appendAcDbEntity(idObj, pEnt)=Acad:eOk) pEnt->close(); pSpaceRecord->close(); /關(guān)閉塊表 pBlockTable->close(); /返回狀態(tài)信息return es;Acad:ErrorStatus newLine()ads_point pt1, pt2;/定義兩個ads_point的點(diǎn)int retval;try /從用戶處獲得第一點(diǎn)if (retval = acedGetPoint(NULL, "nSelect lower left: ", pt1) != R

7、TNORM) throw retval;/以第一點(diǎn)為基點(diǎn), 從用戶處獲得第二點(diǎn).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類型的點(diǎn)轉(zhuǎn)換為AcGePoint3d類型之后創(chuàng)建直線AcDbLine* pLine

8、= new AcDbLine(asPnt3d(pt1), asPnt3d(pt2);/如果創(chuàng)建直線出錯,返回錯誤信息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: /當(dāng)應(yīng)用程序卸載后,為防止AUOTCA

10、D調(diào)用此命令,產(chǎn)生不必要的 /錯誤,移走命令組 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論