zoukankan      html  css  js  c++  java
  • Revit API创建房间

    start
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class CreateRoomAndCopyProperties : IExternalCommand
    {
        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
        {
            UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
            Document doc = uiDoc.Document;
            Selection sel = uiDoc.Selection;
            //1.选择房间
            RoomFilter filter = new RoomFilter();
            Reference refRoom = sel.PickObject(ObjectType.Element, filter, "选择房间:");
            Room room = doc.GetElement(refRoom) as Room;
            //2.获取目标房间属性
            string roomName = room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString();
            string roomDepartment = room.get_Parameter(BuiltInParameter.ROOM_DEPARTMENT).AsString();
            string roomOccupancy = room.get_Parameter(BuiltInParameter.ROOM_OCCUPANCY).AsString();
            //循环创建房间
            bool bContinue = true;
            while (bContinue)
            {
                XYZ point;
                try
                {
                    //3.获取用户输入的点
                    point = sel.PickPoint("点击要创建的房间中的一点:");
                }
                catch (Autodesk.Revit.Exceptions.InvalidOperationException ex)
                {
                    bContinue = false;
                    break;
                }
                catch (Exception)
                {
                    bContinue = false;
                    break;
                }
                //4.根据选中点,创建房间
                Transaction ts = new Transaction(doc, "http://revit.5d6d.com");
                ts.Start();
                //当前视图的楼层doc.ActiveView.GenLevel
                Room newRoom = doc.Create.NewRoom(doc.ActiveView.GenLevel, new UV(point.X, point.Y));
                if (newRoom == null)
                {
                    msg = "创建房间失败。";
                    return Result.Failed;
                }
                //5.读取房间的中心位置
                
    //简单房间只有一个实体
                GeometryObjectArray geomObjectArray = newRoom.ClosedShell.Objects;//
                GeometryObject geoObject = geomObjectArray.get_Item(0);
                Solid roomSolid = geoObject as Solid;
                //计算质心
                XYZ centriod = roomSolid.ComputeCentroid();
                //下降
                XYZ roomCenter = new XYZ(centriod.X, centriod.Y, doc.ActiveView.GenLevel.Elevation);
                //6.修改房间十字叉的位置
                LocationPoint roomLocation = newRoom.Location as LocationPoint;
                roomLocation.Point = roomCenter;
                //7.创建房间标签,放在中心
                RoomTag tag = doc.Create.NewRoomTag(newRoom, new UV(roomCenter.X, roomCenter.Y), doc.ActiveView);
                //8.赋值三个参数值,名称,用途,部门
                newRoom.get_Parameter(BuiltInParameter.ROOM_NAME).Set(roomName);
                newRoom.get_Parameter(BuiltInParameter.ROOM_DEPARTMENT).Set(roomDepartment);
                newRoom.get_Parameter(BuiltInParameter.ROOM_OCCUPANCY).Set(roomOccupancy);

                ts.Commit();
            }

            return Result.Succeeded;
        }
        public class RoomFilter : ISelectionFilter
        {

            public bool AllowElement(Element elem)
            {
                return elem is Room;
            }

            public bool AllowReference(Reference reference, XYZ position)
            {
                return true;
            }
        }
    }
    url:http://greatverve.cnblogs.com/p/CreateRoomAndCopyProperties1.html
  • 相关阅读:
    吴裕雄--天生自然 Zookeeper学习笔记--Zookeeper 权限控制 ACL
    【机器学习】机器学习基础
    【QT】利用pyqt5实现简单界面
    【Mathtype】安装Mathtype后,word无法粘贴的问题
    【优化方法】牛顿法
    博客样式设置
    2018.8.28 练习赛
    2018.8.27 练习赛
    2018.8.26 练习赛
    2018.8.25 练习赛
  • 原文地址:https://www.cnblogs.com/greatverve/p/CreateRoomAndCopyProperties1.html
Copyright © 2011-2022 走看看