创建时间:2013/11/279:06:00一、CAD版本和VC++的版本对应......................................................................................2二、ObjectARX实体创建...............................................................................................................2三、创建直线实例...................................................................................................................2五、修改图形对象的属性...............................................................................................................31、打开图形数据库的对象.....................................................................................................32、修改直线颜色实例.............................................................................................................4六、用类组织函数...........................................................................................................................5七、提高CreateLine函数的可重用性...........................................................................................9八、升级VisualStudio试用版到正式版.....................................................................................13九、创建圆.....................................................................................................................................14十、创建圆弧(“三点法”,“起点、圆心、终点法”,“起点、圆心、圆弧角度法”)........................................................................................................................................................19//添加计算常量的值的函数.............................................................................................21十一、创建多段线.........................................................................................................................24十二、创建正多边形.....................................................................................................................26创建时间:2013/11/279:06:00一、CAD版本和VC++的版本对应AutoCADVisualStudio2000——2002VC6.02004——2006VC7.0(VC.NET2002)2007——2009VC8.0(VC2005)2010——1012VC20082013——2014VC2010二、ObjectARX实体创建1、注册一条直线命令2、在命令函数中添加创建直线对象函数(AcDbLine类)AcGePoint3dptStart();AcGePoint3dptEnd();AcDbLine*pLine=newAcDbLine(ptStart,ptEnd);3在命令函数中添加获得指向块表的指针相关代码AcDbBlockeTable*pBlockTable;acdbHostApplicationServices()-WorkingDataBase()-getBlockTable(pBlockTable,AcDb::kForRead);4、在命令函数中添加获得指向特定块表记录的指针的相关代码AcDbBlockTableRecord*pBlockTableRecord;pBlockTable-getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);5、在命令函数中添加向块表记录中附加实体代码AcDbObjectIdlineId;pBlockTabelRecord-appendAcDbEntity(lineId,pLine);6、在命令函数中添加关闭图形数据库各种对象的代码pBlockTable-close();pBlockTableRecord-close();pLine-close();三、创建直线实例创建时间:2013/11/279:06:00四、五、修改图形对象的属性1、打开图形数据库的对象Acad::ErrorStatusacdbOpenAcDbEntity(AcDbEntity*&pEnt,AcDbObjectIdid,AcDb::Openmodemode,boolopenErasedEntity=false);第一个参数返回值指向图形数据库实体的指针;第二个参数输入了要获得的实体的ID号,第三个参数指定了打开该实体的方式(读或写);第四个参数指定是否允许访问一个已经被删除的实体。创建时间:2013/11/279:06:002、修改直线颜色实例staticAcDbObjectIdCreatLine(){//在内存上创建一个新的AcDbLine对象AcGePoint3dptStart(0,0,0);AcGePoint3dptEnd(100,100,0);AcDbLine*pLine=newAcDbLine(ptStart,ptEnd);//获得指向块表的指针AcDbBlockTable*pBlockTable;acdbHostApplicationServices()-workingDatabase()-getBlockTable(pBlockTable,AcDb::kForRead);//获得指向特定块表记录的指针AcDbBlockTableRecord*pBlockTableRecord;pBlockTable-getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);//将对象添加到块表记录中AcDbObjectIdlineId;pBlockTableRecord-appendAcDbEntity(lineId,pLine);//关闭图形数据库的各种对象pBlockTable-close();pBlockTableRecord-close();pLine-close();//为在命令函数中引用该函数,需要返回lineIdreturnlineId;}staticAcad::ErrorStatusChangeColor(AcDbObjectIdentId,Adesk::UInt16colorIndex){AcDbEntity*pEntity;//打开图形数据库中的对象acdbOpenObject(pEntity,entId,AcDb::kForWrite);//修改实体颜色pEntity-setColorIndex(colorIndex);//关闭实体对象pEntity-close();//被命令函数引用时需返回值returnAcad::eOk;}//-mshlModifyEnt.ChangeColorcommand(donotrename)staticvoidmshlModifyEntChangeColor(void){//AddyourcodeforcommandmshlModifyEnt.ChangeColorhere//创建直线AcDbObjectIdlineId;创建时间:2013/11/279:06:00lineId=CreatLine();//修改直线颜色ChangeColor(lineId,1);}六、用类组织函数1、新建ObjectARX项目CreatEnt2、新建两个C++类CreatEnt和ModifyEnt用这个类保存创建实体的函数头文件#pragmaonce#includeStdAfx.hclassCCreatEnt{public:CCreatEnt(void);~CCreatEnt(void);staticAcDbObjectIdCreatLine();};源文件#includeStdAfx.h#includeCreatEnt.hCCreatEnt::CCreatEnt(void){}创建时间:2013/11/279:06:00CCreatEnt::~CCreatEnt(void){}AcDbObjectIdCCreatEnt::CreatLine(){//在内存上创建一个新的AcDbLine对象AcGePoint3dptStart(0,0,0);AcGePoint3dptEnd(100,100,0);AcDbLine*pLine=newAcDbLine(ptStart,ptEnd);//获得指向块表的指针AcDbBlockTable*pBlockTable;acdbHostApplicationServices()-workingDatabase()-getBlockTable(pBlockTable,AcDb::kForRead);//获得指向特定块表记录的指针AcDbBlockTableRecord*pBlockTableRecord;pBlockTable-getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);//将对象添加到块表记录中AcDbObjectIdlineId;pBlockTableRecord-appendAcDbEntity(lineId,pLine);//关闭图形数据库的各种对象pBlockTable-close();pBlockTableRecord-close();pLine-close();returnlineId;}头文件#pragmaonce#includeStdAfx.hclassCModifyEnt{public:CModifyEnt(void);~CModifyEnt(void);staticAcad::ErrorStatusChangeColor(AcDbObjectIdentId,Adesk::UInt16colorIndex);};源文件#includeStdAfx.h#inclu