ObjectARX(VC)-符号表之视口-创建4个等大的视口

(1)注册一个命令AAAMyGroupCreate4VPorts()

(2)获得视口表

AcDbViewportTable *pVPortTbl = NULL;
acdbHostApplicationServices()->workingDatabase()
	->getViewportTable(pVPortTbl, AcDb::kForWrite);//使用“写”的模式打开数据库的Viewport table

(3)分别创建四个视口

AcGePoint2d pt1, pt2;
		AcDbViewportTableRecord *pVPortTblRcd1 = new AcDbViewportTableRecord;
		pt1.set(0, 0);
		pt2.set(0.5, 0.5);
		pVPortTblRcd1->setLowerLeftCorner(pt1);//设置左下角的点
		pVPortTblRcd1->setUpperRightCorner(pt2);//设置右下角的点
		pVPortTblRcd1->setName(TEXT("4VPorts"));

		AcDbViewportTableRecord *pVPortTblRcd2 = new AcDbViewportTableRecord;
		pt1.set(0.5, 0);
		pt2.set(1, 0.5);
		pVPortTblRcd2->setLowerLeftCorner(pt1);
		pVPortTblRcd2->setUpperRightCorner(pt2);
		pVPortTblRcd2->setName(TEXT("4VPorts"));

		AcDbViewportTableRecord *pVPortTblRcd3 = new AcDbViewportTableRecord;
		pt1.set(0, 0.5);
		pt2.set(0.5, 1);
		pVPortTblRcd3->setLowerLeftCorner(pt1);
		pVPortTblRcd3->setUpperRightCorner(pt2);
		pVPortTblRcd3->setName(TEXT("4VPorts"));


		AcDbViewportTableRecord *pVPortTblRcd4 = new AcDbViewportTableRecord;
		pt1.set(0.5, 0.5);
		pt2.set(1, 1);
		pVPortTblRcd4->setLowerLeftCorner(pt1);
		pVPortTblRcd4->setUpperRightCorner(pt2);
		pVPortTblRcd4->setName(TEXT("4VPorts"));

(4)将新创建的视口添加到视口表pVPortTbl

		pVPortTbl->add(pVPortTblRcd1);
		pVPortTbl->add(pVPortTblRcd2);
		pVPortTbl->add(pVPortTblRcd3);
		pVPortTbl->add(pVPortTblRcd4);

(5)关闭视口表

	pVPortTbl->close();

(6)关闭视口表记录

		pVPortTblRcd1->close();
		pVPortTblRcd2->close();
		pVPortTblRcd3->close();
		pVPortTblRcd4->close();

(7)判断当前的空间

		struct resbuf rb;
		acedGetVar(TEXT("TILEMODE"), &rb);//指定TILEMODE为AutoCAD为系统变量
		//TILEMODE:Accesses the current TILEMODE value for the database. The value of false is 0. The value of true is 1. 
		if (rb.resval.rint == 1)//当前工作空间是模型空间
		{
			acedCommandS(RTSTR, TEXT(".-VPORTS"), 
				RTSTR, TEXT("R"),
				RTSTR, TEXT("4VPorts"),
				RTNONE);
			
		}
		else//当前工作空间是图纸空间
		{
			acedCommandS(RTSTR, TEXT(".-VPORTS"),
				RTSTR, TEXT("R"),
				RTSTR, TEXT("4VPorts"),
				RTSTR, TEXT(""), RTNONE);
		}

注意:arx 2015之后已经将acedCommand函数升级为acedCommandS函数,使用该函数需要添加头文件”acedCmdNF.h”

如果使用acedCommand函数会报错:

“MustSwitchTo_acedCommandC_or_acedCommandS”: 未声明的标识符

(8)效果

(9)项目源代码:

 

static void AAAMyGroupCreate4VPorts() {
		// Put your command code here
		// 获得视口表
		AcDbViewportTable *pVPortTbl = NULL;
		acdbHostApplicationServices()->workingDatabase()
			->getViewportTable(pVPortTbl, AcDb::kForWrite);//使用“写”的模式打开数据库的Viewport table

		//分别创建四个视口
		AcGePoint2d pt1, pt2;
		AcDbViewportTableRecord *pVPortTblRcd1 = new AcDbViewportTableRecord;
		pt1.set(0, 0);
		pt2.set(0.5, 0.5);
		pVPortTblRcd1->setLowerLeftCorner(pt1);//设置左下角的点
		pVPortTblRcd1->setUpperRightCorner(pt2);//设置右下角的点
		pVPortTblRcd1->setName(TEXT("4VPorts"));

		AcDbViewportTableRecord *pVPortTblRcd2 = new AcDbViewportTableRecord;
		pt1.set(0.5, 0);
		pt2.set(1, 0.5);
		pVPortTblRcd2->setLowerLeftCorner(pt1);
		pVPortTblRcd2->setUpperRightCorner(pt2);
		pVPortTblRcd2->setName(TEXT("4VPorts"));

		AcDbViewportTableRecord *pVPortTblRcd3 = new AcDbViewportTableRecord;
		pt1.set(0, 0.5);
		pt2.set(0.5, 1);
		pVPortTblRcd3->setLowerLeftCorner(pt1);
		pVPortTblRcd3->setUpperRightCorner(pt2);
		pVPortTblRcd3->setName(TEXT("4VPorts"));


		AcDbViewportTableRecord *pVPortTblRcd4 = new AcDbViewportTableRecord;
		pt1.set(0.5, 0.5);
		pt2.set(1, 1);
		pVPortTblRcd4->setLowerLeftCorner(pt1);
		pVPortTblRcd4->setUpperRightCorner(pt2);
		pVPortTblRcd4->setName(TEXT("4VPorts"));

		pVPortTbl->add(pVPortTblRcd1);//将新创建的视口添加到视口表pVPortTbl中
		pVPortTbl->add(pVPortTblRcd2);
		pVPortTbl->add(pVPortTblRcd3);
		pVPortTbl->add(pVPortTblRcd4);

		//关闭视口表
		pVPortTbl->close();

		//关闭视口表记录
		pVPortTblRcd1->close();
		pVPortTblRcd2->close();
		pVPortTblRcd3->close();
		pVPortTblRcd4->close();

		//判断当前的空间
		struct resbuf rb;
		acedGetVar(TEXT("TILEMODE"), &rb);//Retrieves the current value of the specified AutoCAD system variable. 
		//TILEMODE:Accesses the current TILEMODE value for the database. The value of false is 0. The value of true is 1. 
		if (rb.resval.rint == 1)//当前工作空间是模型空间
		{
			acedCommandS(RTSTR, TEXT(".-VPORTS"), 
				RTSTR, TEXT("R"),
				RTSTR, TEXT("4VPorts"),
				RTNONE);
			
		}
		else//当前工作空间是图纸空间
		{
			acedCommandS(RTSTR, TEXT(".-VPORTS"),
				RTSTR, TEXT("R"),
				RTSTR, TEXT("4VPorts"),
				RTSTR, TEXT(""), RTNONE);
		}


	}

参考资料:

《AutoCAD ObjectARX(VC)开发基础与实例教程》

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容