Arx函数收集

 

//获取文件名

int
getFile(
    // input:
    const char* pCmdAsk,  // prompt for command line mode
    const char* pDiaAsk,  // prompt for dialog box mode
    const char* pExt,     // file extension
    // output:
    char* pResult)        // selected file returned to the caller.
                          // must be an allocated buffer!
{
    char tmpResult[134];
    struct resbuf *pRb = NULL;
    int res = RTERROR;
    char drive[_MAX_DRIVE], dir[_MAX_DIR];
    char fname[_MAX_FNAME], ext[_MAX_EXT];

    // command line argument?
    //
    if ( NULL != (pRb = acedGetArgs()) && RTSTR == pRb->restype) {
        // yes!
        //
        strcpy( tmpResult, pRb->resval.rstring );
        // continue later: look if acedFindFile finds the file!
        //
        res = RTNORM;
    }
    else {
        // no command line argument
        //
        struct resbuf fileDia;

        // is "filedia" set to 1?
        //
        acedGetVar( "filedia", &fileDia );
        if (1 == fileDia.resval.rint) {
            // yes, display dialog box
            //
            struct resbuf fileRes;

            res = acedGetFileD( pDiaAsk, NULL, pExt, 0, &fileRes );
            if (RTNORM != res) return res;
            if (RTSTR == fileRes.restype) {
                // user selected valid file
                //
                strcpy( pResult, fileRes.resval.rstring );
                free( fileRes.resval.rstring );
                return RTNORM;
            }
        }
        // Prompt at command line required. Either
        // filedia = 0, or "type it" button in dialog was pressed.
        //
        res = acedGetString( 0, pCmdAsk, tmpResult );
        if (RTNORM != res) return res;
    }
    // look if there's already the file extension attached
    //
    _splitpath( tmpResult, drive, dir, fname, ext );
    // if not, append file extension
    //
    if (stricmp( ext, pExt ) != 0)
        _makepath( tmpResult, drive, dir, fname, pExt );

    // look if file exists (only if not in dialog mode)
    //
    res = acedFindFile( tmpResult, pResult );
    if (RTNORM != res)
        acutPrintf( "/nUnable to open %s./n", tmpResult );
    return res;
}

 

例子:  char dwgName[_MAX_PATH];

    if (RTNORM != getFile( "Enter DWG name", "Select Drawing", "dwg",
                           dwgName ))
    {
        return;
    }

——————————————————————————————————————————————

 

// 从dwg文件中拷贝所有图块定义至当前文档中,
// 符号库: 可以用一个dwg文件存储多个符号块定义.
void
CopyBlockTableRecordFromDwgFile(LPCTSTR dwgFile)
{
    Acad::ErrorStatus es;
    AcDbDatabase *db = acdbHostApplicationServices()->workingDatabase();

    ASSERT(dwgFile.CompareNoCase("") != 0);

   if
(FileExists(dwgFile) == TRUE) {
       AcDbDatabase *pDb = new
AcDbDatabase(Adesk::kFalse);
       es = pDb->readDwgFile(dwgFile);
      if
(es != Acad::eOk) {
          acutPrintf("Failed to reading dwg.Error:%d/n",es);
         return
;
       }
       AcDbBlockTable* pBT;
       es = pDb->getSymbolTable(pBT,AcDb::kForRead);
      if
(es != Acad::eOk) {
          acutPrintf("Error getting BlockTable of dwg.Error:%d/n",es);
         return
;
       }

       AcDbObjectId objId;
       AcDbObjectIdArray objIdArray;

       AcDbBlockTableIterator *pIT;
       es = pBT->newIterator(pIT);
      if
(es != Acad::eOk) {
          acutPrintf("Error iterating block table.Error:%d/n",es);
         return
;
       }

      for
(; !pIT->done(); pIT->step()) { 
          es = pIT->getRecordId(objId);
         if
(es == Acad::eOk) {
             objIdArray.append(objId);
          }
       }
      delete
pIT;
       pBT->close();

      
//
       AcDbObjectId destBlkId;
       destBlkId = db->currentSpaceId();

       AcDbIdMapping idMap;
       idMap.setDestDb(db);

       es = db->wblockCloneObjects(objIdArray,destBlkId,idMap,AcDb::kDrcIgnore);
      if
(es != Acad::eOk) {
          acutPrintf("Failed wblockCloneObjects.Error:%d/n",es);
         return
;
       }

      delete
pDb;
    }
}

