ARX几个典型的简单程序(转载)

创建窗体图层"Window_Layer"/ AcDbObjectId createWindowsLayer() { //打开层表,打开方式为只写/// AcDbLayerTable *pLayerTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTable,AcDb::kForWrite); //初始化层表记录对象,并设定层表记录的名称“Window_Layer” AcDbLayerTableRecord *pLayerTableRecord=new AcDbLayerTableRecord; pLayerTableRecord->setName("Window_Layer"); AcCmColor color; color.setColorIndex(1); // set color to red pLayerTableRecord->setColor(color); //层的其他属性(线型等)都用缺省值 //将新建的层表记录添加到层表中,并将层表记录的ID保存到pLayerId作为函数的返回值 AcDbObjectId pLayerId; pLayerTable->add(pLayerId,pLayerTableRecord); //关闭层表和层表记录对象/// pLayerTable->close(); pLayerTableRecord->close(); return pLayerId; } ///*************在指定点插入指定块*******************/// void CTestPlate::OnBlockInsert() { // TODO: Add your control notification handler code here acDocManager->lockDocument(curDoc()); AcDbObjectId blockId; //要插入的块的Id值 AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable,AcDb::kForRead); Acad::eOk!=pBlockTable->getAt("ASDK-NO-ATTR", blockId,AcDb::kForRead)//根据块名获得要插入的块的ID值 AcDbBlockReference *pBlkRef=new AcDbBlockReference;//插入块实质是插入块的引用 pBlkRef->setBlockTableRecord(blockId);//指定所引用的图块表记录的对象ID resbuf to,from; from.restype=RTSHORT;//插入图块要进行用户坐标与世界坐标的转换 from.resval.rint=1;//UCS to.restype=RTSHORT; to.resval.rint=0;//WCS AcGeVector3d normal(0.0,0.0,1.0); acedTrans(&(normal.x),&from,&to,Adesk::kTrue,&(normal.x));//转换函数 AcGePoint3d basePoint(12,23,0);//指定的插入点(可以根据需要输入) //acedGetPoint(NULL,"/nEnter insertion point:",asDblArray(basePoint)); pBlkRef->setPosition(basePoint); pBlkRef->setRotation(0.0); pBlkRef->setNormal(normal); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); pBlockTable->close(); AcDbObjectId newEntId; pBlockTableRecord->appendAcDbEntity(newEntId,pBlkRef); pBlockTableRecord->close(); pBlkRef->close(); acDocManager->lockDocument(curDoc()); } //點遷多義線中之一直線,獲得線段之位置(圓弧可自行補上) void GetPolyLineSelectLineIndex(AcDbPolyline *Poly,AcGePoint3d SelectPt,int Index) { AcGePoint2d tempPt; double Distance=11111111; tempPt.x=SelectPt.x; tempPt.y=SelectPt.y; AcDbVoidPtrArray entitySet; Poly->explode(entitySet); for(int i=0;i { AcDbEntity *pEnt; pEnt=AcDbPolyline::cast((AcRxObject*)entitySet[i]); if(pEnt->isA()==AcDbLine::desc()) { AcDbLine *pLine=AcDbLine::cast(pEnt); AcGePoint2d StPt,EndPt; StPt.x=pLine->startPoint().x; StPt.y=pLine->startPoint().y; EndPt.x=pLine->endPoint().x; EndPt.y=pLine->endPoint().y; pLine->close(); AcGeLine2d GeLine(StPt,EndPt); double pama=0; if((GeLine.isOn(tempPt,pama)==Adesk::kTrue)&&pama<=1&&pama>=0) { Index=i; break; } else { if(GeLine.distanceTo(tempPt) { AcGeLine2d tempLine; GeLine.getPerpLine(tempPt,tempLine); AcGePoint2d InsertPt; GeLine.intersectWith(tempLine,InsertPt); double pama=0; if((GeLine.isOn(InsertPt,pama)==Adesk::kTrue)&&pama<=1&&pama>=0) { Distance=GeLine.distanceTo(tempPt); Index=i; } } } } pEnt->close(); } } int unionSolid(AcDbObjectId extrudeId,AcDb3dSolid *&pSolid) { //打开切弧实体 pExtrude AcDb3dSolid *pExtrude; if (Acad::eOk!=acdbOpenObject(pExtrude,extrudeId,AcDb::kForWrite)){ acutPrintf("/nError: Invalid extrude solid! "); if(pExtrude!=NULL) pExtrude->close(); return RTERROR; } if(pExtrude==NULL){ acutPrintf("/nError: Invalid extrude solid! "); return RTERROR; } // 实体 if(pSolid==NULL){ acutPrintf("/nError: Invalid extrude solid! "); return RTERROR; } //Unit if(Acad::eOk!=pSolid->booleanOper(AcDb::kBoolUnite,pExtrude)) { acutPrintf("/nError: substract error!"); pExtrude->close(); return RTERROR; } pExtrude->close(); return RTNORM; } Acad::ErrorStatus DyZoom(AcGePoint2d CenterPt,double Height,double Width) { Acad::ErrorStatus es; AcDbViewTableRecord *view=new AcDbViewTableRecord(); view->setCenterPoint(CenterPt); view->setFrontClipAtEye(false); view->setHeight(Height); view->setWidth(Width); es=acedSetCurrentView(view,NULL); view->close(); delete view; view=NULL; return es; } 创建circle和newlayer(加了错误检查的代码) Acad::ErrorStatus createCircle(AcDbObjectId& circleId) { circleId = AcDbObjectId::kNull; AcGePoint3d center(9.0,3.0,0.0); AcGeVector3d normal(0.0,0.0,0.1); AcDbCircle*pCirc=new AcDbCircle(center,normal,2.0); if(pCirc==NULL) return Acad::eOutOfMemory; AcDbBlockTable*pBlockTable; Acad::ErrorStatus es= acdbHostApplicationServices()->workingDatabase()-> getSymbolTable(pBlockTable,AcDb::kForRead); if(es!=Acad::eOk) { delete pCirc; return es; } AcDbBlockTableRecord*pBlockTableRecord; es=pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); if(es!=Acad::eOk){ Acad::ErrorStatus es2=pBlockTable->close(); if (es2!=Acad::eOk){ acrx_abort("/n应用程序X关闭边失败,错误码为:%d", acadErrorStatusText(es2)); } delete pCirc; return es; } es=pBlockTable->close(); if (es!=Acad::eOk) { acrx_abort("/n应用程序X关闭边失败,错误码为:%d", acadErrorStatusText(es)); } es=pBlockTableRecord->appendAcDbEntity(circleId,pCirc); if(es!=Acad::eOk){ Acad::ErrorStatus es2=pBlockTableRecord->close(); if (es2!=Acad::eOk){ acrx_abort("/n应用程序X关闭模型空间块表记录失败,错误码为:%s", acadErrorStatusText(es2)); } delete pCirc; return es; } es=pBlockTableRecord->close(); if(es!=Acad::eOk) { acrx_abort("/n应用程序X关闭模型空间块表记录失败,错误码为:%d", acadErrorStatusText(es)); } es=pCirc->close(); if(es!=Acad::eOk){ acrx_abort("/n应用程序X关闭实体失败,错误码为:%d", acadErrorStatusText(es)); } return es; } Acad::ErrorStatus createNewLayer() { AcDbLayerTableRecord*pLayerTableRecord=new AcDbLayerTableRecord; if (pLayerTableRecord==NULL) return Acad::eOutOfMemory; Acad::ErrorStatus es =pLayerTableRecord->setName("ASDK_MYLAYER"); if(es!=Acad::eOk) { delete pLayerTableRecord; return es; } AcDbLayerTable*pLayerTable; es=acdbHostApplicationServices()->workingDataBase()-> getSymbolTable(pLayerTable,AcDb::kForWrite); if(es!=Acad::eOk){ delete pLayerTableRecord; return es; } //由于先型对象ID的缺省直是0,不是有效的ID,必须将其设置为有效的ID, //即CONTINUOUS线型。其他数据成员都为有效缺省值,因此不须对其进行设置 AcDbLinetypeTable*pLinetypeTbl; es=acdbHostApplicationServices()->workingDatabase()-> getSymbolTable(pLinetypeTbl,AcDb::kForRead); if (es!=Acad::eOk){ delete pLayerTableRecord; es=pLayerTable->close(); if(es!=Acad::eOk){ acrx_abort("/n应用程序X关闭实体失败,错误码为:%d", acadErrorStatusText(es)); } return es; } AcDbObjectId ltypeobjId; es=pLinetypeTbl->getAt("CONTINUOUS",ltypeObjId); if (es!=Acad::eOk){ delete pLayerTableRecord; es=pLayerTable->close(); if (es!=Acad::eOk){ acrx_abort("/n应用程序X关闭实体失败,错误码为:%d",acadErrorStatusText(es)); } return es; } pLayerTableRecord->setLinetypeObjectId(ltypeObjId); es=pLayerTable->add(pLayerTableRecord); if (es!=Acad::eOk) { Acad::ErrorStatus es2=pLayerTable->close(); if (es2!=Acad::eOk) { acrx_abort("/n应用程序X关闭实体失败,错误码为:%d", acadErrorStatusText(es2)); } delete pLayerTableRecord; return es; } es=pLayerTable->close(); if(es!=Acad::eOk) { acrx_abort("/n应用程序X关闭实体失败,错误码为:%d", acadErrorStatusText(es)); } es=pLayerTableRecord->close(); if(es!=Acad::eOk) { acrx_abort("/n应用程序X关闭实体失败,错误码为:%d", acadErrorStatusText(es)); } return es; } Function name: setEntityElevation Parameters: ads_name, double Return value: False or True According to the Entity name setting the elevation value of text,polyline,2dpolyline,block,hatch which is given BOOL setEntityElevation(ads_name en, double elevation) { AcDbEntity* pEnt; AcDbObjectId eId; if(acdbGetObjectId(eId, en) != Acad::eOk) return FALSE; if(acdbOpenObject(pEnt,eId,AcDb::kForWrite) != Acad::eOk) return FALSE; if(!pEnt) { acutPrintf("/nFail to open Database!!"); return FALSE; } if(pEnt->isKindOf(AcDbPolyline::desc())) { ((AcDbPolyline*)pEnt)->setElevation(elevation); pEnt->close(); // Finished with the pEnt header. } else if(pEnt->isKindOf(AcDb2dPolyline::desc())) { ((AcDb2dPolyline*)pEnt)->setElevation(elevation); pEnt->close(); // Finished with the pEnt header. } else if(pEnt->isKindOf(AcDbText::desc())) { AcGePoint3d point3d; point3d = ((AcDbText*)pEnt)->position(); point3d[2] = elevation; ((AcDbText*)pEnt)->setPosition(point3d); pEnt->close(); // Finished with the pEnt header. } else if(pEnt->isKindOf(AcDbMText::desc())) { AcGePoint3d point3d; point3d = ((AcDbMText*)pEnt)->location(); point3d[2] = elevation; ((AcDbMText*)pEnt)->setLocation(point3d); pEnt->close(); // Finished with the pEnt header. } else if(pEnt->isKindOf(AcDbBlockReference::desc())) { AcGePoint3d point3d; point3d = ((AcDbBlockReference*)pEnt)->position(); point3d[2] = elevation; ((AcDbBlockReference*)pEnt)->setPosition(point3d); pEnt->close(); // Finished with the pEnt header. } else if(pEnt->isKindOf(AcDbShape::desc())) { AcGePoint3d point3d; point3d = ((AcDbShape*)pEnt)->position(); point3d[2] = elevation; ((AcDbShape*)pEnt)->setPosition(point3d); pEnt->close(); // Finished with the pEnt header. } else if(pEnt->isKindOf(AcDbHatch::desc())) { ((AcDbHatch*)pEnt)->setElevation(elevation); pEnt->close(); // Finished with the pEnt header. } else { pEnt->close(); return FALSE; } return TRUE; 读取CAD线型文件 class CLinetypeParam { public: CLinetypeParam(); CLinetypeParam(CString v_strName, CString v_strView); virtual ~CLinetypeParam(); public: CString m_strName; //线型名 CString m_strView; //线型描述 }; typedef CArray AryLinetype; BOOL CBaseInf:ReadLineTypeFile(AryLinetype &v_Param, CString v_strPath) { char szPath[MAX_PATH]; if (ads_findfile(v_strPath,szPath) != RTNORM) { ads_printf("Could not find file %s./n", v_strPath); return FALSE; } CLinetypeParam TempParam; TempParam.m_strName = _T("CONTINUOUS"); TempParam.m_strView = _T("_______________________________________"); //v_Param.Add(CLinetypeParam("CONTINUOUS", // "_______________________________________")); v_Param.Add(TempParam); CStdioFile DateFile; CFileException e; CString strTemp = _T(""); if( !DateFile.Open(szPath, CFile::modeRead, &e ) ) { ads_printf("Could not open file %s./n", v_strPath); return FALSE; } while(DateFile.ReadString(strTemp)) { int nSt = strTemp.Find('*'); int nMi = strTemp.Find(','); if(nSt != -1 && nSt != -1 && nSt < nMi) { CLinetypeParam TempParam; TempParam.m_strName = strTemp.Mid(nSt+1,nMi-nSt-1); TempParam.m_strView = strTemp.Mid(nMi+1); v_Param.Add(TempParam); } } DateFile.Close(); return TRUE; } 良好的使用Arx提供的几何类 void CGeoByArx::convertArc2Arc( AcGeCircArc3d*pGeArc, AcDbArc*&pDbArc ) { AcGePoint3d center = pGeArc->center(); AcGeVector3d normal = pGeArc->normal(); AcGeVector3d refVec = pGeArc->refVec(); AcGePlane plane = AcGePlane(center, normal); double ang = refVec.angleOnPlane(plane); pDbArc = new AcDbArc(center, normal, pGeArc->radius(),pGeArc->startAng() + ang, pGeArc->endAng() + ang ); } void CGeoByArx::convertArc2Arc( AcDbArc*pDbArc, AcGeCircArc3d*&pGeArc) { pGeArc = new AcGeCircArc3d( pDbArc->center(), pDbArc->normal(), pDbArc->no rmal().perpVector(), pDbArc->radius(), pDbArc->startAngle(), pDbArc->endAngle()); } 延高程三维实体切片[ARX程序] BOOL CSliceBody::DrawSliceBody(AcDbObjectIdArray& idArray) { AcDbEntity* pEnt=NULL; Acad::ErrorStatus es; double dMaxz(350),dMinz(300); double dHeight=5.0; //ads_printf("/n最高点高程为:%.2f/n最低点高程为:%.2f",dMaxz,dMinz); CString strTemp; strTemp.Format("/n请输入起始高程<%.2f>:",dMinz); if(ads_getreal(strTemp,&dMinz)!=RTCAN) { strTemp.Format("/n请输入终止高程<%.2f>:",dMaxz); if(ads_getreal(strTemp,&dMaxz)!=RTCAN) { strTemp.Format("/n请输入高程间距<%.2f>:",dHeight); if(ads_getreal(strTemp,&dHeight)!=RTCAN) { int nCount=0; CArray aryHeight; while (nCount*dHeight+dMinzisKindOf(AcDb3dSolid::desc()))//如果是Curve类 { /* double volume; AcGePoint3d centroid; double momInertia[3]; double prodInertia[3]; double prinMoments[3]; AcGeVector3d prinAxes[3]; double radiiGyration[3]; AcDbExtents extents; */ AcDb3dSolid* p3dSolid=NULL; p3dSolid=AcDb3dSolid::cast(pEnt); int nColor=1; if(p3dSolid!=NULL) { //p3dSolid->getMassProp(volume,centroid,momInertia,prodInertia, // prinMoments,prinAxes,radiiGyration,extents); for(int j=0;jgetSlice(plane,Adesk::kTrue,pNewSolid)==Acad::eOk) { if(pNewSolid!=NULL) { TURNCOLOR(nColor) pNewSolid->setColorIndex(nColor); CTszDwg::AddEntity(pNewSolid); pNewSolid->close(); } } } if(p3dSolid!=NULL) { TURNCOLOR(nColor) p3dSolid->setColorIndex(nColor); CTszDwg::AddEntity(p3dSolid); p3dSolid->close(); } } } pEnt->close(); } } } } return TRUE; } / // Cad颜色编辑框 // class CCadColorEdit : public CListCtrlEdit { // Construction public: CCadColorEdit(); // Attributes public: // Operations public: // Overrides // Clazard generated virtual function overrides //{{AFX_VIRTUAL(CCadColorEdit) //}}AFX_VIRTUAL // Implementation public: virtual ~CCadColorEdit(); private: CString m_Text; // Generated message map functions protected: CBrush m_Brush; COLORREF m_curColor; //{{AFX_MSG(CCadColorEdit) afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnPaint(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; class CLayerParam; // // Cad颜色编辑框 // CCadColorEdit::CCadColorEdit() { m_curColor=RGB(255,255,255); } CCadColorEdit::~CCadColorEdit() { } BEGIN_MESSAGE_MAP(CCadColorEdit, CListCtrlEdit) //{{AFX_MSG_MAP(CLayerCtrl) ON_WM_PAINT() ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CCadColorEdit::OnPaint() { CPaintDC dc(this); // device context for painting GetWindowText(m_Text); // Delete the old brush m_Brush.DeleteObject(); //m_Brush.CreateSolidBrush(RGB(255,255,255)); CDC* pDC = GetDC(); pDC->SetBkMode(TRANSPARENT); pDC->SetBkColor(RGB(255,255,255)); pDC->SelectObject(&m_Brush); CRect rc; GetClientRect(&rc); ScreenToClient(&rc); pDC->Rectangle(0, 0, rc.Width(), rc.Height()); m_Brush.CreateSolidBrush(m_curColor); pDC->SelectObject(&m_Brush); pDC->Rectangle(2, 3, 20, rc.Height()-3); pDC->SetTextColor(RGB(0, 0, 0)); pDC->TextOut(23, 0, m_Text.GetBuffer(m_Text.GetLength())); } void CCadColorEdit::OnLButtonDown(UINT nFlags, CPoint point) { // TOD Add your message handler code here and/or call default //CEdit::OnLButtonDown(nFlags, point); //acedSetColorDialog(int& nColor,Adesk::Boolean bAllowMetaColor, // int nCurLayerColor); int nColor; GetWindowText(m_Text); nColor=atoi(m_Text); if(acedSetColorDialog(nColor,FALSE,256)==IDOK) { m_Text.Format("%d",nColor); SetWindowText(m_Text); m_curColor=acdbGetRGB(nColor); } } AcDbDatabase* pDb=acdbCurDwg(); AcDbObjectId id1=AddTextStyle("jing6","宋体",pDb); AcDbObjectId id2=AddTextStyle("jing8","宋体",pDb); pDb->setTextstyle(id1); AcDbObjectId AddTextStyle(const char* strName,const char* strStype,AcDbDatabase* pDb) { AcDbObjectId idTextStyle=NULL; AcDbTextStyleTable *pTable=NULL; AcDbTextStyleTableRecord *pTableRecord; if (pDb==NULL) pDb=acdbCurDwg(); pDb->getTextStyleTable(pTable,AcDb::kForWrite); if(pTable==NULL) { AfxMessageBox("字体表打开错误"); return idTextStyle; } // 生成新的图层表记录 pTable->getAt(ACDB_MODEL_SPACE,pTableRecord,AcDb::kForWrite); if(pTable->has(strName)) { pTable->getAt(strName,idTextStyle); } else { pTableRecord=new AcDbTextStyleTableRecord; pTableRecord->setName(strName); pTableRecord->setFont(strStype,FALSE,FALSE,200,100); pTableRecord->setTextSize(3.0); pTable->add(idTextStyle,pTableRecord); pTableRecord->close(); } pTable->close(); return idTextStyle; } //程序功能:根据某一点求得其在直线上的垂直点 //输入参数:const AcGePoint3d v_ptStart 组成直线的起点 // const AcGePoint3d v_ptEnd 组成直线的终点 // const AcGePoint3d v_ptActive 要求的点 //返回参数:求得的垂点 AcGePoint3d CGeometry3D::GetUprightPoint(const AcGePoint3d v_ptStart, const AcGePoint3d v_ptEnd, const AcGePoint3d v_ptActive) { if(CGeometry3D::GetLength(v_ptStart,v_ptEnd)dLineSE||dM2>dLineSE) { if(fabs(dM1-dM2)>ZERO) { UpRightPt.x=(dM2*v_ptStart.x-dM1*v_ptEnd.x)/(dM2-dM1); UpRightPt.y=(dM2*v_ptStart.y-dM1*v_ptEnd.y)/(dM2-dM1); UpRightPt.z=(dM2*v_ptStart.z-dM1*v_ptEnd.z)/(dM2-dM1); } } else { if(fabs(dM1+dM2)>ZERO) { UpRightPt.x=(dM2*v_ptStart.x+dM1*v_ptEnd.x)/(dM1+dM2); UpRightPt.y=(dM2*v_ptStart.y+dM1*v_ptEnd.y)/(dM1+dM2); UpRightPt.z=(dM2*v_ptStart.z+dM1*v_ptEnd.z)/(dM1+dM2); } } return UpRightPt; } 如何获得程序路径 struct resbuf rb; char sTemp[1024],*str; ads_getvar("acadprefix",&rb); strcpy(sTemp,rb.resval.string); acad_free(rb.resval.rstring); str=strchr(sTemp,';'); *str='/0'; str=strrchr(sTemp,'//'); *str='/0'; 上段程序中,sTemp中存储了安装CAD的目录 AUTOCAD的系统变量存储了一些与安装有关的信息,虽然不多,在正常情况是够用的.与目录有关的主要有: dwgprefix 当前dwg图形存储的目录 acadprefix acad环境变量存储的目录 dwgname 当前dwg文件名 savefile 当前自动存储文件名 ///从RGB得到cad颜色索引值 int getNearestACI(COLORREF color) { long acirgb, r,g,b; long mindst = 2147483647L; long dst = 0; int minndx = 0; long red=GetRValue(color); long green=GetGValue(color); long blue=GetBValue(color); for ( int i = 1; i < 255; i++ ) { acirgb = acdbGetRGB ( i ); r =GetRValue(acirgb); g =GetGValue(acirgb); b =GetBValue(acirgb); dst = abs ( r-red) + abs ( g -green) + abs (b-blue); if ( dst < mindst ) { minndx = i; mindst = dst; } } return minndx; } //功 能:从CAD的颜色得到RGB COLORREF CGlobal::GetColorFromIndex(int colorIndex) { if(colorIndex < 0 || colorIndex > 255) { ads_alert("传入的颜色号不在0~255之间!"); return 0; } BYTE R, G, B; #ifdef ARX_2002_dll R = lpszRGBData[colorIndex*3+0]; G = lpszRGBData[colorIndex*3+1]; B = lpszRGBData[colorIndex*3+2]; #else long zhi = acdbGetRGB(colorIndex); WORD LOW = LOWORD(zhi); WORD HIG = HIWORD(zhi); R = LOBYTE(LOW); G = HIBYTE(LOW); B = LOBYTE(HIG); #endif return RGB(R,G,B); //return acdbGetRGB(nColor); } 获取AcDbDimension里的属性信息 AcDbEntity *pEnt; AcDbObjectId id; AcGePoint3d ptPick; ads_name eName; if (acedEntSel ("Select a dimension: " , eName, asDblArray (ptPick)) != RTNORM ) return; acdbGetObjectId (id, eName); acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead); //----- Get the id of the block table record which owns the text entity AcDbDimension *pDim =AcDbDimension::cast (pEnt); if (pDim == NULL) { pEnt->close (); return; } id =pDim->dimBlockId (); pDim->close (); AcDbBlockTableRecord *pr; acdbOpenAcDbObject ((AcDbObject *&) pr, id, AcDb::kForRead); //----- Iterating the block table record AcDbBlockTableRecordIterator *pi; pr->newIterator (pi); while (!pi->done ()) { pi->getEntity (pEnt, AcDb::kForRead); if (pEnt->isKindOf (AcDbMText::desc ())) { AcDbMText *pt = (AcDbMText *) pEnt; char *s = pt->contents (); acutPrintf (s); delete s; } pEnt->close(); pi->step(); } pr->close();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: 我不懂你在说什么,但是我可以告诉你有关arx和dxf文件的一些信息。Arx是AutoCAD的开发技术,它可以帮助您在AutoCAD中轻松地创建和管理实体。Dxf文件是一种专门用于AutoCAD的文件格式,它可以用来存储AutoCAD的几何图形和实体。要编写代码以批量插入dxf文件,您需要了解AutoCAD的API,并使用该API编写代码实现批量插入的功能。 ### 回答2: ARX是AutoCAD的应用程序接口,通过使用ARX,可以用C++开发插件程序,实现自动化操作和功能扩展。 实现ARX批量插入DXF文件的代码可以按照以下步骤进行编写: 1. 引入必要的头文件 首先,在代码中引入必要的头文件,包括包含AutoCAD的头文件和ARX编程的头文件。 2. 创建插入函数 创建一个函数,该函数用于批量插入DXF文件。函数可以定义如下: ```cpp void BatchInsertDxfFiles() { //定义一个DXF文件路径的数组,包含需要插入的所有DXF文件的路径 const char* dxfFiles[] = {"/path/to/dxf1.dxf", "/path/to/dxf2.dxf", "/path/to/dxf3.dxf"}; //获取当前数据库 acdbHostApplicationServices()->workingDatabase(); //开始事务处理 acdbTransactionManager->startTransaction(); //遍历DXF文件路径数组 for (int i = 0; i < sizeof(dxfFiles) / sizeof(dxfFiles[0]); i++) { //定义一个DXF文件路径 const char* dxfFilePath = dxfFiles[i]; //创建一个数据库对象,用于读取DXF文件 AcDbDatabase* sourceDb = new AcDbDatabase(false, true); //读取DXF文件 if (sourceDb->readDwgFile(dxfFilePath) != Acad::eOk) { acutPrintf("Failed to read DXF file: %s\n", dxfFilePath); continue; } //获取当前数据库对象的块表 AcDbBlockTable* blockTable = sourceDb->getBlockTable(); //获取模型空间的块表记录 AcDbBlockTableRecord* modelSpaceRecord; blockTable->getAt(ACDB_MODEL_SPACE, modelSpaceRecord, AcDb::kForRead); //获取当前数据库的块表 AcDbBlockTable* destBlockTable = acdbHostApplicationServices()->workingDatabase()->getBlockTable(); //将模型空间的块表记录复制到当前数据库的块表中 AcDbBlockTableRecord* destModelSpaceRecord; destBlockTable->getAt(ACDB_MODEL_SPACE, destModelSpaceRecord, AcDb::kForWrite); destModelSpaceRecord->deepCloneObjects(modelSpaceRecord->objectId(), destModelSpaceRecord->objectId()); //释放资源 delete sourceDb; modelSpaceRecord->close(); destModelSpaceRecord->close(); } //提交事务处理 acdbTransactionManager->endTransaction(); } ``` 3. 注册命令函数 在代码中注册函数为AutoCAD的命令函数,使得我们可以在AutoCAD的命令行中使用该命令。可以使用acedRegCmds命令进行注册,代码示例: ```cpp void initApp() { // ...省略部分代码... //注册命令函数 acedRegCmds->addCommand("MYCOMMANDS", "MYBATCHINSERTDXF", "BATCHINSERTDXF", ACRX_CMD_MODAL, BatchInsertDxfFiles); } void unloadApp() { // ...省略部分代码... //卸载命令函数 acedRegCmds->removeGroup("MYCOMMANDS"); } ``` 4. 编译、加载和运行 将编写的代码进行编译生成ARX插件,将插件加载到AutoCAD中,并输入命令“MYBATCHINSERTDXF”进行批量插入DXF文件的操作。 以上是一个使用ARX编写的批量插入DXF文件的代码示例,实现了通过ARX批量插入DXF文件的功能。具体的代码可以根据实际需求进行修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值