天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 45|回复: 1

objectARX 添加布局视口

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式


#pragma once
2
3 // ----------------------------------------------------------------------------------------------------------------
4 // Summary: 布局裁图
5 // ----------------------------------------------------------------------------------------------------------------
6 class CLayoutCutDrawing
7 {
8 public:
9     CLayoutCutDrawing(void);
10     ~CLayoutCutDrawing(void);
11
12     // --------------------------------------------------------------------------------------------
13 // Summary: 绘制布局裁图
14 // Parameters:
15 //     pt1                -    裁图区域所在的外包最小点
16 //     pt2                -    裁图区域所在的外包最大点
17 //     ptInsertTopLeft    -    视口的左下脚点
18 //     dScaleFactor        -    缩放比例
19 //     dAngle                -    裁图角度
20 //     pBoundary            -    裁图边界
21 // Returns:
22 //     成功返回 Acad::eOk, 否则返回 Acad::ErrorStatus 错误状态
23 // --------------------------------------------------------------------------------------------
24     static Acad::ErrorStatus DrawLayout(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptInsertBottomLeft, LPCTSTR lpszLayoutName, double dScaleFactor, double dAngle, AcDbPolyline* pBoundary);
25
26     // --------------------------------------------------------------------------------------------
27 // Summary: 创建新布局
28 // Parameters:
29 //     lpszName        -    布局的名称
30 //     layoutId        -    布局id
31 //     blkTabRecId    -    布局块表记录
32 // Returns:
33 //     成功返回 Acad::eOk, 否则返回 Acad::ErrorStatus 错误状态
34 // --------------------------------------------------------------------------------------------
35     static Acad::ErrorStatus CreateNewLayout(LPCTSTR lpszName, AcDbObjectId& layoutId, AcDbObjectId& blkTabRecId);
36
37 protected:
38
39     // --------------------------------------------------------------------------------------------
40 // Summary: 遍历所有布局
41 // --------------------------------------------------------------------------------------------
42     Acad::ErrorStatus AllLayout();
43
44     // --------------------------------------------------------------------------------------------
45 // Summary: 查找指定名称的布局
46 // Parameters:
47 //     lpszName        -    布局的名称
48 //     layoutId        -    布局id
49 //     blkTabRecId    -    布局块表记录
50 // Returns:
51 //     成功返回 Acad::eOk, 否则返回 Acad::ErrorStatus 错误状态
52 // --------------------------------------------------------------------------------------------
53     static Acad::ErrorStatus FindLayout(LPCTSTR lpszName, AcDbObjectId& layoutId, AcDbObjectId& blkTabRecId);
54 };

 

 

 

 

objectARX 添加布局视口

签到天数: 137 天

[LV.7]常住居民III

41

主题

3

回帖

299

积分

管理员

积分
299
QQ
发表于 5 天前 | 显示全部楼层
  1.     static void MyGroupTest136()
  2.     {
  3.         AcDbDatabase* pDbUse = acdbHostApplicationServices()->workingDatabase();
  4.         AcDbDictionary* pNOD;
  5.         Acad::ErrorStatus eStat;
  6.         // 打开数据库的命名对象字典 (NamedObjects)
  7.         eStat = pDbUse->getNamedObjectsDictionary(pNOD, AcDb::kForRead);
  8.         if (eStat != Acad::eOk)
  9.             return;
  10.         AcDbObjectId idDict;
  11.         eStat = pNOD->getAt(_T("ACAD_LAYOUT"), idDict);
  12.         pNOD->close();
  13.         if (eStat != Acad::eOk)
  14.             return;
  15.         AcDbDictionary* pDict;
  16.         eStat = acdbOpenObject(pDict, idDict, AcDb::kForRead);
  17.         if (eStat != Acad::eOk)
  18.             return;
  19.         AcDbObjectId idLyt;
  20.         eStat = pDict->getAt(_T("Layout1"), idLyt);
  21.         pDict->close();
  22.         // 布局管理器
  23.         AcApLayoutManager* pLayM = (AcApLayoutManager*)acdbHostApplicationServices()->layoutManager();
  24.         // 设置当前布局
  25.         pLayM->setCurrentLayout(_T("Layout1"));
  26.         AcDbLayout* pLyt;
  27.         if (acdbOpenObject(pLyt, idLyt, AcDb::kForRead) != Acad::eOk)
  28.             return;
  29.         AcDbObjectId idBtr = pLyt->getBlockTableRecordId();
  30.         pLyt->close();
  31.         AddViewPort(idBtr, AcGePoint3d(2, 5, 0), AcGeVector3d(0, 0, 1));
  32.         AddViewPort(idBtr, AcGePoint3d(5, 5, 0), AcGeVector3d(-1, -1, 1));
  33.         AddViewPort(idBtr, AcGePoint3d(8, 5, 0), AcGeVector3d(1, 1, 1));
  34.     }
  35.     // 添加视口
  36.     static void AddViewPort(AcDbObjectId idToBtr, AcGePoint3d centerPoint, AcGeVector3d vecVPoint)
  37.     {
  38.         AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();
  39.         AcDbViewport* pVp = new AcDbViewport;
  40.         // 将新视口附加到图纸空间
  41.         AcDbBlockTableRecord* pBTR;
  42.         if (acdbOpenObject(pBTR, idToBtr, AcDb::kForWrite) != Acad::eOk)
  43.         {
  44.             acutPrintf(_T("\n无法访问图纸空间."));
  45.             delete pVp;
  46.             return;
  47.         }
  48.         if (pBTR->appendAcDbEntity(pVp) != Acad::eOk)
  49.         {
  50.             acutPrintf(_T("\n无法将视口附加到图纸空间."));
  51.             pBTR->close();
  52.             delete pVp;
  53.             return;
  54.         }
  55.         pBTR->close();
  56.         pVp->setCenterPoint(centerPoint);
  57.         // 设置查看方向
  58.         pVp->setViewDirection(vecVPoint);
  59.         // 假设目标点是WCS(0,0,0)
  60.         AcGeMatrix3d ucsMatrix;
  61.         getTrnsMatrix(ucsMatrix, vecVPoint, AcGePoint3d(0, 0, 0));
  62.         // 在视口的x-y平面中获取一个矩形窗口,该平面表示绘图的范围
  63.         AcGePoint2d maxExt, minExt;
  64.         getUcsExts(maxExt, minExt, ucsMatrix);
  65.         // 这里2是视图的高度。 您可以将其更改为任何高度
  66.         SetViewportExtents(pVp, maxExt, minExt, 2);
  67.         pVp->setOn();
  68.         pVp->close();
  69.     }
  70.     // 获取 WCS 到 UCS 转换矩阵
  71.     static void getTrnsMatrix(AcGeMatrix3d& ucsMatrix, AcGeVector3d ViewDirection, AcGePoint3d origin)
  72.     {
  73.         AcGePlane XYPlane(origin, ViewDirection);
  74.         ucsMatrix.setToWorldToPlane(XYPlane);
  75.     }
复制代码

 

 

 

 

objectARX 添加布局视口
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-9-30 04:27 , Processed in 0.119369 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表