2012-02-06 18:23:14|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, ObjectArx, AutoCAD|来源:唯设编程网
Step6、定义创建直线VC函数void myCreateLine(),创建圆的VC函数void myCreateCircle(),最终完成后的代码如下:
//画直线 void myCreateLine() { //在内存上创建一个新的AcDbLine对象 AcGePoint3d ptStart(0,0,0); AcGePoint3d ptEnd(100,100,0); AcDbLine *pLine=new AcDbLine(ptStart,ptEnd); //获取指向块表的指针 AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead); //获得指向特定的块表记录(模型空间)的指针 AcDbBlockTableRecord* pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); //将AcDbline类的对象添加到块表记录中 AcDbObjectId lineId; pBlockTableRecord->appendAcDbEntity(lineId,pLine); //关闭图形数据库的各种对象 pBlockTable->close(); pBlockTableRecord->close(); pLine->close(); } //画圆 void myCreateCircle() { //在内存上创建一个新的AcDbLine对象 AcGePoint3d ptCenter(0,0,0); AcGeVector3d normal(0.0,0.0,1.0); double fRadius=25; //AcDbCircle *pCircle=new AcDbCircle(ptCenter,normal,fRadius); AcDbCircle *pCircle=new AcDbCircle(); pCircle->setCenter(ptCenter); pCircle->setRadius(fRadius); //获取指向块表的指针 AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForRead); //获得指向特定的块表记录(模型空间)的指针 AcDbBlockTableRecord* pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite); //将AcDbCircle类的对象添加到块表记录中 AcDbObjectId circleId; pBlockTableRecord->appendAcDbEntity(circleId,pCircle); //关闭图形数据库的各种对象 pBlockTable->close(); pBlockTableRecord->close(); pCircle->close(); }
选择:生成->重新生成解决方案,结果没有问题!
Step7、启动AutoCAD2007,输入命令ARX,根据提示输入L加载ARX文件,在文件对话框中选择我们刚才编译生成的ARX文件,如图所示:
单击打开完成加载。
Step8、在前面我们使用
acedRegCmds->addCommand(_T("DEDYDGROUP"),_T("CREATELINE"),_T("CREATELINE"),ACRX_CMD_TRANSPARENT|ACRX_CMD_USEPICKSET,myCreateLine); acedRegCmds->addCommand(_T("DEDYDGROUP"),_T("CREATECIRCLE"),_T("CREATECIRCLE"),ACRX_CMD_TRANSPARENT|ACRX_CMD_USEPICKSET,myCreateCircle);
函数分别添加了我们自定义的命令CREATELINE和CREATECIRCLE用于画直线和画圆,我们在AutoCAD环境中直接输入 CREATELINE命令然后回车,CREATECIRCLE然后回车,结果如图所示:
到此,我们就完成了使用VC2005和ObjectARX2007进行AutoCAD2007二次开发的环境配置并实现了一个简单实例。