欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Revit 二次开发 - 视图缩放组件突出中心显示

最编程 2024-04-07 07:31:46
...

转载一下,以备后用
http://blog.sina.com.cn/s/blog_16796559b0102y8fj.html

当然要实现视图缩放需要ZoomAndCenterRectangle函数的帮助喽,高亮构件只需加入选择集,构件居中显示需要ShowElements函数

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Mechanical;
using System.Xml;
using Autodesk.Revit.UI.Events;

namespace HelloWorld
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Test : IExternalCommand
    {  
        public  Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document Doc = uiDoc.Document;
            IList list = new List();
            Reference refer=uiDoc.Selection.PickObject(ObjectType.Element,"Scale");
            //转化到实例
            FamilyInstance instance = Doc.GetElement(refer) as FamilyInstance;
            //获得实例的坐标
            LocationPoint location = instance.Location as LocationPoint;
            //转化为XYZ
            XYZ xyz = location.Point;

            //缩放因子
            XYZ ViewOne = new XYZ(xyz.X - 10, xyz.Y - 10, 0);
            XYZ ViewTwo = new XYZ(xyz.X + 10, xyz.Y + 10, 0);
            IList UiViews = uiDoc.GetOpenUIViews();
            UIView UIview = UiViews.Where(o => o.ViewId == Doc.ActiveView.Id) as UIView;
            //缩放视图函数
            UIview.ZoomAndCenterRectangle(ViewOne, ViewTwo);

            //加入选择集 高亮显示
            list.Add(Doc.GetElement(refer).Id);
            uiDoc.Selection.SetElementIds(list);
            //居中显示构件
            uiDoc.ShowElements(instance);
            return Result.Succeeded;
        }
    }
}