Building Coder(Revit 二次开发) - UIView 和 Windows 设备坐标
来源:互联网 发布:linux svn改登录账号 编辑:程序博客网 时间:2024/06/03 10:18
原文链接:UIView and Windows Device Coordinates
Revit 2013 API 中新提供了一个新的视图 API,具体地说是提供一个新类 UIView。UIView 代表一个视图窗口,让我们可以通过程序来移动、缩放和决定窗口平铺时的大小等等一系列操作。也为我们从其它可视化环境切换回视图提供了可能。
UIView 目前只公开了三个方法:
1. GetWindowRectangle:使用窗口坐标系返回视图的绘图区域的矩形坐标;
2. GetZoomCorners:使用 Revit 模型坐标系返回视图矩形的四个角坐标;
3. ZoomAndCreateRectangle:将视图缩放并居中到一个指定的矩形区域中
UIView 是 Revit API 第一次提供了窗口坐标和 Revit 坐标之间的关联,开启了 Revit 全新的交互方式。比方说:在 Idling 事件中显示自定义的 Tooltip ……
值得一提的是,目前 Revit API 只能通过 UIDocument.GetOpenUIViews() 方法获取 UIView 对象。由于每个 UIView 都是和一个视图绑定的,所以我们可以通过 UIView.ViewId 来判断某个 UIView 是属于哪个视图的。
我创建了一个简单的外部命令 WinCoords 来测试 UIView。它的功能如下:
- 获取当前视图
- 获取当前文档的所有 UIView 对象
- 找到属于当前视图的 UIView 对象
- 读取当前 UIView 的窗口和 Revit 坐标
- 调用 ZoomAndCenterRectangle 将 Revit 模型放大 10%
注意:窗口坐标系中 Y 方向和通常的坐标系中相反。显示矩形坐标的 RectangleString() 方法代码如下:
Revit 2013 API 中新提供了一个新的视图 API,具体地说是提供一个新类 UIView。UIView 代表一个视图窗口,让我们可以通过程序来移动、缩放和决定窗口平铺时的大小等等一系列操作。也为我们从其它可视化环境切换回视图提供了可能。
UIView 目前只公开了三个方法:
1. GetWindowRectangle:使用窗口坐标系返回视图的绘图区域的矩形坐标;
2. GetZoomCorners:使用 Revit 模型坐标系返回视图矩形的四个角坐标;
3. ZoomAndCreateRectangle:将视图缩放并居中到一个指定的矩形区域中
UIView 是 Revit API 第一次提供了窗口坐标和 Revit 坐标之间的关联,开启了 Revit 全新的交互方式。比方说:在 Idling 事件中显示自定义的 Tooltip ……
值得一提的是,目前 Revit API 只能通过 UIDocument.GetOpenUIViews() 方法获取 UIView 对象。由于每个 UIView 都是和一个视图绑定的,所以我们可以通过 UIView.ViewId 来判断某个 UIView 是属于哪个视图的。
我创建了一个简单的外部命令 WinCoords 来测试 UIView。它的功能如下:
- 获取当前视图
- 获取当前文档的所有 UIView 对象
- 找到属于当前视图的 UIView 对象
- 读取当前 UIView 的窗口和 Revit 坐标
- 调用 ZoomAndCenterRectangle 将 Revit 模型放大 10%
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ){UIApplication uiapp = commandData.Application;UIDocument uidoc = uiapp.ActiveUIDocument;Document doc = uidoc.Document;View view = doc.ActiveView;UIView uiview = null;IList<UIView> uiviews = uidoc.GetOpenUIViews();foreach( UIView uv in uiviews ){if( uv.ViewId.Equals( view.Id ) ){uiview = uv;break;}}Rectangle rect = uiview.GetWindowRectangle();IList<XYZ> corners = uiview.GetZoomCorners();XYZ p = corners[0];XYZ q = corners[1];string msg = string.Format( "UIView Windows rectangle: {0}; zoom corners: {1}-{2}; click Close to zoom in by 10%.", RectangleString( rect ), PointString( p ), PointString( q ) );TaskDialog.Show( "WinCoords", msg );// Calculate new zoom corners to // zoom in by 10%, i.e. the two corners// end up at 0.45 of their previous// distance to the centre point.XYZ v = q - p;XYZ center = p + 0.5 * v;v *= 0.45;p = center - v;q = center + v;uiview.ZoomAndCenterRectangle( p, q );return Result.Succeeded;}
注意:窗口坐标系中 Y 方向和通常的坐标系中相反。显示矩形坐标的 RectangleString() 方法代码如下:
/// <summary>/// 返回一个表示矩形区域的字符串,格式是(左上角)-(右下角)/// 窗口坐标系的 Y 方向是相反方向/// </summary>static string RectangleString( Rectangle r ){return string.Format( "({0},{1})-({2},{3})", r.Left, r.Top, r.Right, r.Bottom );}
- Building Coder(Revit 二次开发) - UIView 和 Windows 设备坐标
- Building Coder(Revit 二次开发) - 真实世界中的角坐标
- Building Coder(Revit 二次开发) - 组合使用 Revit 和 Vault
- Building Coder(Revit 二次开发) - 参数访问和计划信息
- Building Coder(Revit 二次开发) - 列出链接文件和 TransmissionData
- Building Coder(Revit 二次开发) - 布尔操作和 InstanceVoidCutUtils
- Building Coder(Revit 二次开发) - 对象关系
- Building Coder(Revit 二次开发) - RevitLoopup 更新
- Building Coder(Revit 二次开发) - 拖放API
- Building Coder(Revit 二次开发) - 翻译 Revit Tooltip
- Building Coder(Revit 二次开发) - 元素层级事件(上)
- Building Coder(Revit 二次开发) - 元素层级事件(下)
- Building Coder(Revit 二次开发) - 失败处理API(上)
- Building Coder(Revit 二次开发) - 失败处理API(下)
- Building Coder(Revit 二次开发) - 复制 Legend 组件
- Building Coder(Revit 二次开发) - 放置族实例
- Building Coder(Revit 二次开发) - 设置标签类型
- Building Coder(Revit 二次开发) - 族元素可见性
- Android Building System
- SQL Server | 第三,四天学习总结
- ubuntu 10.04 装系统
- 项目经理注意事项
- zoj 3519 Who is the Smartest Man
- Building Coder(Revit 二次开发) - UIView 和 Windows 设备坐标
- android make file 参数解释及模板(即 android.mk内容解释)
- Hibernate学习笔记(三)【配置详解】
- 【iOS开发必收藏】详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程!2012-6-25日更新iap恢复
- I/O电压供电居然也行?
- hdu_1874
- android 系统 makefile文件(Android.mk)组织结构(main.mk)
- const_iterator思考
- autocad 07教程学习