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();