——————————————————————————————————————————————
DXF读取函数
LPCTSTR bytesToHexStr(char* buffer, int len, CString& hexStr)
{
    unsigned char k;
    int j;
    CString tmpStr;
 
    hexStr.Empty();    // make sure nothing in it yet since we are concatenating it
 
    for (j=0;j<len;j++) {
        k = static_cast<unsigned char>(buffer[j]);
        tmpStr.Format(_T("%02hX"), k);
        hexStr += tmpStr;
    }
    return hexStr;
}
int dxfCodeToDataType(int resType)
{
 // which data type is this value
    if ((resType >= 0) && (resType <= 9))
        return RTSTR;
    else if ((resType >= 10) && (resType <= 17))
        return RT3DPOINT;
    else if ((resType >= 38) && (resType <= 59))
        return RTREAL;
    else if ((resType >= 60) && (resType <= 79))
        return RTSHORT;
    else if ((resType >= 90) && (resType <= 99))
        return RTLONG;
    else if ((resType == 100) || (resType == 101) || (resType == 102) ||(resType == 105))
        return RTSTR;
 else if ((resType >= 110) && (resType <= 112))
  return RTSTR;
    else if ((resType >= 140) && (resType <= 149))
        return RTREAL;
    else if ((resType >= 170) && (resType <= 179))
        return RTSHORT;
    else if ((resType >= 210) && (resType <= 219))
        return RT3DPOINT;
    else if ((resType >= 270) && (resType <= 299))
        return RTSHORT;
    else if ((resType >= 300) && (resType <= 309))
        return RTSTR;
    else if ((resType >= 310) && (resType <= 369))
        return RTENAME;
    else if ((resType >= 370) && (resType <= 379))
        return RTSHORT;
    else if ((resType >= 380) && (resType <= 389))
        return RTSHORT;
    else if ((resType >= 390) && (resType <= 399))
        return RTENAME;
    else if ((resType >= 400) && (resType <= 409))
        return RTSHORT;
    else if ((resType >= 410) && (resType <= 419))
        return RTSTR;
    else if (resType == 1004)
        return resType;        // binary chunk
    else if ((resType >= 999) && (resType <= 1009))
        return RTSTR;
    else if ((resType >= 1010) && (resType <= 1013))
        return RT3DPOINT;
    else if ((resType >= 1038) && (resType <= 1059))
        return RTREAL;
    else if ((resType >= 1060) && (resType <= 1070))
        return RTSHORT;
    else if ((resType == 1071))
        return RTLONG;
    else if ((resType < 0) || (resType > 4999))
        return resType;
    else
        return RTNONE;
}
void dxfToStr(const resbuf* rb, CString& dxfCodeStr, CString& valueStr)
{
    int dataType = dxfCodeToDataType(rb->restype);
    dxfCodeStr.Format(_T("%d"), rb->restype);
 
    CString tmpStr;
 
    switch (dataType) {
 case RTSHORT:
  valueStr.Format(_T("%d"), rb->resval.rint);
  break;
 case RTLONG:
  valueStr.Format(_T("%ld"), rb->resval.rlong);
  break;
 case RTREAL:
  valueStr.Format(_T("%g"), rb->resval.rreal);
  break;
 case RTSTR:
  if (rb->resval.rstring == NULL)
   valueStr = _T("(NULL)");
  else
   valueStr.Format(_T("/"%s/""), rb->resval.rstring);
  break;
 case RT3DPOINT:
  valueStr.Format(_T("(%g, %g, %g)"), rb->resval.rpoint[X],
   rb->resval.rpoint[Y], rb->resval.rpoint[Z]);
  break;
 case RTPOINT:
  valueStr.Format(_T("(%g, %g)"), rb->resval.rpoint[X], rb->resval.rpoint[Y]);
  break;
 case 1004:
  valueStr.Format(_T("Binary Chunk: /"%s/""),
   bytesToHexStr(rb->resval.rbinary.buf,
   rb->resval.rbinary.clen, tmpStr));
  break;
 case -6:
  valueStr = _T("Extension Dictionary");
  break;
 case -5:
  valueStr = _T("Persistent Reactors");
  break;
 case -4:
  valueStr.Format(_T("Conditional Operator: /"%s/""), rb->resval.rstring);
  break;
 case -3:
  valueStr = _T("Start of Xdata");
  break;
 case -2:
  valueStr.Format(_T("<Entity Name Reference: %8lx>"), rb->resval.rlname[0]);
  break;
 case -1:
 case RTENAME:
  if ((rb->restype >= 330 )&& (rb->restype < 340))
   valueStr.Format(_T("<Soft Pointer: %8lx>"), rb->resval.rlname[0]);
  else if((rb->restype >= 340) && (rb->restype < 350))
   valueStr.Format(_T("<Hard Pointer: %8lx>"), rb->resval.rlname[0]);
  else if((rb->restype >= 350) && (rb->restype < 360))
   valueStr.Format(_T("<Soft Ownership: %8lx>"), rb->resval.rlname[0]);
  else if((rb->restype >= 360) && (rb->restype < 370))
   valueStr.Format(_T("<Hard Ownership: %8lx>"), rb->resval.rlname[0]);
  else if((rb->restype >= 390) && (rb->restype < 399))
   valueStr.Format(_T("<Hard Pointer: %8lx>"), rb->resval.rlname[0]);
  else
   valueStr.Format(_T("<Entity Name: %8lx>"), rb->resval.rlname[0]);
  break;
 case RTPICKS:
  valueStr.Format(_T("<Selection Set: %8lx>"), rb->resval.rlname[0]);
  break;
 case RTLB:
  valueStr = _T("List Begin");
  break;
 case RTLE:
  valueStr = _T("List End");
  break;
 case RTNIL:
  valueStr = _T("NIL");
  break;
 case RTT:
  valueStr = _T("T");
  break;
 default:
  valueStr = _T("*Unknown*");
  break;
    }
}
——————————————————————————————————————————————
设置获取系统变量 acedsetvar/acedgetvar
——————————————————————————————————————————————
acad的窗口缩放效果,类似VBA的ZoomWindow
void asdkzoomExt()
{
 // get the extents of the drawing
 AcDbViewTableRecord view;
 AcGePoint3d max =acdbHostApplicationServices()->workingDatabase()->extmax(),
          min = acdbHostApplicationServices()->workingDatabase()->extmin();
 
 AcGePoint2d max_2d (max[X], max[Y]);
 AcGePoint2d min_2d (min[X], min[Y]);
 // now set the view centre point
 view.setCenterPoint (min_2d + (max_2d - min_2d) / 2.0);
 // now height and width of view
 view.setHeight(max_2d[Y] - min_2d[Y]);
 view.setWidth (max_2d[X] - min_2d[X]);
 // set the view
 acedSetCurrentView (&view, NULL);
 // updates the extents
 acdbHostApplicationServices()->workingDatabase()->updateExt(TRUE);
}

