Object Arx實用函數(shù)收集匯總.doc_第1頁
Object Arx實用函數(shù)收集匯總.doc_第2頁
Object Arx實用函數(shù)收集匯總.doc_第3頁
Object Arx實用函數(shù)收集匯總.doc_第4頁
Object Arx實用函數(shù)收集匯總.doc_第5頁
已閱讀5頁,還剩60頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

/添加HatchAcDbObjectId 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: doesnt 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;/*/函數(shù)名稱:drawDonutAtPoint/函數(shù)類型:void /返回值:/功能描述:/函數(shù)作者:Darcy/創(chuàng)建日期:2003-x-x/參數(shù)列表:/變量名:nPt 變量類型:const AcGePoint2d& 變量說明:中點/變量名:nRadius 變量類型:const double 變量說明:半徑/*void drawDonutAtPoint(const AcGePoint2d& nPt,const double nRadius)AcGePoint2d pt;AcDbPolyline * pPline = new AcDbPolyline(2);pt = nPt;pt.x -= nRadius;pPline-addVertexAt( 0 , pt , 1.0 , nRadius*2.0 , nRadius*2.0);pt.x += nRadius * 2.0;pPline-addVertexAt( 1 , pt , 1.0 , nRadius*2.0 , nRadius*2.0);pPline-setClosed(Adesk:kTrue);/添加到當(dāng)前數(shù)據(jù)庫:addToCurrentSpaceAndClose(pPline);我也跟幾貼,得點愛心幣,互相交流/得到指定層上的所有實體Acad:ErrorStatus CDrawFunction:getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,const AcArray& layerNameArr)Acad:ErrorStatus es=Acad:eOk;ASSERT(pDb);if(pDb=NULL)return Acad:eInvalidInput;AcDbBlockTable *pBlkTable=NULL;if(es=pDb-getBlockTable(pBlkTable,AcDb:kForRead)!=Acad:eOk)/打開塊表acedAlert(打開塊表失敗);return es;AcDbBlockTableRecord *pBlkTableRecord=NULL;if(es=pBlkTable-getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb:kForRead)!=Acad:eOk)/打開塊表記錄acedAlert(打開塊表記錄失敗);pBlkTable-close();return es;pBlkTable-close();/關(guān)閉塊表AcDbBlockTableRecordIterator *pIterator=NULL; /創(chuàng)建疊代器if(es=pBlkTableRecord-newIterator(pIterator)!=Acad:eOk)pBlkTableRecord-close();return es;CAcModuleResourceOverride resoverride;CProgressDlg progress;progress.Create();progress.SetPos(0);progress.SetWindowText(正在檢測圖形中所有實體.);for(pIterator-start();!pIterator-done();pIterator-step()/遍歷整個數(shù)據(jù)庫AcDbEntity *entity=NULL;es=pIterator-getEntity(entity,AcDb:kForRead); /打開實體if(es=Acad:eLockViolation)acedAlert(內(nèi)存鎖定);else if(es=Acad:eWasOpenForWrite)acedAlert(實體以寫方式打開);else if(es=Acad:eWasOpenForRead)acedAlert(實體以讀方式打開);else if(layerNameArr.contains(entity-layer()IdArr.append(entity-objectId();entity-close();progress.StepIt();delete pIterator;pIterator=NULL;pBlkTableRecord-close();acutPrintf(eend);return es;/得到指定層上指定顏色的所有實體Acad:ErrorStatus CDrawFunction:getAllEntity(AcDbDatabase *pDb,AcDbObjectIdArray& IdArr,const AcArray& layerNameArr,Adesk:UInt16 colorIndex)Acad:ErrorStatus es=Acad:eOk;ASSERT(pDb);if(pDb=NULL)return Acad:eInvalidInput;AcDbBlockTable *pBlkTable=NULL;if(es=pDb-getBlockTable(pBlkTable,AcDb:kForRead)!=Acad:eOk)/打開塊表acedAlert(打開塊表失敗);return es;AcDbBlockTableRecord *pBlkTableRecord=NULL;if(es=pBlkTable-getAt(ACDB_MODEL_SPACE,pBlkTableRecord,AcDb:kForRead)!=Acad:eOk)/打開塊表記錄acedAlert(打開塊表記錄失敗);pBlkTable-close();return es;pBlkTable-close();/關(guān)閉塊表AcDbBlockTableRecordIterator *pIterator=NULL; /創(chuàng)建疊代器if(es=pBlkTableRecord-newIterator(pIterator)!=Acad:eOk)pBlkTableRecord-close();return es;CAcModuleResourceOverride resoverride;CProgressDlg progress;progress.Create();progress.SetPos(0);progress.SetWindowText(正在檢測圖形中所有實體.);for(pIterator-start();!pIterator-done();pIterator-step()/遍歷整個數(shù)據(jù)庫AcDbEntity *entity=NULL;if(es=pIterator-getEntity(entity,AcDb:kForRead)!=Acad:eOk)/打開實體delete pIterator;pIterator=NULL;pBlkTableRecord-close();return es;if(layerNameArr.contains(entity-layer()&entity-colorIndex()=colorIndex)IdArr.append(entity-objectId();entity-close();progress.StepIt();delete pIterator;pIterator=NULL;pBlkTableRecord-close();return es;/得到圖形中所有的層Acad:ErrorStatus CDrawFunction:getAllLayerName(AcDbDatabase *pDb,CStringArray& layerArray)Acad:ErrorStatus es=Acad:eOk;if(pDb=NULL)return Acad:eInvalidInput;layerArray.RemoveAll();AcDbLayerTable *pLayerTable=NULL;if(es=pDb-getSymbolTable(pLayerTable,AcDb:kForRead)!=Acad:eOk)pLayerTable-close();return es;/創(chuàng)建一個層表迭代器AcDbLayerTableIterator *pLayerTableIterator;pLayerTable-newIterator(pLayerTableIterator);pLayerTable-close();char *pLayerName=NULL;CString name;for(int i=0;!pLayerTableIterator-done();pLayerTableIterator-step(),i+)AcDbLayerTableRecord *pLayerTableRecord=NULL;pLayerTableIterator-getRecord(pLayerTableRecord,AcDb:kForRead);pLayerTableRecord-getName(pLayerName);name.Format(%s,pLayerName);pLayerTableRecord-close();layerArray.Add(name);if(pLayerName) acutDelString(pLayerName);delete pLayerTableIterator;pLayerTableIterator=NULL;return es;/*根據(jù)線形名得到線型ID*/*/BOOL CDrawFunction:getLinetypeIdFromString(const char* str, AcDbObjectId& id)/-查找安裝目錄-/CString AcadInstallPath;FindAcadInstallPath(AcadInstallPath);CString File=AcadInstallPath+linetypeuser.lin;/-查找完畢-/ ASSERT(str!=NULL);AcDbLinetypeTable *pLinetypeTable;acdbHostApplicationServices()-workingDatabase()-getSymbolTable(pLinetypeTable, AcDb:kForRead);Acad:ErrorStatus mess;mess=pLinetypeTable-getAt(str,id);if(mess=Acad:eKeyNotFound|mess=Acad:ePermanentlyErased)pLinetypeTable-close();Acad:ErrorStatus error;error=acdbLoadLineTypeFile(str,File.GetBuffer(0),acdbHostApplicationServices()-workingDatabase();if(error=Acad:eNullObjectPointer)AcDbLinetypeTable *pLinetypeTable;acdbHostApplicationServices()-workingDatabase()-getSymbolTable(pLinetypeTable, AcDb:kForRead);pLinetypeTable-getAt(CONTINUOUS, id);pLinetypeTable-close();return FALSE;else if(error=Acad:eFileSystemErr)AfxMessageBox(the specified file cannot be opened);return FALSE;else if(error=Acad:eUndefinedLineType)AcDbLinetypeTable *pLinetypeTable;acdbHostApplicationServices()-workingDatabase()-getSymbolTable(pLinetypeTable, AcDb:kForRead);AfxMessageBox(the linetype name specified by ltname is not found in the file);pLinetypeTable-getAt(CONTINUOUS, id);pLinetypeTable-close();return TRUE;AcDbLinetypeTable *pLinetypeTable;acdbHostApplicationServices()-workingDatabase()-getSymbolTable(pLinetypeTable, AcDb:kForRead);pLinetypeTable-getAt(str,id);pLinetypeTable-close();return TRUE;pLinetypeTable-close();return TRUE;void CDrawFunction:FindAcadInstallPath(CString &AcadInstallPath)/查找樣式目錄安裝路徑TCHAR AcadPath255;HKEY hKey;if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT(SOFTWARE線路處開發(fā)組RDS20021.00),0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS):AfxMessageBox(注冊路徑不對);return ;DWORD dwDataType=REG_SZ;DWORD dwLength=255;LONG lRet=RegQueryValueEx(hKey,TEXT(path),NULL,NULL,(LPBYTE)AcadPath,&dwLength);RegCloseKey(hKey);if(lRet!=ERROR_SUCCESS)acutPrintf(Read failedn);return ;/-查找完畢-/AcadInstallPath.Format(%s,AcadPath);AcDbObjectId CDrawFunction:createTextStyle(CString fontName,CString bigFontName,CString textStyleName)AcGiTextStyle *TextStyle=new AcGiTextStyle(fontName,bigFontName,0,0.67,0,0,Adesk:kFalse,Adesk:kFalse,Adesk:kFalse,Adesk:kFalse,Adesk:kFalse,textStyleName); /字體名 AcDbObjectId textStyleId;toAcDbTextStyle(*TextStyle,textStyleId);return textStyleId;/*wuweifan2002.12.12*/*插入多行文本*/*/AcDbObjectId CDrawFunction:createMutiText(AcGePoint3d BasePoint,AcDb:TextHorzMode hMode,AcDb:TextVertMode vMode,CString Text,double texthight,double widthfactor,double angle,int color,CString smallFontName,CString bigFontName,CString layerName)ASSERT(Text!=NULL);AcDbMText *pMText=new AcDbMText();if(pMText=NULL)throw Acad:eOutOfMemory;AcDbObjectId TextStyleId;TextStyleId=createTextStyle(smallFontName,bigFontName,xianlu);pMText-setTextStyle(TextStyleId);pMText-setContents(Text.GetBuffer(Text.GetLength();pMText-setTextHeight(texthight);pMText-setRotation(angle);pMText-setLineSpacingFactor(0.8);pMText-setColorIndex(color);if(layerName!=)pMText-setLayer(layerName.GetBuffer(0);AcDbObjectId MTextId;addToModelSpace(MTextId, pMText);pMText-close();return MTextId;/*插入單行文本*/*/AcDbObjectId CDrawFunction:createtextAll(AcGePoint3d pt,char *text,AcDb:TextHorzMode hMode,AcDb:TextVertMode vMode,double hight,double widthFactor,double rotation,int color,CString smallFontName,CString bigFontName,CString layerName)ASSERT(text!=NULL);AcDbText *pText=NULL;pText=new AcDbText;if(pText=NULL)throw Acad:eOutOfMemory;AcDbObjectId textId;textId=createTextStyle(smallFontName,bigFontName,xianlu);pText-setTextStyle(textId);pText-setTextString(text);pText-setHeight(hight);pText-setColorIndex(color);pText-setRotation(rotation);pText-setWidthFactor(widthFactor);pText-setPosition(pt);if(layerName!=)pText-setLayer(layerName.GetBuffer(0);addToModelSpace(textId, pText);pText-close();return textId;/設(shè)置尺寸文本樣式void CDrawFunction:setDimTextStyle(AcDbObjectId dimId,AcDbObjectId textStyleId,int colorIndex,double textHeight,double textScator,double textGap,bool align)AcDbDimension *dimText;acdbOpenObject(dimText,dimId,AcDb:kForWrite);dimText-setDimtxsty(textStyleId); /文本字體DIMTXSTYAcCmColor color;color.setColorIndex(colorIndex);dimText-setDimclrt(color);/文本顏色DIMCLRT dimText-setDimtxt(textHeight); /文本高度DIMTXT dimText-setDimtfac(textScator);/文本高寬比DIMTFAC dimText-setDimgap(textGap);/文本距尺寸距離DIMGAP dimText-setDimtoh(align);/文本標(biāo)注DIMTOHdimText-close();/設(shè)置尺寸延伸線類型Acad:ErrorStatus CDrawFunction:setextensionlineStyle(AcDbObjectId dimId,int colorIndex,double length,double offLength,bool v1,bool v2)Acad:ErrorStatus es=Acad:eOk;AcDbDimension *dimText=NULL;if(es=acdbOpenObject(dimText,dimId,AcDb:kForWrite)!=Acad:eOk)return es;AcCmColor color;if(es=color.setColorIndex(colorIndex)!=Acad:eOk)dimText-close();return es;dimText-setDimclre(color);/設(shè)置顏色DIMCLRE dimText-setDimexe(length);/設(shè)置超出長度DIMEXE dimText-setDimexo(offLength);/尺寸偏離長度DIMEXO dimText-setDimse1(v1);/是否注第一條線DIMSE1 dimText-setDimse2(v2);/是否注第二條線DIMSE2 dimText-close();return es;/繪制對齊尺寸線AcDbObjectId CDrawFunction:drawDimension(AcGePoint3d xLine1Point,AcGePoint3d xLine2Point,double fwj,int direction,double distance,CString dimText,CString m_cLayerName)AcDbAlignedDimension *dimension=new AcDbAlignedDimension;AcGePoint3d dimLinePoint;/ CCalcuMethod *calcu=new CCalcuMethod();/ calcu-calEndZbSelf(xLine2Point,distance*direction,fwj,dimLinePoint);/ delete calcu;calcu=NULL;dimension-setXLine1Point(xLine1Point);dimension-setDimLinePoint(dimLinePoint);dimension-setXLine2Point(xLine2Point);dimension-setDimensionText(dimText.GetBuffer(0);dimension-setLayer(m_cLayerName.GetBuffer(0);AcDbObjectId dimId;addToModelSpace(dimId,dimension);dimension-close();return dimId;Acad:ErrorStatus CDrawFunction:createLine(AcDbObjectId &lineId,AcGePoint3d startPt,AcGePoint3d endPt,int color,CString Layer,char *linetype)Acad:ErrorStatus es=Acad:eOk;ASSERT(linetype!=NULL);AcDbLine *pLine = new AcDbLine(startPt, endPt);if(es=pLine-setColorIndex(color)!=Acad:eOk)pLine-close();return es;if(Layer!=)if(pLine-setLayer(Layer)=Acad:eKeyNotFound |pLine-setLayer(Layer)=Acad:eDeletedEntry )createNewLayer(Layer);if(es=pLine-setLayer(Layer.GetBuffer(0)!=Acad:eOk)pLine-close();return es;if(linetype!=NULL)AcDbObjectId lineTypeId;if(getLinetypeIdFromString(linetype,lineTypeId)if(es=pLine-setLinetype(lineTypeId)!=Acad:eOk)pLine-close();return es;if(es=pLine-setLinetypeScale(1)!=Acad:eOk)pLine-close();return es;es=addToModelSpace(lineId,pLine);return es;Acad:ErrorStatus CDrawFunction:createCircle(AcDbObjectId& circleId,AcGePoint3d center,double radius,int color,CString layer)Acad:ErrorStatus es=Acad:eOk;AcGeVector3d normal(0,0,1);AcDbCircle *circle=new AcDbCircle(center,normal,radius);if(es=circle-setColorIndex(color)!=Acad:eOk)circle-close();return es;if(layer!=)if(circle-setLayer(layer)=Acad:eKeyNotFound |circle-setLayer(layer)=Acad:eDeletedEntry )createNewLayer(layer);if(es=circle-setLayer(layer.GetBuffer(0)!=Acad:eOk)circle-close();return es;es=addToModelSpace(circleId,circle);return es;Acad:ErrorStatus CDrawFunction:DrawPolyline(AcDbObjectId& polylineId, AcGePoint3dArray ptArr, int Color, double Width,bool IsClose,CString Layer,char *linetype)Acad:ErrorStatus es=Acad:eOk; AcDb2dPolyline *pNewPline;if(IsClose)pNewPline=new AcDb2dPolyline(AcDb:k2dSimplePoly,ptArr,0,Adesk:kTrue,Width,Width);else pNewPline=new AcDb2dPolyline(AcDb:k2dSimplePoly,ptArr,0,Adesk:kFalse,Width,Width);if(es=pNewPline-setColorIndex(Color)!=Acad:eOk)pNewPline-close();return es;if(Layer!=)if(pNewPline-setLayer(Layer)=Acad:eKeyNotFound |pNewPline-setLayer(Layer)=Acad:eDeletedEntry )createNewLayer(Layer);if(es=pNewPline-setLayer(Layer)!=Acad:eOk)pNewPline-close();return es;if(linetype!=NULL)AcDbObjectId lineTypeId;if(getLinetypeIdFromString(linetype,lineTypeId)if(es=pNewPline-setLinetype(lineTypeId)!=Acad:eOk)pNewPline-close();return es;if(es=pNewPline-setLinetypeScale(1)!=Acad:eOk)pNewPline-close();return es;if(!pNewPline-isLinetypeGenerationOn()if(es=pNewPline-setLinetypeGenerationOn()!=Acad:eOk)pNewPline-close();return es;es=addToModelSpace(polylineId,pNewPline);return es;Acad:ErrorStatus CDrawFunction:DrawSplinePolyline(AcDbObjectId& polylineId, AcGePoint3dArray ptArr, int Color, double Width,bool IsClose,CString Layer,char *linetype)Acad:ErrorStatus es=Acad:eOk; AcDb2dPolyline *pNewPline;if(IsClose)pNewPline=new AcDb2dPolyline(AcDb:k2dQuadSplinePoly,ptArr,0,Adesk:kTrue,Width,Width);else pNewPline=new AcDb2dPolyline(AcDb:k2dQuadSplinePoly,ptArr,0,Adesk:kFalse,Width,Width);if(es=pNewPline-setColorIndex(Color)!=Acad:eOk)pNewPline-close();return es;if(Layer!=)if(pNewPline-setLayer(Layer)=Acad:eKeyNotFound |pNewPline-setLayer(Layer)=Acad:eDeletedEntry )createNewLayer(Layer);if(es=pNewPline-setLayer(Layer)!=Acad:eOk)pNewPline-close();return es;if(linetype!=NULL)AcDbObjectId lineTypeId;if(getLinetypeIdFromString(linetype,lineTypeId)if(es=pNewPline-setLinetype(lineTypeId)!=Acad:eOk)pNewPline-close();return es;if(es=pNewPline-setLinetypeScale(1)!=Acad:eOk)pNewPline-close();return es;if(!pNewPline-isLinetypeGenerationOn()if(es=pNewPline-setLinetypeGenerationOn()!=Acad:eOk)pNewPline-close();return es;es=addToModelSpace(polylineId,pNewPline);return es;/得到文本邊界void CDrawFunction:getTextBoundary(AcDbObjectId objectId,double offset,AcDbObjectId &textBoundaryId)AcDbExtents Ext;AcDbEntity *pEnt;acdbOpenObject(pEnt,objectId,AcDb:kForWrite);if(pEnt-isKindOf(AcDbText:desc()AcDbText *pText=AcDbText:cast(pEnt);AcGePoint3d basePoint;basePoint=pText-position();double rotateAngle=pText-rotation();pText-setRotation(0);pText-getGeomExtents(Ext);AcGePoint3d minPt,maxPt;minPt=Ext.minPoint();maxPt=Ext.maxPoint();AcGePoint3dArray pointArray;AcGePoint3d point1,point2,point3,point4;point1.x=minPt.x-offset;point1.y=minPt.y-offset;point1.z=0;pointArray.append(point1);point2.x=maxPt.x+offset;point2.y=minPt.y-offset;point2.z=0;pointArray.append(point2);point3.x=maxPt.x+offset;point3.y=maxPt.y+offset;point3.z=0;pointArray.append(point3);point4.x=minPt.x-offset;point4.y=maxPt.y+offset;point4.z=0;pointArray.append(point4);DrawPolyline(textBoundaryId,pointArray,1,0,TRUE,0,CONTINUOUS);AcGeMatrix3d matrix;AcGeVector3d axis;ident_init(matrix); axis.set(0,0,1);matrix=matrix.rotation(rotateAngle,axis,basePoint); /旋轉(zhuǎn)矩陣AcDbEntity *BounEnt;acdbOpenObject(BounEnt,textBoundaryId,AcDb:kForWrite);BounEnt-transformBy(matrix);BounEnt-close();pText-setRotation(rotateAngle);else if(pEnt-isKindOf(AcDbMText:desc()AcDbMText *pMtext=AcDbMText:cast(pEnt);AcGePoint3d basePoint;basePoint=pMtext-location();double rotateAngle=pMtext-rotation();pMtext-setRotat

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論