C++ Programmer's Cookbook

{C++ 基础} {C++ 高级} {C#界面,C++核心算法} {设计模式} {C#基础}

arx & c++ 常用函数代码

 

1改变实体颜色

Acad::ErrorStatus
changeColor(AcDbObjectId entId, Adesk::UInt16 newColor)
{
    AcDbEntity 
*pEntity;
    acdbOpenObject(pEntity, entId,
        AcDb::kForWrite);

    pEntity
->setColorIndex(newColor);
    pEntity
->close();

    
return Acad::eOk;
}


2打开model空间
bool OpenWorkingModelSpace()
{
    Acad::ErrorStatus es ;
    AcDbBlockTable 
*pBlockTbl ;
    AcDbBlockTableRecord 
*pp ;
    
//AcDbObjectId pObjectid;

    
// Get the block table
    if ( (es =acdbHostApplicationServices ()->workingDatabase ()->getBlockTable (pBlockTbl, AcDb::kForRead)) != Acad::eOk )
    
{
        acutPrintf (
"\nCouldn't open the block table!") ;
        
return false;
    }

    
// Get the Model Space record and open it for read.
    if ( (es =pBlockTbl->getAt (ACDB_MODEL_SPACE, pp, AcDb::kForWrite)) != Acad::eOk )
    
{
        acutPrintf (
"\nCouldn't get Model Space! Drawing corrupt.\n") ;
        pBlockTbl
->close () ;
        
return  false;
    }

    pBlockTbl
->close ();
    
//pp即为model的指针
    
//使用pp
    pp->close();
    
return true;
}


3创建textstyle

bool CreateTextStyle()
{
    Acad::ErrorStatus es;
    AcDbTextStyleTable 
* pTextStyleTable;
    es
= acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pTextStyleTable, AcDb::kForWrite);
    
if (es != Acad::eOk) 
    
{
        delete pTextStyleTable;
        
return false;
    }

    
if(pTextStyleTable->has("textstyle name"))
    
{
        
//delete pTextStyleRecord;
        pTextStyleTable->close();
        
return true;
    }

    AcDbTextStyleTableRecord 
* pTextStyleRecord = new AcDbTextStyleTableRecord();
    
if (pTextStyleRecord == NULL)
        
return false;
    

     es 
= pTextStyleRecord->setName("Mytablestyle");
        
//es = pTextStyleRecord->setFont("@宋体",Adesk::kFalse,Adesk::kFalse,936,FIXED_PITCH );
       es = pTextStyleRecord->setBigFontFileName("gbcbig.shx");
       es 
= pTextStyleRecord->setFileName("txt.shx");
       
//es = pTextStyleRecord->setTextSize(2.2);
        
//设置属性
    if (es != Acad::eOk) 
    
{
        delete pTextStyleRecord;
        
return false;
    }

    es 
= pTextStyleTable->add(pTextStyleRecord);
    
if (es != Acad::eOk)
    
{
        acutPrintf(
"not add id");
        delete pTextStyleRecord;
        
return false;
    }

    pTextStyleTable
->close();
    pTextStyleRecord
->close();
   

    
return true;
}


4增加blockref到model

bool AddblockrefToModel()
{

    
if(pMS == NULL)
      
return false;
    AcDbBlockTable 
*pBlockTable ;
    AcDbObjectId pTitileBlockId;
    
// Open the block table for read
    Acad::ErrorStatus es ;
    
if ( (es =acdbHostApplicationServices ()->workingDatabase ()->getBlockTable (pBlockTable, AcDb::kForRead)) != Acad::eOk )
        
return false ;

    
if ( pBlockTable->getAt("xxx",pTitileBlockId) == Adesk::kTrue )
    
{    
        
return false ;
    }

    pBlockTable
->close ();

    
    AcDbBlockReference 
* pTitileBlockRef = new AcDbBlockReference(AcGePoint3d(xx ,yy,zz),pTitileBlockId);
    AcGeScale3d pscale(scale); 
    pTitileBlockRef
->setScaleFactors(pscale);
    
//设置属性
    
    pMS
->appendAcDbEntity(pTitileBlockRef);
    pTitileBlockRef
->close();

    
return true;
    
}

5遍历block中的属性 
//与遍历block中的实体相似
AcDbObjectIterator *pBlkRefAttItr=pBlkRef->attributeIterator();
for (pBlkRefAttItr->start(); !pBlkRefAttItr->done();pBlkRefAttItr->step())
{
AcDbObjectId attObjId;
attObjId 
= pBlkRefAttItr->objectId();

AcDbAttribute 
*pAtt = NULL;
Acad::ErrorStatus es 
= acdbOpenObject(pAtt, attObjId, AcDb::kForRead);
if (es != Acad::eOk) 
{
acutPrintf(
"\nFailed to open attribute");
delete pBlkRefAttItr;
continue;
}

if (strcmp(pAtt->tag(),"TITLE:"== 0)
{
CString title 
= pAtt->textString();
if (strcmp(title,"PROGRESS(D)"== 0)
//操作
}

else if (strcmp(title,"PROGRESS(P)"== 0)
{
//操作
}

}

pAtt
->close();
}

6公差标注设置函数:
void SetDimtpAndDimtm(double tp,double tm)
{
AcDbDimStyleTable 
*pDimStyleTbl;
acdbCurDwg()
->getDimStyleTable(pDimStyleTbl,AcDb::kForRead);
AcDbDimStyleTableRecord 
*pDimStyleTblRcd;
pDimStyleTbl
->getAt("",pDimStyleTblRcd,AcDb::kForWrite);
if (fabs(tp) == fabs(tm))
{
pDimStyleTblRcd
->setDimtfac(1.0)
}

else pDimStyleTblRcd->setDimtfac(0.5);
if (tp == 0.0 && tm == 0.0)
{
pDimStyleTblRcd
->setDimtol(0);
}

else
{
pDimStyleTblRcd
->setDimtp(tp);
pDimStyleTblRcd
->setDimtol(1);
pDimStyleTblRcd
->setDimtm(tm);
}

pDimStyleTblRcd
->close();
pDimStyleTbl
->close();
}

posted on 2006-02-08 14:08 梦在天涯 阅读(2265) 评论(1)  编辑 收藏 引用 所属分类: ARX/DBX

评论

# re: arx & c++ 常用函数代码 2006-02-17 09:03 梦在天涯

Finding the Active Viewports in Model Space

// Set some viewport information.
AcDbViewportTable* pViewportTable;
if (db.getViewportTable(pViewportTable, AcDb::kForRead)
== Acad::eOk)
{
// Find the first viewport and open it for write.
AcDbViewportTableRecord *pRecord;
if (pViewportTable->getAt(
"*ACTIVE", pRecord,
AcDb::kForWrite) == Acad::eOk)
{
pRecord->setCenterPoint(AcGePoint2d(0.5, 0.5));
pRecord->setHeight(1.0);
pRecord->setWidth(1.0);
pRecord->close();
}
pViewportTable->close();
}
  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


公告

EMail:itech001#126.com

导航

统计

  • 随笔 - 461
  • 文章 - 4
  • 评论 - 746
  • 引用 - 0

常用链接

随笔分类

随笔档案

收藏夹

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

积分与排名

  • 积分 - 1796270
  • 排名 - 5

最新评论

阅读排行榜