//
// This is command 'ZOOMWIN, by Fenton Webb [Apr/17/2002], DevTech, Autodesk
void asdkzoomWin()
{
 AcGePoint3d max, min;
 // get the window coords
 int res = acedGetPoint (NULL, "/nPick zoom window pnt : ",asDblArray(min));
 // if ok
 if (res == RTNORM)
 {
  res = acedGetCorner (asDblArray(min), "/nPick other corner : ",
   asDblArray(max));
  // get the extents of the drawing
  AcDbViewTableRecord view;
  
  AcGePoint2d max_2d (max[X], max[Y]);
  AcGePoint2d min_2d (min[X], min[Y]);
  // now set the view centre point
  view.setCenterPoint (min_2d + (max_2d - min_2d) / 2.0);
  // now height and width of view
  view.setHeight(max_2d[Y] - min_2d[Y]);
  view.setWidth (max_2d[X] - min_2d[X]);
  // set the view
  acedSetCurrentView (&view, NULL);
  // updates the extents
  acdbHostApplicationServices()->workingDatabase()->updateExt(TRUE);
 }
}
——————————————————————————————————————————————
调用acad标准对话框
线型选择
 AcDbObjectId new_linetypeId;
 char * new_linetypename = NULL;
 if (acedLinetypeDialog(acdbCurDwg()->celtype(),true,new_linetypename,new_linetypeId) && new_linetypename) {
  acutPrintf("/nLinetype selected: %s",new_linetypename);
  free(new_linetypename);
 } else {
  acutPrintf("/nLinetype not selected!");
 }
