zoukankan      html  css  js  c++  java
  • Revit 二次开发 交互及UIAPI之Selection

    学习地址:https://www.bilibili.com/video/BV1mf4y1S72o?p=12

    本章内容

    • Selection交互API
    • TaskDialog对话框
    • Ribbon菜单

    Selection交互API

    实例练习一

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.Attributes;
    using System.Windows.Forms;
    using Autodesk.Revit.UI.Selection;
    
    namespace RevitDevTV
    {
        /// <summary>
        /// Selection 交互API,实例练习
        /// </summary>
        [TransactionAttribute(TransactionMode.Manual)]
        [RegenerationAttribute(RegenerationOption.Manual)]
        public class Sele : IExternalCommand
        {
            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                UIDocument uidoc = commandData.Application.ActiveUIDocument;
                Document doc = uidoc.Document;
                Selection s1 = uidoc.Selection;
                XYZ point = null;
                try
                {
                    point = s1.PickPoint("请选择一个点");
                }
                catch (Exception ex)
                {
                    return Result.Succeeded;
                }
                Transaction trans = new Transaction(doc,"t1");
                trans.Start();
                //创建一个柱子
                FamilySymbol familySymbol = doc.GetElement(new ElementId(691519)) as FamilySymbol;
                if (!familySymbol.IsActive)
                {
                    familySymbol.Activate();
                }
                //创建标高
                Level level = null;
                //创建柱子
                FamilyInstance fi = doc.Create.NewFamilyInstance(point,familySymbol,level,Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                trans.Commit();
                //===============计算体积
                Selection s2 = uidoc.Selection;
                Reference re = s2.PickObject(ObjectType.Element,"请选择一个物体");
                Element ele = doc.GetElement(re);
                Options opt = new Options();
                GeometryElement gelem = ele.get_Geometry(opt);
                double v = 0.0; //存储体积
                v = GetSolid(gelem).Sum(m=>m.Volume)*0.3048*0.3048;
                TaskDialog.Show("Hint","选中的物体体积为:"+v.ToString("f3"));
                IList<Element> pickedElement = s2.PickElementsByRectangle(new WallSelectionfilte(),"请框选目标物体");
                double num = pickedElement.Count();
                TaskDialog.Show("Hint","已选中墙数为:"+num);
                return Result.Succeeded;
            }
            private List<Solid> GetSolid(GeometryElement gelem)
            {
                List<Solid> solids = new List<Solid>();
                foreach (GeometryObject obj in gelem)
                {
                    if (obj is Solid)
                    {
                        solids.Add(obj as Solid);
                    }
                    if (obj is GeometryElement)
                    {
                        solids.AddRange(GetSolid(obj as GeometryElement));
                    }
                    if (obj is GeometryInstance)
                    {
                        GeometryInstance gins = obj as GeometryInstance;
                        GeometryElement gelm = gins.GetInstanceGeometry();
                        solids.AddRange(GetSolid(gelem));
                    }
                }
                return solids;
            }
        }
        public class WallSelectionfilte : ISelectionFilter
        {
            public bool AllowElement(Element elem)
            {
                return elem is Wall;
            }
    
            public bool AllowReference(Reference reference, XYZ position)
            {
                return true;
            }
        }
    }
  • 相关阅读:
    斐波那契数列 的两种实现方式(Java)
    单链表反转
    单链表合并
    两个有序list合并
    list去重 转载
    RemoveAll 要重写equals方法
    Java for LeetCode 138 Copy List with Random Pointer
    Java for LeetCode 137 Single Number II
    Java for LeetCode 136 Single Number
    Java for LeetCode 135 Candy
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13285563.html
Copyright © 2011-2022 走看看