Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have done several searches about it, but the information found does not work correctly.
What I am looking to achieve is to select a floor (INITIAL FLOOR) and a reference plane and that this plane allows the floor to be divided into 2 instances (FLOOR A AND FLOOR B).
The reason I need this is to model certain projects much faster, for this reason it does not work for me to do it using parts.
I share down below the code.... I already did a Dynamo Script using Python and it works preaty well, but for security reasons we have to convert it into C#.
using Autodesk.Revit.Attributes
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace YourNamespace
{
[Transaction(TransactionMode.Manual)]
public class FloorCutter : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// Get the Revit document and UI application
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
// Prompt the user to select the floor to cut
Reference floorRef = uiDoc.Selection.PickObject(ObjectType.Element, new FloorSelectionFilter(), "Select floor to cut");
Element floor = doc.GetElement(floorRef);
// Prompt the user to select the reference plane
Reference planeRef = uiDoc.Selection.PickObject(ObjectType.Plane, "Select reference plane");
SketchPlane plane = doc.GetElement(planeRef) as SketchPlane;
// Create a plane object from the reference plane
Plane cuttingPlane = plane.GetPlane();
// Get the geometry of the floor
GeometryElement geom = floor.get_Geometry(new Options());
// Loop through the geometry objects and find the floor slab
foreach (GeometryObject obj in geom)
{
Solid solid = obj as Solid;
if (solid != null && solid.Volume > 0)
{
// Split the floor at the cutting plane
Face face = FindSplittingFace(solid, cuttingPlane);
Solid[] splitSolids = solid.Split(face);
// Create a new floor from the split solids
foreach (Solid splitSolid in splitSolids)
{
if (splitSolid.Volume > 0)
{
Floor newFloor = Floor.Create(doc, floor.GetTypeId(), floor.LevelId, splitSolid);
newFloor.Name = floor.Name + " (cut)";
}
}
}
}
return Result.Succeeded;
}
private Face FindSplittingFace(Solid solid, Plane plane)
{
// Find the face of the solid that intersects with the cutting plane
foreach (Face face in solid.Faces)
{
if (face.Intersect(plane) == SetComparisonResult.Overlap)
{
return face;
}
}
return null;
}
}
public class FloorSelectionFilter : ISelectionFilter
{
public bool AllowElement(Element element)
{
return element is Floor;
}
public bool AllowReference(Reference reference, XYZ position)
{
return false;
}
}
}
;
Thank you very much in advance
Solved! Go to Solution.