zoukankan      html  css  js  c++  java
  • ObjectARX代码片段一

    转载自网络

    Finding the Active Viewports in Model Space 

     1 // Set some viewport information. 
     2 AcDbViewportTable* pViewportTable; 
     3 if (db.getViewportTable(pViewportTable, AcDb::kForRead) 
     4     == Acad::eOk) 
     5 { 
     6     // Find the first viewport and open it for write. 
     7     AcDbViewportTableRecord *pRecord; 
     8     if (pViewportTable->getAt( 
     9         "*ACTIVE", pRecord, 
    10         AcDb::kForWrite) == Acad::eOk) 
    11     { 
    12         pRecord->setCenterPoint(AcGePoint2d(0.5, 0.5)); 
    13         pRecord->setHeight(1.0); 
    14         pRecord->setWidth(1.0); 
    15         pRecord->close(); 
    16     } 
    17     pViewportTable->close(); 
    18 } 

    1改变实体颜色

     1 Acad::ErrorStatus changeColor(AcDbObjectId entId, Adesk::UInt16 newColor)
     2 {
     3     AcDbEntity *pEntity;
     4     acdbOpenObject(pEntity, entId,
     5         AcDb::kForWrite);
     6 
     7     pEntity->setColorIndex(newColor);
     8     pEntity->close();
     9 
    10     return Acad::eOk;
    11 }

    2打开model空间

     1 bool OpenWorkingModelSpace()
     2 {
     3     Acad::ErrorStatus es ;
     4     AcDbBlockTable *pBlockTbl ;
     5     AcDbBlockTableRecord *pp ;
     6     //AcDbObjectId pObjectid;
     7 
     8     // Get the block table
     9     if ( (es =acdbHostApplicationServices ()->workingDatabase ()->getBlockTable (pBlockTbl, AcDb::kForRead)) != Acad::eOk )
    10     {
    11         acutPrintf ("\nCouldn't open the block table!") ;
    12         return false;
    13     }
    14     // Get the Model Space record and open it for read.
    15     if ( (es =pBlockTbl->getAt (ACDB_MODEL_SPACE, pp, AcDb::kForWrite)) != Acad::eOk )
    16     {
    17         acutPrintf ("\nCouldn't get Model Space! Drawing corrupt.\n") ;
    18         pBlockTbl->close () ;
    19         return  false;
    20     }
    21     pBlockTbl->close ();
    22     //pp即为model的指针
    23     //使用pp
    24     pp->close();
    25     return true;
    26 }

    3创建textstyle

     1 bool CreateTextStyle()
     2 {
     3     Acad::ErrorStatus es;
     4     AcDbTextStyleTable * pTextStyleTable;
     5     es= acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pTextStyleTable, AcDb::kForWrite);
     6     if (es != Acad::eOk) 
     7     {
     8         delete pTextStyleTable;
     9         return false;
    10     }
    11     if(pTextStyleTable->has("textstyle name"))
    12     {
    13         //delete pTextStyleRecord;
    14         pTextStyleTable->close();
    15         return true;
    16     }
    17     AcDbTextStyleTableRecord * pTextStyleRecord = new AcDbTextStyleTableRecord();
    18     if (pTextStyleRecord == NULL)
    19         return false;
    20 
    21 
    22     es = pTextStyleRecord->setName("Mytablestyle");
    23     //es = pTextStyleRecord->setFont("@宋体",Adesk::kFalse,Adesk::kFalse,936,FIXED_PITCH );
    24     es = pTextStyleRecord->setBigFontFileName("gbcbig.shx");
    25     es = pTextStyleRecord->setFileName("txt.shx");
    26     //es = pTextStyleRecord->setTextSize(2.2);
    27     //设置属性
    28     if (es != Acad::eOk) 
    29     {
    30         delete pTextStyleRecord;
    31         return false;
    32     }
    33     es = pTextStyleTable->add(pTextStyleRecord);
    34     if (es != Acad::eOk)
    35     {
    36         acutPrintf("not add id");
    37         delete pTextStyleRecord;
    38         return false;
    39     }
    40     pTextStyleTable->close();
    41     pTextStyleRecord->close();
    42 
    43 
    44     return true;
    45 }

    4增加blockref到model

     1 bool AddblockrefToModel()
     2 {
     3     if(pMS == NULL)
     4         return false;
     5     AcDbBlockTable *pBlockTable ;
     6     AcDbObjectId pTitileBlockId;
     7     // Open the block table for read
     8     Acad::ErrorStatus es ;
     9     if ( (es =acdbHostApplicationServices ()->workingDatabase ()->getBlockTable (pBlockTable, AcDb::kForRead)) != Acad::eOk )
    10         return false ;
    11 
    12     if ( pBlockTable->getAt("xxx",pTitileBlockId) == Adesk::kTrue )
    13     {    
    14         return false ;
    15     }
    16     pBlockTable->close ();
    17 
    18 
    19     AcDbBlockReference * pTitileBlockRef = new AcDbBlockReference(AcGePoint3d(xx ,yy,zz),pTitileBlockId);
    20     AcGeScale3d pscale(scale); 
    21     pTitileBlockRef->setScaleFactors(pscale);
    22     //设置属性
    23 
    24     pMS->appendAcDbEntity(pTitileBlockRef);
    25     pTitileBlockRef->close();
    26 
    27     return true;
    28 }

    5遍历block中的属性 //与遍历block中的实体相似

     1 AcDbObjectIterator *pBlkRefAttItr=pBlkRef->attributeIterator();
     2 for (pBlkRefAttItr->start(); !pBlkRefAttItr->done();pBlkRefAttItr->step())
     3 {
     4     AcDbObjectId attObjId;
     5     attObjId = pBlkRefAttItr->objectId();
     6 
     7     AcDbAttribute *pAtt = NULL;
     8     Acad::ErrorStatus es = acdbOpenObject(pAtt, attObjId, AcDb::kForRead);
     9     if (es != Acad::eOk) 
    10     {
    11         acutPrintf("\nFailed to open attribute");
    12         delete pBlkRefAttItr;
    13         continue;
    14     }
    15     if (strcmp(pAtt->tag(),"TITLE:") == 0)
    16     {
    17         CString title = pAtt->textString();
    18         if (strcmp(title,"PROGRESS(D)") == 0)
    19         { //操作
    20         }
    21         else if (strcmp(title,"PROGRESS(P)") == 0)
    22         {
    23             //操作
    24         }
    25     }
    26     pAtt->close();
    27 }

    6公差标注设置函数:

     1 void SetDimtpAndDimtm(double tp,double tm)
     2 {
     3     AcDbDimStyleTable *pDimStyleTbl;
     4     acdbCurDwg()->getDimStyleTable(pDimStyleTbl,AcDb::kForRead);
     5     AcDbDimStyleTableRecord *pDimStyleTblRcd;
     6     pDimStyleTbl->getAt("",pDimStyleTblRcd,AcDb::kForWrite);
     7     if (fabs(tp) == fabs(tm))
     8     {
     9         pDimStyleTblRcd->setDimtfac(1.0)
    10     }
    11     else pDimStyleTblRcd->setDimtfac(0.5);
    12     if (tp == 0.0 && tm == 0.0)
    13     {
    14         pDimStyleTblRcd->setDimtol(0);
    15     }
    16     else
    17     {
    18         pDimStyleTblRcd->setDimtp(tp);
    19         pDimStyleTblRcd->setDimtol(1);
    20         pDimStyleTblRcd->setDimtm(tm);
    21     }
    22     pDimStyleTblRcd->close();
    23     pDimStyleTbl->close();
    24 }
  • 相关阅读:
    php数组的创建及操作
    继承的几种方式
    js对象的创建与原型总结
    对象的创建
    变量与内存
    js函数的几个特殊点
    正则表达式的几个简单验证
    数组排序sort()
    对象与数组
    js函数动态传参
  • 原文地址:https://www.cnblogs.com/lzx838/p/2631931.html
Copyright © 2011-2022 走看看