
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone, I'm trying to create a plugin that will allow me to create filled regions just by selecting a face. I use Selection.PickObject(ObjectType.Face), convert that reference to a PlanarFace type, and then use PlanarFace.GetEdgesAsCurveLoops to get the collection of CurveLoops and pass that to FilledRegion.Create to create my filled region.
However it's resulting in unexpected behavior. If I click on the face of a roof surface, it creates the FilledRegion exactly over the Face like I want it to. But when I click the Face of a Family Instance, it still creates the FilledRegion- but instead of creating it over the Face of the Family Instance, it creates the instance at the Project Origin of the Document.
I attached the code below and am also including some screenshots showing the problem in action. Does anyone know how to get around this? Thanks!
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document currentDoc = uiDoc.Document;
Autodesk.Revit.DB.View currentView = uiDoc.ActiveView;
Selection sel = uiApp.ActiveUIDocument.Selection;
Transaction transaction = new Transaction(currentDoc);
Element stringFillType = new FilteredElementCollector(currentDoc)
.OfClass(typeof(FilledRegionType))
.FirstOrDefault(x => x.Name == "String 1");
transaction.Start("String fill");
Reference moduleFaceReference = sel.PickObject(ObjectType.Face);
GeometryObject geoObj = currentDoc.GetElement(moduleFaceReference).GetGeometryObjectFromReference(moduleFaceReference);
PlanarFace moduleFace = geoObj as PlanarFace;
IList<CurveLoop> faceEdges = moduleFace.GetEdgesAsCurveLoops();
FilledRegion fillRegion = FilledRegion.Create(currentDoc, stringFillType.Id, currentView.Id, faceEdges);
transaction.Commit();
Result result = Result.Succeeded;
return result;
// throw new NotImplementedException();
}
}
Solved! Go to Solution.