ObjectARX_符号表---->UCS
2018-02-06 00:00
162 查看
创建 UCS 来调整图形的参考系。
创建 UCS:
设置为当前 UCS:
移动UCS 的原点:
UCS 绕 Z 轴旋转60°:
在UCS 中创建实体:
创建 UCS:
void ZffCHAP4NewUCS() { // 获得当前图形的UCS表 AcDbUCSTable *pUcsTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getUCSTable(pUcsTbl, AcDb::kForWrite); // 定义UCS的参数 AcGePoint3d ptOrigin(0, 0, 0); AcGeVector3d vecXAxis(1, 1, 0); AcGeVector3d vecYAxis(-1, 1, 0); // 创建新的UCS表记录 AcDbUCSTableRecord *pUcsTblRcd = new AcDbUCSTableRecord(); // 设置UCS的参数 Acad::ErrorStatus es = pUcsTblRcd->setName("NewUcs"); if (es != Acad::eOk) { delete pUcsTblRcd; pUcsTbl->close(); return; } //AcDbUCSTableRecord 类的 setOrigin、setXAxis 和setYAxis 三个函数分别用来设置原点、X 轴和 Y 轴的方向。 pUcsTblRcd->setOrigin(ptOrigin); pUcsTblRcd->setXAxis(vecXAxis); pUcsTblRcd->setYAxis(vecYAxis); // 将新建的UCS表记录添加到UCS表中 es = pUcsTbl->add(pUcsTblRcd); if (es != Acad::eOk) { delete pUcsTblRcd; pUcsTbl->close(); return; } // 关闭对象 pUcsTblRcd->close(); pUcsTbl->close(); }
设置为当前 UCS:
void ZffCHAP4SetCurUcs() { // 提示用户输入UCS的名称 char ucsName[40]; if (acedGetString(NULL, "\n输入用户坐标系的名称:", ucsName) != RTNORM) return; // 获得指定的UCS表记录 AcDbUCSTable *pUcsTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getUCSTable(pUcsTbl, AcDb::kForRead); if (!pUcsTbl->has(ucsName)) { pUcsTbl->close(); return; } AcDbUCSTableRecord *pUcsTblRcd = NULL; pUcsTbl->getAt(ucsName, pUcsTblRcd, AcDb::kForRead); // 获得UCS的变换矩阵 AcGeMatrix3d mat;// UCS 到 WCS 转换 AcGeVector3d vecXAxis, vecYAxis, vecZAxis; vecXAxis = pUcsTblRcd->xAxis(); vecYAxis = pUcsTblRcd->yAxis(); vecZAxis = vecXAxis.crossProduct(vecYAxis);//两个矢量的向量积(根据 UCS 的 X、Y 轴方向获得 Z 方向。) mat.setCoordSystem(pUcsTblRcd->origin(), vecXAxis,vecYAxis, vecZAxis); // 关闭UCS表和UCS表记录 pUcsTblRcd->close(); pUcsTbl->close(); // 设置当前的UCS acedSetCurrentUCS(mat); }
移动UCS 的原点:
void ZffCHAP4MoveUcsOrigin() { // 获得当前UCS的变换矩阵 AcGeMatrix3d mat; Acad::ErrorStatus es = acedGetCurrentUCS(mat); // 根据变换矩阵获得UCS的参数 AcGePoint3d ptOrigin; AcGeVector3d vecXAxis, vecYAxis, vecZAxis; mat.getCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis); // 移动UCS的原点 AcGeVector3d vec(100, 100, 0); ptOrigin += vec; // 更新变换矩阵 mat.setCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis); // 应用新的UCS acedSetCurrentUCS(mat); }
UCS 绕 Z 轴旋转60°:
void ZffCHAP4RotateUcs() { // 获得当前UCS的变换矩阵 AcGeMatrix3d mat; Acad::ErrorStatus es = acedGetCurrentUCS(mat); // 根据变换矩阵获得UCS的参数 AcGePoint3d ptOrigin; AcGeVector3d vecXAxis, vecYAxis, vecZAxis; mat.getCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis); // 绕Z轴旋转60度 vecXAxis.rotateBy(60 * atan(1) * 4 / 180, vecZAxis); vecYAxis.rotateBy(60 * atan(1) * 4 / 180, vecZAxis); // 更新变换矩阵 mat.setCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis); // 应用新的UCS acedSetCurrentUCS(mat); }
在UCS 中创建实体:
void ZffCHAP4AddEntInUcs() { // 转换坐标系的标记 struct resbuf wcs, ucs; wcs.restype = RTSHORT; wcs.resval.rint = 0; ucs.restype = RTSHORT; ucs.resval.rint = 1; // 提示用户输入直线的起点和终点 ads_point pt1, pt2; if (acedGetPoint(NULL, "拾取直线的起点:", pt1) != RTNORM) return; if (acedGetPoint(pt1, "拾取直线的终点:", pt2) != RTNORM) return; // 将起点和终点坐标转换到WCS acedTrans(pt1, &ucs, &wcs, 0, pt1); acedTrans(pt2, &ucs, &wcs, 0, pt2); // 创建直线 AcDbLine *pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2)); AcDbBlockTable *pBlkTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl, AcDb::kForRead); AcDbBlockTableRecord *pBlkTblRcd= NULL; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,AcDb::kForWrite); pBlkTbl->close(); pBlkTblRcd->appendAcDbEntity(pLine); pLine->close(); pBlkTblRcd->close(); }
相关文章推荐
- ObjectARX_符号表---->文字样式
- ObjectARX_符号表---->视图
- ObjectARX_符号表---->视口
- ObjectARX_符号表---->标注样式
- ObjectARX_符号表---->图层
- "*" "::" "." ":" "->" c/c++编程中几种符号的用法和说明
- JavaScript位移运算符(无符号) >>> 三个大于号 的使用方法详解
- java移位运算符实验程序:<<(左移)、>>(带符 号右移)和>>>(无符号右移)
- <!--内容//-->请问在CSS里面,这个符号是什么 意思?
- C语言里面,这个符号(->)
- 获取屏蔽符号<!-- -->屏蔽的字符串的代码
- OpenCV编程->无法解析的外部符号 "void __cdecl cv::cvtColor
- <perl> 符号引用
- 请实现一个反转32位有符号整数的函数,例如123—>321,-123->-321,120->21,如果溢出就返回0(面试题)
- Java移位运算符详解实例——左移位运算符>>、带符号的右移位运算符>>
- java中右移运算符>>和无符号右移运算符>>>的区别
- error LNK2019: 无法解析的外部符号 ___glutInitWithExit@12,该符号在函数 _glutInit_ATEXIT_HACK@8 中被引用 1>GEARS.obj : er
- 分析轮子(二)- << ,>>,>> (左移、右移、无符号右移)
- perl 面向对象 -> 符号使用
- scala符号<:和: =>以及_*等