




已阅读5页,还剩60页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/添加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;/*/函数名称:drawDonutAtPoint/函数类型:void /返回值:/功能描述:/函数作者:Darcy/创建日期:2003-x-x/参数列表:/变量名: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);/添加到当前数据库: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();/关闭块表AcDbBlockTableRecordIterator *pIterator=NULL; /创建叠代器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()/遍历整个数据库AcDbEntity *entity=NULL;es=pIterator-getEntity(entity,AcDb:kForRead); /打开实体if(es=Acad:eLockViolation)acedAlert(内存锁定);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();/关闭块表AcDbBlockTableRecordIterator *pIterator=NULL; /创建叠代器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()/遍历整个数据库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;/创建一个层表迭代器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;/*根据线形名得到线型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线路处开发组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;/设置尺寸文本样式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);/文本标注DIMTOHdimText-close();/设置尺寸延伸线类型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);/设置颜色DIMCLRE dimText-setDimexe(length);/设置超出长度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); /旋转矩阵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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论