Hi all,
I am trying to create a foundation slab according to existing room boundaries and I'm getting some wierd results.
If you look at the attached document I have included a macro for this:
Applying it to room 1 works fine
Applying to room 2 gets a funky shape
Applying to room 3 throws an error
I have included a commented out line that draws model lines and used it instead of creating slabs, it works fine for all rooms!
I don't know what am I doing wrong.
Here is my macro code:
public void floorByRoom() { Document doc = this.Document; Selection sel = this.Selection; List<ElementId> roomIdList = new List<ElementId>() ; //Checking if there is an existing selection if (sel.Elements.IsEmpty) // If no selection is present prompt for it { roomIdList.Clear(); RoomSelectionFilter gridSelFilter = new RoomSelectionFilter(doc); IList<Reference> roomRefList = sel.PickObjects(ObjectType.Element,gridSelFilter,"Select rooms"); foreach (Reference r in roomRefList){ roomIdList.Add(r.ElementId); } } else // If a selection is present filter the rooms out of it { FilteredElementCollector collector = new FilteredElementCollector(doc,sel.GetElementIds()); roomIdList=collector.OfCategory(BuiltInCategory.OST_Rooms).ToElementIds().ToList(); } // Get a floor type for floor creation FilteredElementCollector floorTypeCollector = new FilteredElementCollector(doc); floorTypeCollector.OfClass(typeof(FloorType)).OfCategory(BuiltInCategory.OST_StructuralFoundation); FloorType floorType = floorTypeCollector.FirstElement() as FloorType; Transaction t = new Transaction(doc,"Floor by rooms"); t.Start(); foreach (ElementId rmId in roomIdList) { Room rm = doc.GetElement(rmId) as Room; Parameter rmLvlParam = rm.get_Parameter("Level"); ElementId rmLvlId = rmLvlParam.AsElementId(); ElementId viewLvlId = doc.ActiveView.GenLevel.Id; if (rmLvlId==viewLvlId){ SpatialElementBoundaryOptions bo = new SpatialElementBoundaryOptions(); SketchPlane sp = doc.ActiveView.SketchPlane; CurveArray roomsCurves = new CurveArray(); // Array to hold curv data collected from room boundreis foreach (IList<Autodesk.Revit.DB.BoundarySegment> lstBs in rm.GetBoundarySegments(bo)) { foreach (Autodesk.Revit.DB.BoundarySegment bs in lstBs) { roomsCurves.Append(bs.Curve); } } // Uncomment the next line to model floor (doesnt work) //doc.Create.NewFoundationSlab(roomsCurves,floorType,doc.GetElement(viewLvlId) as Level,true,XYZ.BasisZ); foreach (Curve c in roomsCurves) doc.Create.NewModelCurve(c,sp); } } t.Commit(); } }
And after I solve this problem I want your advise on what is the appropreate method to apply an offset to the curves before creating the geometry, I have tried to use the Clipper library (http://www.angusj.com.......) and I have got some good results with rooms with straight boundary segments, but unfortunately this library does't seem to deal with arc segments.
Any suggestions are appreciated 🙂
Cheers,
Samer
Solved! Go to Solution.