|
轉(zhuǎn)自 http://www./forum/read.php?tid=2644
/******************************************************************
函數(shù)名: setView 功能: 設(shè)置視圖(相當(dāng)于Zoom Window命令) 輸入?yún)?shù): Pt1 -- 視圖左上角點(diǎn) Pt2 -- 視圖右下角點(diǎn) ex_ratio -- 擴(kuò)展比率,一般為1.0 輸出參數(shù): 返回值: void 其它: *****************************************************************/ void setView(AcGePoint2d Pt1, AcGePoint2d Pt2, double ex_ratio) { AcGePoint2d CenterPt; //若X坐標(biāo)或Y坐標(biāo)重合,判為意外,不進(jìn)行SetView操作 if ((fabs(Pt1.x-Pt2.x)<1e-6)||(fabs(Pt1.y-Pt2.y)<1e-6)) return; //確保兩個(gè)坐標(biāo)點(diǎn)分別為左上角和右下角 if (Pt1.x>Pt2.x) { double tmp; tmp = Pt1.x; Pt1.x = Pt2.x; Pt2.x = tmp; } if (Pt2.y>Pt1.y) { double tmp; tmp = Pt1.y; Pt1.y = Pt2.y; Pt2.y = tmp; } //獲取當(dāng)前DwgView的尺寸 CRect CADrect; acedGetAcadDwgView()->GetClientRect(&CADrect); double width,height,ratio; ratio = (double)(CADrect.right-CADrect.left)/(double)(CADrect.bottom-CADrect.top); if (fabs(ratio)<1e-6) return; if ((Pt2.x-Pt1.x)/(Pt1.y-Pt2.y) > ratio) { width = Pt2.x-Pt1.x; height = width/ratio; }else{ height = Pt1.y-Pt2.y; width = height * ratio; } //設(shè)置當(dāng)前視圖中心點(diǎn) CenterPt.x = (Pt1.x+Pt2.x)/2; CenterPt.y = (Pt1.y+Pt2.y)/2; //改變當(dāng)前視圖 AcDbViewTableRecord pVwRec; pVwRec.setCenterPoint(CenterPt); pVwRec.setWidth(width * ex_ratio); pVwRec.setHeight(height * ex_ratio); acedSetCurrentView( &pVwRec, NULL ); } ///////////////////////////////////////////////////////////////
// 函 數(shù) 名 : oxaGetVar // 函數(shù)功能 : // 處理過(guò)程 : // 備 注 : // 作 者 : user // 時(shí) 間 : 2004年6月16日 // 返 回 值 : int // 參數(shù)說(shuō)明 : const CString strSym, // AcGePoint3d &vOut /////////////////////////////////////////////////////////////// int oxaGetVar(const CString strSym, AcGePoint3d &vOut ) { resbuf rbVar ; int iRt=acedGetVar(strSym, &rbVar) ; if (iRt!=RTNORM) { return iRt; } //oxaPrint(&rbVar); if (rbVar.restype==RTPOINT) { vOut.x=rbVar.resval.rpoint[0]; vOut.y=rbVar.resval.rpoint[1]; } if (rbVar.restype==RT3DPOINT) { vOut.x=rbVar.resval.rpoint[0]; vOut.y=rbVar.resval.rpoint[1]; vOut.z=rbVar.resval.rpoint[2]; } return RTNORM; } ///////////////////////////////////////////////////////////////////////////////// //# DOC.BEGIN //# 函數(shù)名稱(chēng): oxaGetVar //# 函數(shù)編號(hào): OXA //# 函數(shù)聲明: //# 函數(shù)參數(shù): const CString strSym, // int &vOut //# 返回值: int //# 函數(shù)分類(lèi): //# 函數(shù)功能: 獲取系統(tǒng)變量, 封裝acedGetVar() //# 注意事項(xiàng): //# 涉及的全局變量: //# 調(diào)用的OXARX函數(shù): //# 函數(shù)算法: //# ACAD版本:R14 R15 R16 //# 配合函數(shù): //# 類(lèi)似函數(shù): //# 替換函數(shù): //# 現(xiàn)存缺陷: //# 示例程序: //# 測(cè)試要求: //# 歷史記錄: 2003年11月10日 , zjw ,完成 // //# DOC.END ////////////////////////////////////////////////////////////////////////// int oxaGetVar(const CString strSym, int &vOut ) { resbuf rbVar; int iRt=acedGetVar(strSym, &rbVar) ; if (iRt!=RTNORM) { return iRt; } if (rbVar.restype==RTLONG) { vOut=rbVar.resval.rlong; } if (rbVar.restype==RTSHORT) { vOut=rbVar.resval.rint; } return RTNORM; } ///////////////////////////////////////////////////////////////////////////////// //# DOC.BEGIN //# 函數(shù)名稱(chēng): oxaGetVar //# 函數(shù)編號(hào): OXA //# 函數(shù)聲明: //# 函數(shù)參數(shù): const CString strSym, // double &vOut //# 返回值: int //# 函數(shù)分類(lèi): //# 函數(shù)功能: 獲取系統(tǒng)變量, 封裝acedGetVar() //# 注意事項(xiàng): //# 涉及的全局變量: //# 調(diào)用的OXARX函數(shù): //# 函數(shù)算法: //# ACAD版本:R14 R15 R16 //# 配合函數(shù): //# 類(lèi)似函數(shù): //# 替換函數(shù): //# 現(xiàn)存缺陷: //# 示例程序: //# 測(cè)試要求: //# 歷史記錄: 2003年11月24日 , zjw ,完成 // //# DOC.END int oxaGetVar(const CString strSym, double &vOut ) { resbuf rbVar; int iRt=acedGetVar(strSym, &rbVar) ; if (iRt!=RTNORM) { return iRt; } if (rbVar.restype==RTREAL) { vOut=rbVar.resval.rreal; } return RTNORM; } ///////////////////////////////////////////////////////////////////////////////// //# DOC.BEGIN //# 函數(shù)名稱(chēng): oxaGetVar //# 函數(shù)編號(hào): OXA //# 函數(shù)聲明: //# 函數(shù)參數(shù): const CString strSym, // CString &vOut //# 返回值: int //# 函數(shù)分類(lèi): //# 函數(shù)功能:獲取系統(tǒng)變量, 封裝acedGetVar() //# 注意事項(xiàng): //# 涉及的全局變量: //# 調(diào)用的OXARX函數(shù): //# 函數(shù)算法: //# ACAD版本:R14 R15 R16 //# 配合函數(shù): //# 類(lèi)似函數(shù): //# 替換函數(shù): //# 現(xiàn)存缺陷: //# 示例程序: //# 測(cè)試要求: //# 歷史記錄: 2003年11月24日 , zjw ,完成 // //# DOC.END int oxaGetVar(const CString strSym, CString &vOut ) { resbuf rbVar; int iRt=acedGetVar(strSym, &rbVar) ; if (iRt!=RTNORM) { return iRt; } if (rbVar.restype==RTSTR) { vOut=rbVar.resval.rstring; } return RTNORM; }
// 函數(shù)名 : SetCurTextStyle
// 描述 : 設(shè)置當(dāng)前TextStyle // 返回 : Acad::ErrorStatus // 參數(shù) : const char* lpStyleName // 參數(shù) : AcDbDatabase* pDb/* = NULL */ Acad::ErrorStatus SetCurTextStyle(const char* lpStyleName, AcDbDatabase* pDb/* = NULL */) { AcDbDatabase* pCurDb = pDb; if (pCurDb == NULL) pCurDb = acdbHostApplicationServices()->workingDatabase(); AcDbTextStyleTableRecordPointer spRecord(lpStyleName, pCurDb, AcDb::kForRead); Acad::ErrorStatus es = spRecord.openStatus(); if (es == Acad::eOk) { es = pCurDb->setTextstyle(spRecord->objectId()); } return es; } // Function name : SetCurLayer
// Description : 設(shè)置當(dāng)前層 // Return type : Acad::ErrorStatus // Argument : const char* lpLayerName // Argument : AcDbDatabase* pDb/* = NULL */ Acad::ErrorStatus SetCurLayer(const char* lpLayerName, AcDbDatabase* pDb/* = NULL */) { AcDbDatabase* pCurDb = pDb; if (pCurDb == NULL) pCurDb = acdbHostApplicationServices()->workingDatabase(); AcDbLayerTableRecordPointer spRecord(lpLayerName, pCurDb, AcDb::kForRead); Acad::ErrorStatus es = spRecord.openStatus(); if (es == Acad::eOk) { es = pCurDb->setClayer(spRecord->objectId()); } return es; } //獲取屬性塊中所有屬性的字符串值,并且存于鏈表中
void FEGroups::iterateDictionary()
{ //obtain the GROUP dictionary by looking up "ACAD_GROUP" in the named object dictionary // /* AcDbDictionary *pNamedobj; acdbHostApplicationServices()->workingDatabase() ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead); // Get a pointer to the ASDK_DICT dictionary. // AcDbDictionary *pDict; pNamedobj->getAt("ACAD_GROUP", (AcDbObject*&)pDict, AcDb::kForRead); pNamedobj->close(); */ // Get a pointer to the ACAD_GROUP dictionary AcDbDictionary *pDict; acdbHostApplicationServices()->workingDatabase() ->getGroupDictionary(pDict, AcDb::kForRead); // Get an iterator for the ASDK_DICT dictionary. // AcDbDictionaryIterator* pDictIter = pDict->newIterator(); AcDbGroup *pGroup; char* name; for (; !pDictIter->done(); pDictIter->next()) { // Get the current record, open it for read, and // print its name. // pDictIter->getObject((AcDbObject*&)pGroup, AcDb::kForRead); pGroup->getName(name); pGroup->close(); acutPrintf("\nintval is: %s", name); } delete pDictIter; pDict->close(); } //檢測(cè)AutoCAD是否已經(jīng)運(yùn)行
void Autocadtest()
{ // TODO: Add your control notification handler code here IAcadApplication m_autocad; IAcadDocuments m_acaddocs; IAcadDocument m_acaddoc; IAcadModelSpace m_acadmodel; LPDISPATCH pDisp; LPUNKNOWN pUnk; CLSID clsid; BeginWaitCursor(); ::CLSIDFromProgID(L"AutoCAD.Application",&clsid); if(::GetActiveObject(clsid,NULL,&pUnk)==S_OK) { VERIFY(pUnk->QueryInterface(IID_IDispatch,(void**) &pDisp)==S_OK); m_autocad.AttachDispatch(pDisp); pUnk->Release(); } else { if(!m_autocad.CreateDispatch("AutoCAD.Application")) { AfxMessageBox("Autocad program not found\n"); exit(1); } } m_autocad.SetVisible(true); m_acaddocs.AttachDispatch(m_autocad.GetDocuments(),true); m_acaddoc.AttachDispatch(m_acaddocs.Add(vtMissing),true); m_acadmodel.AttachDispatch(m_acaddoc.GetModelSpace(),true); m_acadmodel.AddCircle(pVal,100); m_acadmodel.ReleaseDispatch(); m_acaddoc.ReleaseDispatch(); m_acaddocs.ReleaseDispatch(); m_autocad.ReleaseDispatch(); } //計(jì)算多邊形的形心坐標(biāo)
BOOL GetPolyCentroid(AcDbPolyline * pPline, ads_point CenPt) { unsigned int i, iCount = 0; AcDbVoidPtrArray curveSegments, regions; AcGePoint3d LinePt0, LinePt1; AcGePoint3d origin; AcGeVector3d xAxis, yAxis; double perimeter, area, prodInertia; double momInertia[2], prinMoments[2], radiiGyration[2]; AcGePoint2d centroid; AcGeVector2d prinAxes[2]; AcGePoint2d extentsLow, extentsHigh; if (pPline->isClosed() != Adesk::kTrue) { ads_printf("\n折線(xiàn)不封閉, 無(wú)法形成正確的區(qū)域。"); return FALSE; } curveSegments.append((AcDbCurve *) pPline); if (AcDbRegion::createFromCurves(curveSegments, regions) != Acad::eOk){ ads_printf("\n創(chuàng)建臨時(shí)區(qū)域對(duì)象失敗!"); //清除Region, 應(yīng)第9 貼的指點(diǎn),即使createFromCurves錯(cuò)誤,也應(yīng)清除之; iCount = regions.length(); for(i = 0; i < iCount; i++) delete (AcDbRegion *)regions.at(i); return FALSE; } AcDbRegion * pRegion; if ((iCount = regions.length()) == 0){ ads_printf("\n創(chuàng)建臨時(shí)區(qū)域對(duì)象為空!"); return FALSE; } if (iCount > 1){ // 多個(gè) AcDbRegion , 無(wú)法確定應(yīng)該返回哪一個(gè),干脆返回NULL; ads_printf("\n多個(gè)區(qū)域實(shí)體。"); for(i = 0; i < iCount; i++) delete (AcDbRegion *)regions.at(i); return FALSE; } pRegion = (AcDbRegion *) regions.at(0); origin.set(0,0,0); //設(shè)置原點(diǎn)坐標(biāo) xAxis.set(1,0,0); //設(shè)置X Y軸, yAxis.set(0,1,0); if (pRegion->getAreaProp( origin, xAxis, yAxis, perimeter, area, centroid, momInertia, prodInertia, prinMoments, prinAxes, radiiGyration, extentsLow, extentsHigh) != Acad::eOk ){ ads_printf("\n區(qū)域面積: %.3f, 周長(zhǎng):%.3f", area, perimeter); ads_printf("\n獲取區(qū)域對(duì)象屬性失敗!"); delete pRegion; return FALSE; } XYZ_POINT(CenPt, centroid.x, centroid.y, 0); //得到形心坐標(biāo) ads_printf("\n區(qū)域面積: %.3f, 周長(zhǎng):%.3f", area, perimeter); pRegion->close(); delete pRegion; return TRUE; } AcDbObjectId CreateHatch(
AcDbObjectId dbOId, char cLayer[], char cPattern[] = "SOLID", int nColor = 256, double dAngle = 0.0, double dScale = 1.0, AcDbDatabase * pDbDatab = acdbHostApplicationServices()->workingDatabase()) { AcCmColor CmC; AcDbObjectId DbOId; AcDbObjectIdArray DbOIdA(0, 2); AcDbBlockTable * pDbBT; AcDbBlockTableRecord * pDbBTR; AcGeVector3d normal(0.0, 0.0, 1.0); DbOIdA.append(dbOId); AcDbHatch* pDbHat = new AcDbHatch(); pDbHat->setDatabaseDefaults(); pDbHat->setAssociative(Adesk::kTrue); // BUG: doesn't do squat! have to set the reactor yourself to get associativity! pDbHat->appendLoop(AcDbHatch::kExternal, DbOIdA); pDbHat->setPatternScale(dScale); pDbHat->setPatternAngle(dAngle); pDbHat->setPattern(AcDbHatch::kPreDefined, cPattern); pDbHat->setNormal(normal); pDbHat->evaluateHatch(); // crucial call or nothing gets displayed! pDbDatab->getSymbolTable(pDbBT, AcDb::kForRead); pDbBT->getAt(ACDB_MODEL_SPACE, pDbBTR, AcDb::kForWrite); pDbBTR->appendAcDbEntity(DbOId, pDbHat); pDbHat->setLayer(cLayer); CmC.setColorIndex(nColor); ((AcDbEntity *)pDbHat)->setColor(CmC); pDbBT->close(); pDbBTR->close(); pDbHat->close(); return DbOId; } //添加擴(kuò)展數(shù)據(jù)
//實(shí)體添加擴(kuò)展數(shù)據(jù)(字符串) bool AddXData(CString appName, AcDbObjectId entId,CString data) { //open entity for read AcDbEntity*pEnt; Acad::ErrorStatus es=acdbOpenAcDbEntity(pEnt,entId,AcDb::kForRead); if(es!=Acad::eOk) { ads_printf("error in open entity\n"); return false; } //get XData buffer struct resbuf*pRb,*pTemp; pRb=pEnt->xData(appName); if(pRb!=NULL)//have XData { //pTemp移到表尾 pTemp=pRb; for(pTemp=pRb;pTemp->rbnext!=NULL;pTemp=pTemp->rbnext){;} } else//NOT have XData { //create new xData ads_regapp(appName); pRb=ads_newrb(AcDb::kDxfRegAppName); pRb->resval.rstring=(char*)malloc(appName.GetLength()+1); strcpy(pRb->resval.rstring,appName); pTemp=pRb; } //fill xData string pTemp->rbnext=ads_newrb(AcDb::kDxfXdAsciiString); pTemp=pTemp->rbnext; pTemp->resval.rstring=(char*)malloc(data.GetLength()+1); strcpy(pTemp->resval.rstring,data); //add xData es=pEnt->upgradeOpen(); if(es!=Acad::eOk) { ads_printf("\nError occur in updateOpen."); pEnt->close(); ads_relrb(pRb); return false; } es=pEnt->setXData(pRb); if(es!=Acad::eOk) { ads_printf("\nError occur in setXData."); pEnt->close(); ads_relrb(pRb); return false; } // pEnt->close(); ads_relrb(pRb); return true; } //發(fā)命令前加按了兩個(gè)ESCAPE void SendCommand(char *cmd) { HWND wnd; char cp[3]; wnd = adsw_acadMainWnd(); if(!wnd) return; COPYDATASTRUCT cmddata; cp[0] = VK_ESCAPE; cp[1] = VK_ESCAPE; cp[2] = NULL; cmddata.dwData = (DWORD)1; cmddata.cbData = (DWORD)strlen(cp)+1; cmddata.lpData = cp; SendMessage(wnd,WM_COPYDATA,(WPARAM)cp,(LPARAM)&cmddata); cmddata.dwData = (DWORD)1; cmddata.cbData = (DWORD)strlen(cmd)+1; cmddata.lpData = cmd; SendMessage(wnd,WM_COPYDATA,(WPARAM)wnd,(LPARAM)&cmddata); } //函數(shù)功能:根據(jù)用戶(hù)指定的兩點(diǎn),自動(dòng)創(chuàng)建破斷線(xiàn) void CAD_EXTBreakLine() { acutPrintf("指定兩點(diǎn),自動(dòng)創(chuàng)建折線(xiàn)破斷線(xiàn)\n"); ads_point StartPoint,EndPoint; if(acedGetPoint(NULL,"\n請(qǐng)指定破斷線(xiàn)的起點(diǎn):",StartPoint)!=RTNORM) return; if(acedGetPoint(StartPoint,"\n請(qǐng)指定破斷線(xiàn)的終點(diǎn):",EndPoint)!=RTNORM) return; AcGePoint3d Start,End; End = AcGePoint3d(EndPoint[X],EndPoint[Y],0); Start = AcGePoint3d(StartPoint[X],StartPoint[Y],0); float Length = Start.distanceTo(End); AcGeVector3d Normal = End-Start; Normal = Normal.normal(AcGeContext::gTol); AcGePoint3d Point1(Start-Length*Normal*0.15); AcGePoint3d Point2(Start+Length*Normal*0.45); AcGePoint3d Point5(End-Length*Normal*0.45); AcGePoint3d Point6(End+Length*Normal*0.15); AcGeVector3d Normal2(-Normal.y,Normal.x,0); AcGePoint3d Point3(Start+Length*Normal*0.5+Length*Normal2*0.10); AcGePoint3d Point4(Start+Length*Normal*0.5-Length*Normal2*0.10); AcGePoint3dArray vertices; vertices.append(Point1); vertices.append(Point2); vertices.append(Point3); vertices.append(Point4); vertices.append(Point5); vertices.append(Point6); AddNewLayer("COMMANTARY"); AcDb2dPolyline* pBreakLine = new AcDb2dPolyline (AcDb::k2dSimplePoly,vertices,0,Adesk::kTrue,0,0,NULL); pBreakLine->setLayer("COMMANTARY",TRUE); AcGeMatrix3d mat; acdbUcsMatrix(mat,acdbHostApplicationServices()->workingDatabase()); pBreakLine->transformBy(mat); pBreakLine->makeOpen(); AddEntityToDb(pBreakLine); } //******************生成回轉(zhuǎn)體********************** /* pt -- 旋轉(zhuǎn)基點(diǎn) ver -- 旋轉(zhuǎn)軸 angle -- 旋轉(zhuǎn)角度(角度制) 注意: 旋轉(zhuǎn)軸不能垂直于面域平面、不能穿過(guò)面域*/ //************************************************** void CreatRevolve(AcDbObjectId entid, AcGeVector3d normal, AcGePoint3d pt, AcGeVector3d ver, double angle) { Acad::ErrorStatus es; AcDbCurve *curve; AcDbObjectId tm; if (acdbOpenObject(curve,entid,AcDb::kForWrite)!=Acad::eOk) { acutPrintf("打開(kāi)實(shí)體失??!"); return ; } AcDbVoidPtrArray lines,regions1; lines.append((void*)curve); curve->close(); es = AcDbRegion::createFromCurves(lines,regions1); if(es != Acad::eOk) { acutPrintf("獲得面域失??!"); return ; } angle = angle*PI/180; AcDbRegion *pregion1=AcDbRegion::cast((AcRxObject*)regions1[0]); AcDb3dSolid *p3dobj = new AcDb3dSolid; es = p3dobj->revolve(pregion1,pt,ver,angle); if (es != Acad::eOk) { acutPrintf("建立回轉(zhuǎn)體失敗!請(qǐng)檢查回轉(zhuǎn)軸和基準(zhǔn)點(diǎn)是否正確!"); } pBlockTableRecord->appendAcDbEntity(tm,p3dobj); p3dobj->close(); delete pregion1; } 在ObjectARX 實(shí)現(xiàn) Command 的 *Cancel* 功能: (類(lèi)似 AutoLISP 中的 ^C) acedCommand(0); // 就可以了 例如: acedCommand (RTSTR, "dim1", RTSTR, "leader", RTSTR, "0,0", RTSTR, "10,10", 0); acedCommand (0); //復(fù)制對(duì)象 void cloneSameOwnerObjects() { // Step 1: Obtain the set of objects to be cloned. ads_name sset; if (acedSSGet(NULL, NULL, NULL, NULL, sset) != RTNORM) { acutPrintf("\nNothing selected"); return; } // Step 2: Add obtained object IDs to list of objects // to be cloned. long length; acedSSLength(sset, &length); AcDbObjectIdArray objList; AcDbObjectId ownerId = AcDbObjectId::kNull; for (int i = 0; i < length; i++) { ads_name ent; acedSSName(sset, i, ent); AcDbObjectId objId; acdbGetObjectId(objId, ent); // Check to be sure this has the same owner as the first // object. // AcDbObject *pObj; acdbOpenObject(pObj, objId, AcDb::kForRead); if (pObj->ownerId() == ownerId) objList.append(objId); else if (i == 0) { ownerId = pObj->ownerId(); objList.append(objId); } pObj->close(); } acedSSFree(sset); // Step 3: Get the object ID of the desired owner for // the cloned objects. We'll use model space for // this example. // AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbObjectId modelSpaceId; pBlockTable->getAt(ACDB_MODEL_SPACE, modelSpaceId); pBlockTable->close(); // Step 4: Create a new ID map. // AcDbIdMapping idMap; // Step 5: Call deepCloneObjects(). // acdbHostApplicationServices()->workingDatabase() ->deepCloneObjects(objList, modelSpaceId, idMap); // Now we can go through the ID map and do whatever we'd // like to the original and/or clone objects. // // For this example, we'll print out the object IDs of // the new objects resulting from the cloning process. // AcDbIdMappingIter iter(idMap); for (iter.start(); !iter.done(); iter.next()) { AcDbIdPair idPair; iter.getMap(idPair); if (!idPair.isCloned()) continue; acutPrintf("\nObjectId is: %Ld", idPair.value().asOldId()); } } void selObj() { #ifdef OARXWIZDEBUG acutPrintf ("\nOARXWIZDEBUG - caditdellayObjdellayObj() called."); #endif // OARXWIZDEBUG ads_name ents; struct resbuf *rb; AcDbEntity * pEnt; AcDbText *sText; AcDbObjectId objId; ads_name ent; rb=acutNewRb(AcDb::kDxfLayerName); rb->rbnext=acutNewRb(AcDb::kDxfRegAppName); rb->restype=8; rb->resval.rstring="001"; rb=rb->rbnext; rb->restype=1001; rb->resval.rstring ="ll"; rb->rbnext=NULL; acedSSGet("X",NULL,NULL,rb,ents); long entNums=0; acedSSLength(ents,&entNums); if (entNums!= 0) { for (long a = 0; a < entNums ; a ++) { acedSSName(ents,a,ent); // ads_entdel(ent); acdbGetObjectId(objId, ent); acdbOpenObject(pEnt, objId,AcDb::kForRead); if(pEnt->isKindOf(AcDbText::desc())) { pEnt->close(); acdbOpenObject(sText, objId,AcDb::kForWrite); ads_printf(sText->textString()); if (strcmp(sText->textString(),"text")==0) { sText->setHeight(100); sText->setTextString("HELLO"); sText->setColorIndex(5); } sText->close(); } else { pEnt->close(); } } } acedSSFree(ents); acutRelRb(rb); // TODO: Implement the command } //轉(zhuǎn)換AcDbCurve到AcGeCurve3d
Acad::ErrorStatus XdDbUtils::convertDbCurveToGeCurve(AcDbCurve *pDbCurve,AcGeCurve3d *&pGeCurve) { pGeCurve=NULL; if (pDbCurve->isKindOf(AcDbLine::desc())) { AcDbLine *pL=(AcDbLine *)pDbCurve; AcGeLineSeg3d *pGL=new AcGeLineSeg3d; pGL->set(pL->startPoint(),pL->endPoint()); pGeCurve=(AcGeCurve3d *)pGL; } else if (pDbCurve->isKindOf(AcDbArc::desc())) { AcDbArc *pArc=(AcDbArc *)pDbCurve; double ans,ane; ans=pArc->startAngle(); ane=pArc->endAngle(); AcGeCircArc3d *pGArc=new AcGeCircArc3d; pGArc->setCenter(pArc->center()); pGArc->setRadius(pArc->radius()); pGArc->setAngles(ans,ane); pGeCurve=(AcGeCurve3d *)pGArc; } else if (pDbCurve->isKindOf(AcDbCircle::desc())) { AcDbCircle *pCir=(AcDbCircle *)pDbCurve; AcGeCircArc3d * pGCir=new AcGeCircArc3d; pGCir->setCenter(pCir->center()); pGCir->setRadius(pCir->radius()); pGeCurve=(AcGeCurve3d *)pGCir; } else if (pDbCurve->isKindOf(AcDbEllipse::desc())) { AcDbEllipse *pEli=(AcDbEllipse *)pDbCurve; AcGePoint3d pt1,center=pEli->center(); AcGeEllipArc3d *pGEli=new AcGeEllipArc3d; pGEli->setCenter(center); pGEli->setAxes(pEli->majorAxis(),pEli->minorAxis()); pEli->getClosestPointTo(center,pt1,Adesk::kTrue); pGEli->setMajorRadius(pt1.distanceTo(center)/pEli->radiusRatio()); pGEli->setMinorRadius(pt1.distanceTo(center)); double endang=pEli->endAngle(),startang=pEli->startAngle(); if (startang>endang){ endang+=2*PI; } pGEli->setAngles(endang,startang); pGeCurve=(AcGeCurve3d *)pGEli; } else if (pDbCurve->isKindOf(AcDbSpline::desc())) { AcDbSpline *pSL=(AcDbSpline *)pDbCurve; if (!pSL) return Acad::eNotImplemented; if (pSL->isNull()==Adesk::kTrue) return Acad::eNotImplemented; int degree; Adesk::Boolean rational; Adesk::Boolean closed; Adesk::Boolean periodic; AcGePoint3dArray controlPoints; AcGeDoubleArray knots; AcGeDoubleArray weights; double controlPtTol; double knotTol; AcGeTol tol; Acad::ErrorStatus es; es=pSL->getNurbsData(degree,rational,closed,periodic,controlPoints,knots,weights, controlPtTol,knotTol); if (es!=Acad::eOk) return Acad::eNotImplemented; if (rational==Adesk::kTrue) { AcGeNurbCurve3d *pNurb=new AcGeNurbCurve3d(degree,knots,controlPoints,weights,periodic); if (closed==Adesk::kTrue) pNurb->makeClosed(); if (pSL->hasFitData()==Adesk::kTrue) { AcGePoint3dArray fitPoints; double fitTolerance; Adesk::Boolean tangentsExist; AcGeVector3d startTangent; AcGeVector3d endTangent; pSL->getFitData(fitPoints,degree,fitTolerance,tangentsExist,startTangent,endTangent); tol.setEqualPoint(fitTolerance); if (tangentsExist==Adesk::kTrue) pNurb->setFitData(fitPoints,startTangent,endTangent,tol); else pNurb->setFitData(degree,fitPoints,tol); } pGeCurve=(AcGeCurve3d *)pNurb; } else { AcGeNurbCurve3d *pNurb=new AcGeNurbCurve3d(degree,knots,controlPoints,periodic); if (closed==Adesk::kTrue) pNurb->makeClosed(); if (pSL->hasFitData()==Adesk::kTrue) { AcGePoint3dArray fitPoints; double fitTolerance; Adesk::Boolean tangentsExist; AcGeVector3d startTangent; AcGeVector3d endTangent; pSL->getFitData(fitPoints,degree,fitTolerance,tangentsExist,startTangent,endTangent); tol.setEqualPoint(fitTolerance); if (tangentsExist==Adesk::kTrue) pNurb->setFitData(fitPoints,startTangent,endTangent,tol); else pNurb->setFitData(degree,fitPoints,tol); } pGeCurve=(AcGeCurve3d *)pNurb; } } else if ((pDbCurve->isKindOf(AcDb2dPolyline::desc()))|| (pDbCurve->isKindOf(AcDbPolyline::desc()))) { int type=0; AcDbPolyline *pPoly; if (pDbCurve->isKindOf(AcDb2dPolyline::desc())) { AcDb2dPolyline *p2L=(AcDb2dPolyline *)pDbCurve; XdDbUtils::Poly2dToLWPoly(p2L,pPoly); type=1; } else pPoly=(AcDbPolyline *)pDbCurve; XdDbUtils::convertPolylineToGeCurve(pPoly,pGeCurve); if (type) delete pPoly; } return (pGeCurve)?Acad::eOk:Acad::eNotImplemented; } // convert AcDbLine to AcGeLineSeg3d
AcGeLineSeg3d* LineDb2GE(AcDbLine* pDbLine) { return(new AcGeLineSeg3d(pDbLine->startPoint(), pDbLine->endPoint())); } // convert AcDbArc to AcGeCircArc3d
AcGeCircArc3d* ArcDb2Ge( AcDbArc* pDbArc) { return(new AcGeCircArc3d( pDbArc->center(), pDbArc->normal(), pDbArc->normal().perpVector(), pDbArc->radius(), pDbArc->startAngle(), pDbArc->endAngle())); } // convert AcDbCircle to AcGeCircArc3d
AcGeCircArc3d* CircleDb2Ge(AcDbCircle* pDbCircle) { return(new AcGeCircArc3d( pDbCircle->center(), pDbCircle->normal(), pDbCircle->radius())); } // convert AcDbSpline to AcGeNurbCurve3d
AcGeNurbCurve3d* SplineDb2Ge(AcDbSpline* pDbSpline) { AcGeNurbCurve3d* pGeSpline; AcGePoint3dArray fitPoints; int degree; double fitTolerance; Adesk::Boolean tangentsExist; AcGeVector3d startTangent, endTangent; AcGeTol tol; Adesk::Boolean rational, closed, periodic; AcGePoint3dArray controlPoints; AcGeDoubleArray knots, weights; double controlPtTol, knotTol; if (pDbSpline->hasFitData()) { pDbSpline->getFitData(fitPoints, degree, fitTolerance, tangentsExist,startTangent, endTangent); tol.setEqualPoint(fitTolerance); pGeSpline=new AcGeNurbCurve3d(fitPoints, startTangent, endTangent, tangentsExist, tangentsExist,tol); }else{ pDbSpline->getNurbsData(degree, rational, closed, periodic, controlPoints, knots, weights, controlPtTol, knotTol); pGeSpline=new AcGeNurbCurve3d(degree, knots, controlPoints, weights, periodic); if (closed==Adesk::kTrue) pGeSpline->makeClosed(); }; return(pGeSpline); } // convert AcDbEllipse to AcGeEllipArc3d
AcGeEllipArc3d* EllipseDb2Ge(AcDbEllipse* pDbEllise) { return(new AcGeEllipArc3d( pDbEllise->center(), pDbEllise->majorAxis(), pDbEllise->minorAxis(), pDbEllise->majorAxis().length(), pDbEllise->minorAxis().length(), pDbEllise->startAngle(), pDbEllise->endAngle())); } // - CGDgetOsnapPoint.getOsnapPoint command (do not rename)
static void CGDgetOsnapPointgetOsnapPoint(void) { // Add your code for command CGDgetOsnapPoint.getOsnapPoint here AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); AcDbBlockTable *pBT = NULL; AcDbBlockTableRecord *pBTR = NULL; Acad::ErrorStatus es; es = pDb->getSymbolTable (pBT,AcDb::kForRead ); if(es != Acad::eOk) { acutPrintf("get block table failure,exit\n"); return ; } es = pBT->getAt (ACDB_MODEL_SPACE,pBTR,AcDb::kForWrite ); if(es != Acad::eOk) { acutPrintf("get block table record failure,exit\n"); return ; } AcGePoint3d pnt1,pnt2,pnt; pnt1.set(8.0, 7.0, 0.0); pnt2.set(7.0, 7.0, 0.0); pnt.set(9.0,8.0,0.0); AcDbLine *pLine = new AcDbLine(pnt1,pnt2); AcDbObjectId idLine = AcDbObjectId::kNull ; pBTR->appendAcDbEntity (idLine,pLine); AcGePoint3dArray snapPoints; AcDbIntArray geomIds; es = pLine->getOsnapPoints(AcDb::kOsModePerp, 0, pnt, pnt, AcGeMatrix3d::kIdentity, snapPoints, geomIds); for(int i = 0;i<snapPoints.length();i++) { acutPrintf("/nthe point is %.2f,%f.2,%.2f/n",snapPoints.x ,snapPoints.y,snapPoints.z ); } pLine->close (); pBTR->close(); pBT->close(); ///END OF COMMAND FUNCTION } |
|
|
來(lái)自: viki > 《我的圖書(shū)館》