线宽选择
 AcDb::LineWeight w;
 acedLineWeightDialog(AcDb::LineWeight::kLnWt000,false,w);
颜色选择
acedSetColorDialog(i,TRUE,256);
——————————————————————————————————————————————
 函数名:         setView
功能:           设置视图(相当于Zoom Window命令)  
输入参数:       Pt1 -- 视图左上角点
          Pt2 -- 视图右下角点
          ex_ratio -- 扩展比率,一般为1.0
输出参数:  
返回值:         void
其它:  
*****************************************************************/
void setView(AcGePoint2d Pt1, AcGePoint2d Pt2, double ex_ratio)
{
AcGePoint2d CenterPt;

//若X坐标或Y坐标重合,判为意外,不进行SetView操作
if ((fabs(Pt1.x-Pt2.x)<1e-6)||(fabs(Pt1.y-Pt2.y)<1e-6))
return;

//确保两个坐标点分别为左上角和右下角
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;
}

//获取当前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;
}

//设置当前视图中心点
CenterPt.x = (Pt1.x+Pt2.x)/2;
CenterPt.y = (Pt1.y+Pt2.y)/2;

//改变当前视图
AcDbViewTableRecord pVwRec;
pVwRec.setCenterPoint(CenterPt);
pVwRec.setWidth(width * ex_ratio);
pVwRec.setHeight(height * ex_ratio);
acedSetCurrentView( &pVwRec, NULL );
}

///
//    函 数 名 : oxaGetVar
//    函数功能 :
//    处理过程 :
//    备   注 :
//    作   者 : user
//    时   间 : 2004年6月16日
//    返 回 值 : int
//    参数说明 : 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
//# 函数名称: oxaGetVar
//# 函数编号: OXA
//# 函数声明:
//# 函数参数: const CString strSym,
//                 int &vOut
//# 返回值:   int
//# 函数分类:
//# 函数功能: 获取系统变量, 封装acedGetVar()
//# 注意事项:
//# 涉及的全局变量:
//# 调用的OXARX函数:
//# 函数算法:
//# ACAD版本:R14 R15 R16
//# 配合函数:
//# 类似函数:
//# 替换函数:
//# 现存缺陷:
//# 示例程序:
//# 测试要求:
//# 历史记录: 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
//# 函数名称: oxaGetVar
//# 函数编号: OXA
//# 函数声明:
//# 函数参数: const CString strSym,
//                 double &vOut
//# 返回值:   int
//# 函数分类:
//# 函数功能: 获取系统变量, 封装acedGetVar()
//# 注意事项:
//# 涉及的全局变量:
//# 调用的OXARX函数:
//# 函数算法:
//# ACAD版本:R14 R15 R16
//# 配合函数:
//# 类似函数:
//# 替换函数:
//# 现存缺陷:
//# 示例程序:
//# 测试要求:
//# 历史记录: 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
//# 函数名称: oxaGetVar
//# 函数编号: OXA
//# 函数声明:
//# 函数参数: const CString strSym,
//                 CString &vOut
//# 返回值:   int
//# 函数分类:
//# 函数功能:获取系统变量, 封装acedGetVar()
//# 注意事项:
//# 涉及的全局变量:
//# 调用的OXARX函数:
//# 函数算法:
//# ACAD版本:R14 R15 R16
//# 配合函数:
//# 类似函数:
//# 替换函数:
//# 现存缺陷:
//# 示例程序:
//# 测试要求:
//# 历史记录: 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;
}
// 函数名   : SetCurTextStyle
// 描述     : 设置当前TextStyle
// 返回     : Acad::ErrorStatus
// 参数       : const char* lpStyleName
// 参数       : 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
// Descrīption     : 设置当前层
// 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;
}
//获取属性块中所有属性的字符串值,并且存于链表中

