Revit 二次开发创建房间的两种常用方法

1,使用闭合路径

 Transaction ts = new Transaction(doc, "BIM");

            ts.Start();

            try

            {

                Level level = uidoc.ActiveView.GenLevel;

                PlanTopology pt = doc.get_PlanTopology(level);

                foreach (PlanCircuit pc in pt.Circuits)

                {

                    if (!pc.IsRoomLocated)

                    {

                        Room newRoom = doc.Create.NewRoom(null, pc);

                        LinkElementId elemid = new LinkElementId(newRoom.Id);

                        Location location = newRoom.Location;

                        LocationPoint locationPoint = location as LocationPoint;

                        XYZ point3d = locationPoint.Point;

                        UV point2d = new UV(point3d.X, point3d.Y);

                        RoomTag roomTag = doc.Create.NewRoomTag(elemid, point2d, view.Id);

                        if (family != null)

                        {

                            try

                            {

                                FamilySymbol symbol = family.Document.GetElement(family.GetFamilySymbolIds().First()) as FamilySymbol;

                                if (symbol != null)

                                {

                                    roomTag.ChangeTypeId(symbol.Id);

                                }

                            }

                            catch { }

                        }

                    }

                }

 

                ts.Commit();

            }

            catch

            {

                ts.Commit();

            }

 

2,使用点 创建 发现闭合路径自动捕捉 拾取一个已存在的房间 复制属性 房间的位置 暂时不能改动

 Reference refer = uidoc.Selection.PickObject(ObjectType.Element, "");

           Room room = doc.GetElement(refer) as Room;

           string roomDepartment = room.get_Parameter(BuiltInParameter.ROOM_DEPARTMENT).AsString();

           Transaction ts = new Transaction(doc,"BIM");

           ts.Start();

           XYZ xyz = uidoc.Selection.PickPoint();

           LocationPoint roomPoint = room.Location as LocationPoint;

           Room newRoom = doc.Create.NewRoom(doc.ActiveView.GenLevel,new UV(xyz.X,xyz.Y));

           //doc.Create.NewSpace(room.Level, new UV(roomPoint.Point.X, roomPoint.Point.Y));

 

           RoomTag tag = doc.Create.NewRoomTag(new LinkElementId(newRoom.Id), new UV(xyz.X, xyz.Y), doc.ActiveView.Id);

           newRoom.get_Parameter(BuiltInParameter.ROOM_DEPARTMENT).Set(roomDepartment);

          

         

           ts.Commit();

 

3,由于房间的位置是只读的 所以放置房间时 随意选择一点创建。获得的几何中心 删除 再根据中心创建新的房间

UIDocument uidoc=commandData.Application.ActiveUIDocument;
           Document doc=uidoc.Document;

           XYZ xyz = uidoc.Selection.PickPoint();
           Solid sd = null;
           Transaction ts = new Transaction(doc,"BIM");
           ts.Start();

           Room newRoom = doc.Create.NewRoom(doc.ActiveView.GenLevel, new UV(xyz.X, xyz.Y));
        
           GeometryElement geo = newRoom.ClosedShell;
         
           foreach (GeometryObject obj in geo)
           {
               if (obj is Solid)
               {
                   Solid solid = obj as Solid;
                   if (solid != null)
                   {
                       sd = solid;
                     

                       break;
                   }

               }
           }
         
         
           XYZ Center = sd.ComputeCentroid();
           XYZ roomCenter = new XYZ(Center.X, Center.Y, doc.ActiveView.GenLevel.ProjectElevation);
           Room newRoom2 = doc.Create.NewRoom(doc.ActiveView.GenLevel, new UV(roomCenter.X, roomCenter.Y));
           RoomTag tag = doc.Create.NewRoomTag(new LinkElementId(newRoom2.Id), new UV(roomCenter.X, roomCenter.Y), doc.ActiveView.Id);
           doc.Delete(newRoom.Id);
           ts.Commit(); 

  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值