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;
            }
        }
    }
  • 相关阅读:
    微信小程序 --- 获取当前坐标
    微信小程序 --- 缓存数据
    微信小程序 --- 音乐的播放和控制
    微信小程序 --- webSocket
    微信小程序 --- 文件的上传和下载
    微信小程序 --- 选择图片和拍照
    微信小程序 --- loading提示框
    微信小程序 --- toast消息提示框
    Atitit.attilax软件研发与项目管理之道
    Atitit.attilax软件研发与项目管理之道
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13285563.html
Copyright © 2011-2022 走看看