CODE:

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();

}

//检测AutoCAD是否已经运行

CODE:

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();
}

//计算多边形的形心坐标
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折线不封闭, 无法形成正确的区域。");
return FALSE;
}
curveSegments.append((AcDbCurve *) pPline);

if (AcDbRegion::createFromCurves(curveSegments, regions) != Acad::eOk){
ads_printf("\n创建临时区域对象失败!");
//清除Region, 应第9 贴的指点,即使createFromCurves错误,也应清除之;
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创建临时区域对象为空!");
return FALSE;
}
if (iCount > 1){
// 多个 AcDbRegion , 无法确定应该返回哪一个,干脆返回NULL;
ads_printf("\n多个区域实体。");
for(i = 0; i < iCount; i++)
delete (AcDbRegion *)regions.at(i);
return FALSE;
}
pRegion = (AcDbRegion *) regions.at(0);

origin.set(0,0,0); //设置原点坐标
xAxis.set(1,0,0); //设置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区域面积: %.3f, 周长:%.3f", area, perimeter);
ads_printf("\n获取区域对象属性失败!");
delete pRegion;
return FALSE;
}
XYZ_POINT(CenPt, centroid.x, centroid.y, 0); //得到形心坐标
ads_printf("\n区域面积: %.3f, 周长:%.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;

}

objectARX 常用功能实现集合

一 在ARX中禁用AutoCAD的某个命令
以LINE命令为例,在程序中加入下面的一句即可禁用LINE命令:

acedCommand(RTSTR, "undefine", RTSTR, "line",RTNONE);

下面的语句则可恢复LINE命令的定义:

acedCommand(RTSTR, "redefine", RTSTR, "line",RTNONE);

二 在对话框中预览DWG文件
使用acdbDisplayPreviewFromDwg函数,具体的方法为:
char fileName[100];
strcpy(fileName, "C:\\test.dwg");
bool es;
HWND pWnd;
CFrameWnd *pFrame = (CFrameWnd*)GetDlgItem(IDC_PICTURE);

es = acdbDisplayPreviewFromDwg(fileName, pFrame->m_hWnd);
上面的代码将在一个Picture控件中显示指定的图形。
另外,需要包含“dbmain.h”头文件。

三 通过ARX更改AutoCAD窗口的标题名称
CMDIFrameWnd *pp;
pp=acedGetAcadFrame();
pp->SetWindowText ("yourName");
pp->UpdateWindow ();

四 获得当前数据库
在ARX编程中,经常需要使用当前数据库,例如需要获得当前图形中设置的文字样式、标注样式等。
要获得当前数据库,都可以直接使用下面的方法:
AcDbTextStyleTable *pTextStyleTAble;
AcDbObjectId textstyleId;
textstyleId=acdbHostApplicationServices()->workingDatabase()->textstyle();
如果用acadCurDwg来代替acdbHostApplicationServices()->workingDatabase(),也能得到同样的结果。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值