ARX 简单程序(不错的例子)

Posted mjgw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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<CLinetypeParam,CLinetypeParam> 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<double,double> aryHeight;
     while (nCount*dHeight+dMinz<dMaxz+ZERO)
     {
      aryHeight.Add(nCount*dHeight+dMinz);
      nCount++;
     }
     if(aryHeight.GetSize()<1)
      return FALSE;
   
     for(int i=0;i<idArray.length();i++)
     {
      es = acdbOpenAcDbEntity(pEnt, idArray.at(i), AcDb::kForWrite);
      if(es != Acad::eOk)
      {
       ads_printf("/nacdbOpenAcDbEntity错误");  
       return FALSE;
      }
      if (pEnt == NULL)
       continue;
    
      if(pEnt->isKindOf(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;j<aryHeight.GetSize();j++)
        {
         AcGePlane plane;
         plane.set(AcGePoint3d(0,0,aryHeight.GetAt(j)),AcGeVector3d(0,0,1));

         AcDb3dSolid* pNewSolid=NULL;
         if(p3dSolid->getSlice(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)<ZERO)
   return v_ptStart;
double dLineSt=CGeometry3D::GetLength(v_ptActive,v_ptStart);
double dLineEd=CGeometry3D::GetLength(v_ptActive,v_ptEnd);
double dLineSE=CGeometry3D::GetLength(v_ptStart,v_ptEnd);
double dS1=(dLineSt+dLineEd+dLineSE)/2.0;
double dS=dS1*(dS1-dLineSt)*(dS1-dLineEd)*(dS1-dLineSE);
LJSQR(dS)
   double dUpRight=dS*2.0/dLineSE;
double dM1=pow(dLineSt,2)-pow(dUpRight,2);
double dM2=pow(dLineEd,2)-pow(dUpRight,2);
LJSQR(dM1)
   LJSQR(dM2)
   AcGePoint3d UpRightPt;
if(dM1>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();
 

以上是关于ARX 简单程序(不错的例子)的主要内容,如果未能解决你的问题,请参考以下文章

cass9.1打开程序错误——加载arx失败

后缀“arx”的文件怎样打开或者编辑?

一个简单的 Serverless 架构例子

arx代码片段

AutoCAD二次开发(2020版)--4,使用ARX向导创建编程模板(框架)--

arx创建作用域(于)当前文档全局变量