private void GenerateRoom(int x, int y, int radius, bool exit = false) { RoomTag typeOfRoom = RandomRoom(); switch (typeOfRoom) { case RoomTag.Square: default: GenerateSquare(x, y, radius); break; case RoomTag.Circle: GenerateCircle(x, y, radius); break; case RoomTag.Cross: GenerateCross(x, y, radius); break; case RoomTag.SquareWithCorridors: GenerateSquareWithCorridors(x, y, radius); break; } DungeonRoomManager dungeonRoom = Instantiate(roomPrefab, new Vector3(x, y, 0), Quaternion.identity, transform).GetComponent <DungeonRoomManager>(); dungeonRoom.Init(radius, wallMap, pitMap, corridorHeight, exit); rooms.Add(dungeonRoom); }
private void SetDoor(Node node, Door door, RoomTag tagSelect, Door.STATE state) { if (node.RoomTags.HasFlag(tagSelect)) { door.SetState(state); } }
/// <summary> /// Auto tag rooms with specified RoomTagType in a level /// </summary> /// <param name="level">The level where rooms will be auto tagged</param> /// <param name="tagType">The room tag type</param> public void AutoTagRooms(Level level, RoomTagType tagType) { PlanTopology planTopology = m_revit.ActiveUIDocument.Document.get_PlanTopology(level); SubTransaction subTransaction = new SubTransaction(m_revit.ActiveUIDocument.Document); subTransaction.Start(); foreach (ElementId eid in planTopology.GetRoomIds()) { Room tmpRoom = m_revit.ActiveUIDocument.Document.GetElement(eid) as Room; if (m_revit.ActiveUIDocument.Document.GetElement(tmpRoom.LevelId) != null && tmpRoom.Location != null) { // Create a specified type RoomTag to tag a room LocationPoint locationPoint = tmpRoom.Location as LocationPoint; Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV(locationPoint.Point.X, locationPoint.Point.Y); RoomTag newTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(new LinkElementId(tmpRoom.Id), point, null); newTag.RoomTagType = tagType; List <RoomTag> tagListInTheRoom = m_roomWithTags[newTag.Room.Id]; tagListInTheRoom.Add(newTag); } } subTransaction.Commit(); }
/// <summary> /// get all the rooms and room tags in the project /// </summary> private void GetAllRoomsAndTags() { // get the active document Document document = m_revit.ActiveUIDocument.Document; RoomFilter roomFilter = new RoomFilter(); RoomTagFilter roomTagFilter = new RoomTagFilter(); LogicalOrFilter orFilter = new LogicalOrFilter(roomFilter, roomTagFilter); FilteredElementIterator elementIterator = (new FilteredElementCollector(document)).WherePasses(orFilter).GetElementIterator(); elementIterator.Reset(); // try to find all the rooms and room tags in the project and add to the list while (elementIterator.MoveNext()) { object obj = elementIterator.Current; // find the rooms, skip those rooms which don't locate at Level yet. Room tmpRoom = obj as Room; if (null != tmpRoom && null != tmpRoom.Level) { m_rooms.Add(tmpRoom); continue; } // find the room tags RoomTag tmpTag = obj as RoomTag; if (null != tmpTag) { m_roomTags.Add(tmpTag); continue; } } }
/// <summary> /// 弹出配置框 /// </summary> /// <param name="ent"></param> public void SetMulFamily(FamilyEnt ent) { if (ent == null) { TaskDialog.Show("提示", "请选择族"); return; } _selFamily = ent; List <string> roomNames = new List <string>(); FilteredElementCollector collector = new FilteredElementCollector(_doc); List <Element> collection = collector.OfClass(typeof(SpatialElementTag)).ToList(); foreach (Element elem in collector) { if (elem is RoomTag) { RoomTag roomTag = elem as RoomTag; roomNames.Add(roomTag.Room.Name); } } FrmSetFamilyViewModel vm = new FrmSetFamilyViewModel(roomNames); vm.SetConfig = SetConfig; FrmSetFamilyView frm = new FrmSetFamilyView(vm); frm.ShowDialog(); }
public static List <RoomTag> GetModelRoomTags(Document doc) { List <RoomTag> roomTagList = new List <RoomTag>(); IEnumerable <SpatialElementTag> seTags = new FilteredElementCollector(doc) .OfClass(typeof(SpatialElementTag)) .Cast <SpatialElementTag>() .Where(t => !t.IsTaggingLink); foreach (SpatialElementTag set in seTags) { try { RoomTag rt = set as RoomTag; if (rt != null) { roomTagList.Add(rt); } } catch (Exception) { continue; } } return(roomTagList); }
/// <summary> /// Create a room on a given level. /// </summary> void CreateRoom( Document doc, Level level) { Application app = doc.Application; Autodesk.Revit.Creation.Application appCreation = app.Create; Autodesk.Revit.Creation.Document docCreation = doc.Create; XYZ pt1 = new XYZ(0, -5, 0); XYZ pt2 = new XYZ(0, 5, 0); XYZ pt3 = new XYZ(8, 5, 0); XYZ pt4 = new XYZ(8, -5, 0); Line line1 = Line.CreateBound(pt1, pt2); Line line2 = Line.CreateBound(pt2, pt3); Line line3 = Line.CreateBound(pt3, pt4); Line line4 = Line.CreateBound(pt4, pt1); CurveArray curveArr = new CurveArray(); curveArr.Append(line1); curveArr.Append(line2); curveArr.Append(line3); curveArr.Append(line4); docCreation.NewRoomBoundaryLines( doc.ActiveView.SketchPlane, curveArr, doc.ActiveView); // Create a new room UV tagPoint = new UV(4, 0); Room room = docCreation.NewRoom( level, tagPoint); if (null == room) { throw new Exception( "Create a new room failed."); } room.Number = "42"; room.Name = "Lobby"; // Creation.Document.NewRoomTag( Room, UV, View) is obsolete. // Use the NewRoomTag(LinkElementId, UV, ElementId) overload instead. //RoomTag tag = docCreation.NewRoomTag( room, tagPoint, doc.ActiveView ); // 2013 RoomTag tag = docCreation.NewRoomTag( new LinkElementId(room.Id), tagPoint, doc.ActiveView.Id); // 2014 }
protected override void PopulateDbRow(Element element, DataRow row) { RoomTag roomTag = element as RoomTag; Utility.Assign(row, APIObjectList.ColumnRes("ColN_CST_Id"), APIObjectList.GetIdDbValue(roomTag)); Utility.Assign(row, APIObjectList.ColumnRes("ColN_CST_RoomTagType"), APIObjectList.GetNameDbValue(APIObjectList.GetElementById(roomTag.GetTypeId()))); Utility.Assign(row, APIObjectList.ColumnRes("ColN_CST_RoomId"), APIObjectList.GetIdDbValue(roomTag.Room)); Utility.Assign(row, APIObjectList.ColumnRes("ColN_CST_ViewId"), APIObjectList.GetIdDbValue(roomTag.View)); }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="roomTag"></param> /// <returns></returns> private static Revit.Element CloneElement(Autodesk.Revit.UI.UIApplication app, Autodesk.Revit.DB.Architecture.RoomTag roomTag) { Revit.LocationPoint locationPoint = roomTag.Location as Revit.LocationPoint; UV point = new UV(locationPoint.Point.X, locationPoint.Point.Y); RoomTag roomTagClone = null;//app.ActiveUIDocument.Document.Create.NewRoomTag(roomTag.Room, ref point, ); Utils.ParamUtil.SetParameters(roomTagClone.Parameters, roomTag.Parameters); return(roomTagClone); }
/// <summary> /// 查找某一房间 /// </summary> /// <param name="doc">Revit Document</param> /// <param name="roomName">房间标记名称</param> /// <returns>返回房间标记</returns> public static RoomTag FindRoomTag(Document doc, string roomName) { FilteredElementCollector collector = new FilteredElementCollector(doc); List <Element> collection = collector.OfClass(typeof(SpatialElementTag)).ToList(); foreach (Element elem in collector) { if (elem is RoomTag) { RoomTag roomTag = elem as RoomTag; if (roomTag.Room.Name.Contains(roomName)) { return(roomTag); } } } return(null); }
/// <summary> ///constructor /// </summary> public RoomsData(ThisDocument hostAddIn, Autodesk.Revit.ApplicationServices.Application application) { m_application = application; m_thisDocument = hostAddIn; RoomFilter roomFilter = new RoomFilter(); RoomTagFilter roomTagFilter = new RoomTagFilter(); LogicalOrFilter orFilter = new LogicalOrFilter(roomFilter, roomTagFilter); FilteredElementIterator elementIterator = (new FilteredElementCollector(m_thisDocument.Document)).WherePasses(orFilter).GetElementIterator(); elementIterator.Reset(); // try to find all the rooms and room tags in the project and add to the list while (elementIterator.MoveNext()) { object obj = elementIterator.Current; // find the rooms, skip those rooms which don't locate at Level yet. Room tmpRoom = obj as Room; if (null != tmpRoom && null != tmpRoom.Level) { m_rooms.Add(tmpRoom); continue; } // find the room tags RoomTag tmpTag = obj as RoomTag; if (null != tmpTag) { m_roomTags.Add(tmpTag); continue; } } //find out the rooms that without tag ClassifyRooms(); }
/// <summary> ///constructor /// </summary> public RoomsData(ThisApplication application) { m_thisApp = application; ElementFilter filterRoom = new ElementClassFilter(typeof(SpatialElement)); FilteredElementCollector roomCollector = new FilteredElementCollector(m_thisApp.ActiveUIDocument.Document); roomCollector.WherePasses(filterRoom); foreach (Autodesk.Revit.DB.Element ee in roomCollector) { Room tmpRoom = ee as Room; if (null != tmpRoom) { m_rooms.Add(tmpRoom); continue; } } ElementFilter filterRoomTag = new ElementClassFilter(typeof(SpatialElementTag)); FilteredElementCollector roomTagCollector = new FilteredElementCollector(m_thisApp.ActiveUIDocument.Document); roomTagCollector.WherePasses(filterRoomTag); foreach (Autodesk.Revit.DB.Element ee in roomTagCollector) { // find the room tags RoomTag tmpTag = ee as RoomTag; if (null != tmpTag) { m_roomTags.Add(tmpTag); continue; } } //find out the rooms that without tag ClassifyRooms(); }
/// <summary> /// Auto tag rooms with specified RoomTagType in a level /// </summary> /// <param name="level">The level where rooms will be auto tagged</param> /// <param name="tagType">The room tag type</param> public void AutoTagRooms(Level level, RoomTagType tagType) { PlanTopology planTopology = m_revit.ActiveUIDocument.Document.get_PlanTopology(level); SubTransaction subTransaction = new SubTransaction(m_revit.ActiveUIDocument.Document); subTransaction.Start(); foreach (Room tmpRoom in planTopology.Rooms) { if (tmpRoom.Level != null && tmpRoom.Location != null) { // Create a specified type RoomTag to tag a room LocationPoint locationPoint = tmpRoom.Location as LocationPoint; Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV(locationPoint.Point.X, locationPoint.Point.Y); RoomTag newTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(tmpRoom, point, null); newTag.RoomTagType = tagType; List <RoomTag> tagListInTheRoom = m_roomWithTags[newTag.Room.Id.IntegerValue]; tagListInTheRoom.Add(newTag); } } subTransaction.Commit(); }
public static void MoveLinkTags(Document doc, RoomTag rt) { ElementClassFilter classFilter = new ElementClassFilter(typeof(SpatialElement)); ElementId roomId = rt.TaggedRoomId.LinkedElementId; //get link document ElementId rvtLinkId = rt.TaggedRoomId.LinkInstanceId; RevitLinkInstance rvtLink = new FilteredElementCollector(doc) .OfClass(typeof(RevitLinkInstance)) .Cast <RevitLinkInstance>() .Where(rv => rv.Id == rvtLinkId) .FirstOrDefault(); Document link_doc = rvtLink.GetLinkDocument(); // get room from linked document SpatialElement linkedSE = new FilteredElementCollector(link_doc) .OfCategory(BuiltInCategory.OST_Rooms) .WherePasses(classFilter) .Cast <SpatialElement>() .Where(se => se.Id == roomId) .FirstOrDefault(); Room linkedRoom = linkedSE as Room; // tag location Location tLoc = rt.Location; LocationPoint tagLoc = (LocationPoint)rt.Location; XYZ tagPoint = tagLoc.Point; // room location LocationPoint rLoc = linkedRoom.Location as LocationPoint; XYZ rPoint = rLoc.Point; // create "move vector" and move tag XYZ moveVector = new XYZ(rPoint.X - tagPoint.X, rPoint.Y - tagPoint.Y, rPoint.Z - rPoint.Z); tLoc.Move(moveVector); }
/// <summary> /// 获取当前模型指定视图内的所有最外层的墙体 /// Get all the outermost walls in the /// specified view of the current model /// </summary> /// <param name="doc"></param> /// <param name="view">视图,默认是当前激活的视图 /// View, default is currently active view</param> public static List <ElementId> GetOutermostWalls( Document doc, View view = null) { double offset = Util.MmToFoot(1000); if (view == null) { view = doc.ActiveView; } #region Obsolete code using wall location line instad of bounding box //获取顶点 最小x,最大y ; 最大x,最小y #if BEFORE_USING_BOUNDING_BOX List <Wall> wallList = new FilteredElementCollector(doc) .OfClass(typeof(Wall)) .Cast <Wall>() .ToList(); double maxX = -1D; double minX = -1D; double maxY = -1D; double minY = -1D; wallList.ForEach((wall) => { Curve curve = (wall.Location as LocationCurve).Curve; XYZ xyz1 = curve.GetEndPoint(0); XYZ xyz2 = curve.GetEndPoint(1); double _minX = Math.Min(xyz1.X, xyz2.X); double _maxX = Math.Max(xyz1.X, xyz2.X); double _minY = Math.Min(xyz1.Y, xyz2.Y); double _maxY = Math.Max(xyz1.Y, xyz2.Y); if (curve.IsCyclic) { Arc arc = curve as Arc; double _radius = arc.Radius; //粗略对x和y 加/减 _maxX += _radius; _minX -= _radius; _maxY += _radius; _minY += _radius; } if (minX == -1) { minX = _minX; } if (maxX == -1) { maxX = _maxX; } if (maxY == -1) { maxY = _maxY; } if (minY == -1) { minY = _minY; } if (_minX < minX) { minX = _minX; } if (_maxX > maxX) { maxX = _maxX; } if (_maxY > maxY) { maxY = _maxY; } if (_minY < minY) { minY = _minY; } }); double minX = bb.Min.X - offset; double maxX = bb.Max.X + offset; double minY = bb.Min.Y - offset; double maxY = bb.Max.Y + offset; CurveArray curves = new CurveArray(); Line line1 = Line.CreateBound(new XYZ(minX, maxY, 0), new XYZ(maxX, maxY, 0)); Line line2 = Line.CreateBound(new XYZ(maxX, maxY, 0), new XYZ(maxX, minY, 0)); Line line3 = Line.CreateBound(new XYZ(maxX, minY, 0), new XYZ(minX, minY, 0)); Line line4 = Line.CreateBound(new XYZ(minX, minY, 0), new XYZ(minX, maxY, 0)); curves.Append(line1); curves.Append(line2); curves.Append(line3); curves.Append(line4); #endif // BEFORE_USING_BOUNDING_BOX #endregion // Obsolete code using wall location line instad of bounding box BoundingBoxXYZ bb = GetBoundingBoxAroundAllWalls( doc, view); XYZ voffset = offset * (XYZ.BasisX + XYZ.BasisY); bb.Min -= voffset; bb.Max += voffset; XYZ[] bottom_corners = Util.GetBottomCorners( bb, 0); CurveArray curves = new CurveArray(); for (int i = 0; i < 4; ++i) { int j = i < 3 ? i + 1 : 0; curves.Append(Line.CreateBound( bottom_corners[i], bottom_corners[j])); } using (TransactionGroup group = new TransactionGroup(doc)) { Room newRoom = null; group.Start("Find Outermost Walls"); using (Transaction transaction = new Transaction(doc)) { transaction.Start( "Create New Room Boundary Lines"); SketchPlane sketchPlane = SketchPlane.Create( doc, view.GenLevel.Id); ModelCurveArray modelCaRoomBoundaryLines = doc.Create.NewRoomBoundaryLines( sketchPlane, curves, view); // 创建房间的坐标点 -- Create room coordinates double d = Util.MmToFoot(600); UV point = new UV(bb.Min.X + d, bb.Min.Y + d); // 根据选中点,创建房间 当前视图的楼层 doc.ActiveView.GenLevel // Create room at selected point on the current view level newRoom = doc.Create.NewRoom(view.GenLevel, point); if (newRoom == null) { string msg = "创建房间失败。"; TaskDialog.Show("xx", msg); transaction.RollBack(); return(null); } RoomTag tag = doc.Create.NewRoomTag( new LinkElementId(newRoom.Id), point, view.Id); transaction.Commit(); } //获取房间的墙体 -- Get the room walls List <ElementId> ids = RetrieveWallsGeneratingRoomBoundaries( doc, newRoom); group.RollBack(); // 撤销 return(ids); } }
public void AddFlag(RoomTag tag) { RoomTags |= tag; }
/// <summary> /// /// </summary> /// <param name="app"></param> /// <param name="element"></param> /// <returns></returns> public static Revit.Element CloneElement(Application app, Revit.Element element) { Opening opening = element as Opening; if (opening != null) { return(CloneElement(app, opening)); } BoundaryConditions boundaryConditions = element as BoundaryConditions; if (boundaryConditions != null) { return(CloneElement(app, boundaryConditions)); } AreaLoad areaLoad = element as AreaLoad; if (areaLoad != null) { return(CloneElement(app, areaLoad)); } AreaReinforcement areaReinforcement = element as AreaReinforcement; if (areaReinforcement != null) { return(CloneElement(app, areaReinforcement)); } BeamSystem beamSystem = element as BeamSystem; if (beamSystem != null) { return(CloneElement(app, beamSystem)); } Dimension dimension = element as Dimension; if (dimension != null) { return(CloneElement(app, dimension)); } FamilyInstance familyInstance = element as FamilyInstance; if (familyInstance != null) { return(CloneElement(app, familyInstance)); } Floor floor = element as Floor; if (floor != null) { return(CloneElement(app, floor)); } Grid grid = element as Grid; if (grid != null) { return(CloneElement(app, grid)); } Group group = element as Group; if (group != null) { return(CloneElement(app, group)); } Level level = element as Level; if (floor != null) { return(CloneElement(app, floor)); } LineLoad lineLoad = element as LineLoad; if (lineLoad != null) { return(CloneElement(app, lineLoad)); } LoadCase loadCase = element as LoadCase; if (loadCase != null) { return(CloneElement(app, loadCase)); } LoadCombination loadCombination = element as LoadCombination; if (loadCombination != null) { return(CloneElement(app, loadCombination)); } LoadNature loadNature = element as LoadNature; if (loadNature != null) { return(CloneElement(app, loadNature)); } LoadUsage loadUsage = element as LoadUsage; if (loadUsage != null) { return(CloneElement(app, loadUsage)); } ModelCurve modelCurve = element as ModelCurve; if (modelCurve != null) { return(CloneElement(app, modelCurve)); } PointLoad pointLoad = element as PointLoad; if (pointLoad != null) { return(CloneElement(app, pointLoad)); } Rebar rebar = element as Rebar; if (rebar != null) { return(CloneElement(app, rebar)); } ReferencePlane referencePlane = element as ReferencePlane; if (referencePlane != null) { return(CloneElement(app, referencePlane)); } Room room = element as Room; if (room != null) { return(CloneElement(app, room)); } RoomTag roomTag = element as RoomTag; if (roomTag != null) { return(CloneElement(app, roomTag)); } SketchPlane sketchPlane = element as SketchPlane; if (sketchPlane != null) { return(CloneElement(app, sketchPlane)); } View3D view3D = element as View3D; if (view3D != null) { return(CloneElement(app, view3D)); } ViewDrafting viewDrafting = element as ViewDrafting; if (viewDrafting != null) { return(CloneElement(app, viewDrafting)); } ViewSection viewSection = element as ViewSection; if (viewSection != null) { return(CloneElement(app, viewSection)); } ViewSheet viewSheet = element as ViewSheet; if (viewSheet != null) { return(CloneElement(app, viewSheet)); } Wall wall = element as Wall; if (wall != null) { return(CloneElement(app, wall)); } // this element has not yet been exposed in the Creation Document class //Debug.Assert(false); return(null); }
public void RemoveFlag(RoomTag tag) { RoomTags &= ~tag; }
private void Stream( ArrayList data, RoomTag roomTag ) { data.Add( new Snoop.Data.ClassSeparator( typeof( RoomTag ) ) ); data.Add( new Snoop.Data.Bool( "Leader", roomTag.HasLeader ) ); data.Add( new Snoop.Data.Object( "Location", roomTag.Location ) ); data.Add( new Snoop.Data.Object( "Room", roomTag.Room ) ); data.Add( new Snoop.Data.Object( "Room tag type", roomTag.RoomTagType ) ); data.Add( new Snoop.Data.Object( "View", roomTag.View ) ); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { try { WaitCursor waitCursor = new WaitCursor(); UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; Autodesk.Revit.Creation.Application createApp = app.Application.Create; Autodesk.Revit.Creation.Document createDoc = doc.Create; using (Transaction t = new Transaction(doc)) { t.Start("Create Little House"); // Determine the four corners of the rectangular house: double width = 7 * LabConstants.MeterToFeet; double depth = 4 * LabConstants.MeterToFeet; List <XYZ> corners = new List <XYZ>(4); corners.Add(XYZ.Zero); corners.Add(new XYZ(width, 0, 0)); corners.Add(new XYZ(width, depth, 0)); corners.Add(new XYZ(0, depth, 0)); #region Test creating two levels #if CREATE_TWO_LEVELS Level levelBottom = null; Level levelMiddle = null; Level levelTop = null; List <Element> levels = new List <Element>(); Filter filterType = createApp.Filter.NewTypeFilter( typeof(Level)); doc.get_Elements(filterType, levels); foreach (Element e in levels) { if (null == levelBottom) { levelBottom = e as Level; } else if (null == levelMiddle) { levelMiddle = e as Level; } else if (null == levelTop) { levelTop = e as Level; } else { break; } } BuiltInParameter topLevelParam = BuiltInParameter.WALL_HEIGHT_TYPE; Line line; Wall wall; Parameter param; ElementId topId = levelMiddle.Id; List <Wall> walls = new List <Wall>(8); for (int i = 0; i < 4; ++i) { line = createApp.NewLineBound( corners[i], corners[3 == i ? 0 : i + 1]); wall = createDoc.NewWall( line, levelBottom, false); param = wall.get_Parameter(topLevelParam); param.Set(ref topId); walls.Add(wall); } topId = levelTop.Id; for (int i = 0; i < 4; ++i) { line = createApp.NewLineBound( corners[i], corners[3 == i ? 0 : i + 1]); wall = createDoc.NewWall( line, levelMiddle, false); param = wall.get_Parameter(topLevelParam); param.Set(ref topId); walls.Add(wall); } List <Element> doorSymbols = LabUtils.GetAllFamilySymbols( app, BuiltInCategory.OST_Doors); Debug.Assert( 0 < doorSymbols.Count, "expected at least one door symbol" + " to be loaded into project"); FamilySymbol door = doorSymbols[0] as FamilySymbol; XYZ midpoint = LabUtils.Midpoint( corners[0], corners[1]); FamilyInstance inst0 = createDoc.NewFamilyInstance( midpoint, door, walls[0], levelBottom, StructuralType.NonStructural); midpoint.Z = levelMiddle.Elevation; FamilyInstance inst1 = createDoc.NewFamilyInstance( midpoint, door, walls[4], levelMiddle, StructuralType.NonStructural); #endif // CREATE_TWO_LEVELS #endregion // Test creating two levels // Determine the levels where the walls will be located: Level levelBottom = null; Level levelTop = null; if (!LabUtils.GetBottomAndTopLevels(doc, ref levelBottom, ref levelTop)) { message = "Unable to determine wall bottom and top levels"; return(Result.Failed); } Debug.Print(string.Format("Drawing walls on '{0}' up to '{1}'", levelBottom.Name, levelTop.Name)); // Create the walls: BuiltInParameter topLevelParam = BuiltInParameter.WALL_HEIGHT_TYPE; ElementId levelBottomId = levelBottom.Id; ElementId topLevelId = levelTop.Id; List <Wall> walls = new List <Wall>(4); for (int i = 0; i < 4; ++i) { Line line = Line.CreateBound(corners[i], corners[3 == i ? 0 : i + 1]); //Wall wall = createDoc.NewWall( line, levelBottom, false ); // 2012 Wall wall = Wall.Create(doc, line, levelBottomId, false); // 2013 Parameter param = wall.get_Parameter(topLevelParam); param.Set(topLevelId); walls.Add(wall); } // Determine wall thickness for tag offset and profile growth: //double wallThickness = walls[0].WallType.CompoundStructure.Layers.get_Item( 0 ).Thickness; // 2011 //double wallThickness = walls[0].WallType.GetCompoundStructure().GetLayers()[0].Width; // 2012 double wallThickness = walls[0].WallType.Width; // simpler and more direct property available in 2012 // Add door and windows to the first wall; // note that the NewFamilyInstance() api method does not automatically add door // and window tags, like the ui command does. we add tags here by making additional calls // to NewTag(): FamilySymbol door = LabUtils.GetFirstFamilySymbol(doc, BuiltInCategory.OST_Doors); if (null == door) { LabUtils.InfoMsg("No door symbol found."); return(Result.Failed); } FamilySymbol window = LabUtils.GetFirstFamilySymbol( doc, BuiltInCategory.OST_Windows); if (null == window) { LabUtils.InfoMsg("No window symbol found."); return(Result.Failed); } XYZ midpoint = LabUtils.Midpoint(corners[0], corners[1]); XYZ p = LabUtils.Midpoint(corners[0], midpoint); XYZ q = LabUtils.Midpoint(midpoint, corners[1]); double tagOffset = 3 * wallThickness; //double windowHeight = 1 * LabConstants.MeterToFeet; double windowHeight = levelBottom.Elevation + 0.3 * ( levelTop.Elevation - levelBottom.Elevation); p = new XYZ(p.X, p.Y, windowHeight); q = new XYZ(q.X, q.Y, windowHeight); View view = doc.ActiveView; door.Activate(); // 2016 FamilyInstance inst = createDoc.NewFamilyInstance( midpoint, door, walls[0], levelBottom, StructuralType.NonStructural); midpoint += tagOffset * XYZ.BasisY; //IndependentTag tag = createDoc.NewTag( // view, inst, false, TagMode.TM_ADDBY_CATEGORY, // TagOrientation.Horizontal, midpoint ); // 2017 IndependentTag tag = IndependentTag.Create( doc, view.Id, new Reference(inst), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, midpoint); // 2018 IList <FamilyPointPlacementReference> fpprefs = inst.GetFamilyPointPlacementReferences(); IList <Reference> refs = inst.GetReferences(FamilyInstanceReferenceType.CenterLeftRight); //IndependentTag tag = IndependentTag.Create( doc, // view.Id, refs[0], false, TagMode.TM_ADDBY_CATEGORY, // TagOrientation.Horizontal, midpoint ); // 2018 window.Activate(); // 2016 inst = createDoc.NewFamilyInstance(p, window, walls[0], levelBottom, StructuralType.NonStructural); p += tagOffset * XYZ.BasisY; //tag = createDoc.NewTag( view, inst, // false, TagMode.TM_ADDBY_CATEGORY, // TagOrientation.Horizontal, p ); // 2017 tag = IndependentTag.Create( doc, view.Id, new Reference(inst), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, p); // 2018 inst = createDoc.NewFamilyInstance(q, window, walls[0], levelBottom, StructuralType.NonStructural); q += tagOffset * XYZ.BasisY; //tag = createDoc.NewTag( view, inst, // false, TagMode.TM_ADDBY_CATEGORY, // TagOrientation.TAG_HORIZONTAL, q ); // 2011 //tag = createDoc.NewTag( view, inst, // false, TagMode.TM_ADDBY_CATEGORY, // TagOrientation.Horizontal, q ); // 2012 tag = IndependentTag.Create( doc, view.Id, new Reference(inst), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, p); // 2018 // Grow the profile out by half the wall thickness, // so the floor and roof do not stop halfway through the wall: double w = 0.5 * wallThickness; corners[0] -= w * (XYZ.BasisX + XYZ.BasisY); corners[1] += w * (XYZ.BasisX - XYZ.BasisY); corners[2] += w * (XYZ.BasisX + XYZ.BasisY); corners[3] -= w * (XYZ.BasisX - XYZ.BasisY); CurveArray profile = new CurveArray(); for (int i = 0; i < 4; ++i) { //Line line = createApp.NewLineBound( // 2013 Line line = Line.CreateBound( // 2014 corners[i], corners[3 == i ? 0 : i + 1]); profile.Append(line); } // Add a floor, a roof and the roof slope: bool structural = false; Floor floor = createDoc.NewFloor( profile, structural); List <Element> roofTypes = new List <Element>( LabUtils.GetElementsOfType( doc, typeof(RoofType), BuiltInCategory.OST_Roofs)); Debug.Assert(0 < roofTypes.Count, "expected at least one roof type" + " to be loaded into project"); // Ensure that we get a valid roof type. // In Revit 2013, the first one encountered // is sloped glazing with zero entries in // its compound layers; actually, the entire // compound structure is null: //RoofType roofType = null; //foreach( RoofType rt in roofTypes ) //{ // CompoundStructure cs = rt.GetCompoundStructure(); // if( null != cs // && 0 < cs.GetLayers().Count ) // { // roofType = rt; // break; // } //} RoofType roofType = roofTypes .Cast <RoofType>() .FirstOrDefault <RoofType>(typ => null != typ.GetCompoundStructure()); ModelCurveArray modelCurves = new ModelCurveArray(); FootPrintRoof roof = createDoc.NewFootPrintRoof(profile, levelTop, roofType, out modelCurves); // Regenerate the model after roof creation, // otherwise the calls to set_DefinesSlope and // set_SlopeAngle throw the exception "Unable // to access curves from the roof sketch." doc.Regenerate(); // The argument to set_SlopeAngle is NOT an // angle, it is really a slope, i.e. relation // of height to distance, e.g. 0.5 = 6" / 12", // 0.75 = 9" / 12", etc. double slope = 0.3; foreach (ModelCurve curve in modelCurves) { roof.set_DefinesSlope(curve, true); roof.set_SlopeAngle(curve, slope); } // Add a room and a room tag: Room room = createDoc.NewRoom(levelBottom, new UV(0.5 * width, 0.5 * depth)); //RoomTag roomTag = createDoc.NewRoomTag( // room, new UV( 0.5 * width, 0.7 * depth ), // null ); // 2014 RoomTag roomTag = createDoc.NewRoomTag( new LinkElementId(room.Id), new UV(0.5 * width, 0.7 * depth), null); // 2015 //doc.AutoJoinElements(); // todo: remove this, the transaction should perform this automatically //LabUtils.InfoMsg( "Little house was created successfully." ); //#region Test setting BaseOffset and LimitOffset //// 11334196 [Failed to set Room.BaseOffset and Room.LimitOffset properties] //double h = 0.123; //room.BaseOffset = -h; //room.LimitOffset = h + h; //#endregion // Test setting BaseOffset and LimitOffset t.Commit(); return(Result.Succeeded); } } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
private GameObject CheckIsGoodRoom(Node node, RoomSettings roomS, RoomTag roomTag) { return(node.RoomTags.HasFlag(roomTag) ? roomS.Room : null); }
public void SetFlag(RoomTag tag) { RoomTags = tag; }
/// <summary> /// 按配置放置族 /// </summary> /// <param name="ent"></param> public void SetConfig(SetConfigEnt ent) { if (_selFamily == null) { return; } try { Family family = FindAndLoadFamily(_doc, _selFamily); //创建族实例 FamilySymbol fSymbol = null; ISet <ElementId> idSet = family.GetFamilySymbolIds(); if (idSet.Count > 0) { fSymbol = _doc.GetElement(idSet.ElementAt <ElementId>(0)) as FamilySymbol; if (!fSymbol.IsActive) { fSymbol.Activate(); } //获取实例参数 FamilyInstance instance = _doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), fSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); string len = instance.LookupParameter("长度").AsValueString(); string wid = instance.LookupParameter("宽度").AsValueString(); string hei = instance.LookupParameter("高度").AsValueString(); double length = double.Parse(len); double width = double.Parse(wid); double height = double.Parse(hei); _doc.Delete(instance.Id); RoomTag rmtag = FindRoomTag(_doc, ent.RoomName); Room room = rmtag.Room; BoundingBoxXYZ boundingBoxXYZ = room.get_BoundingBox(_doc.ActiveView); XYZ minPoint = boundingBoxXYZ.Min; XYZ maxPoint = boundingBoxXYZ.Max; XYZ minp = AUnit.FT2MM(minPoint); XYZ maxp = AUnit.FT2MM(maxPoint); var roomLength = maxp.X - minp.X; //房间长度 var roomWidth = maxp.Y - minp.Y; //房间宽度 double lenCount = Math.Floor(roomLength / length); double widCount = Math.Floor(roomWidth / width); if (ent.Num > lenCount * widCount) { TaskDialog.Show("提示", "当前房间仅能摆放此族" + lenCount * widCount + "个"); return; } if (ent.Direction == "横向") { double allCount = Math.Ceiling(ent.Num / lenCount); for (int i = 1; i <= allCount; i++) { double y = 0; if (i == 1) { y = width / 2; } else { y = width * i - width / 2; } for (int j = 1; j <= lenCount; j++) { if (i * j > ent.Num) { break; } double x = 0; if (j == 1) { x = length / 2; } else { x = length * j - length / 2; } XYZ point = minp + new XYZ(x, y, 0); point = AUnit.MM2FT(point); //创建族实例 FamilyInstance fi = _doc.Create.NewFamilyInstance(point, fSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } } else if (ent.Direction == "纵向") { double allCount = Math.Ceiling(ent.Num / widCount); for (int i = 1; i <= allCount; i++) { double x = 0; if (i == 1) { x = length / 2; } else { x = length * i - length / 2; } for (int j = 1; j <= widCount; j++) { if (i * j > ent.Num) { break; } double y = 0; if (j == 1) { y = width / 2; } else { y = width * j - width / 2; } XYZ point = minp + new XYZ(x, y, 0); point = AUnit.MM2FT(point); //创建族实例 FamilyInstance fi = _doc.Create.NewFamilyInstance(point, fSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); } } } } } catch (Exception ex) { TaskDialog.Show("错误", ex.Message); return; } TaskDialog.Show("提示", "创建成功"); }