Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I am trying to divide a Floor element into several Parts using a grid that will come from an external file but I am having trouble getting it to work. Any and all help would be appreciated.
The grid file is a .txt with the starting and ending point of each line, forming a grid.
Here's the code I have so far:
// Returns the Parts' ElementIds
public List<ElementId> DivideElement(Document doc, Element floor, string grid_file)
{
List<ElementId> pieces = new List<ElementId>();
// Read coordinates from grid_file
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), grid_file);
// Method which returns tuples of origin and end coordinates for each grid line
List<Tuple<XYZ, XYZ>> grid = CreateGridLines(path);
IList<ElementId> to_divide = new List<ElementId>(1);
to_divide.Add(floor.Id);
// Grid
IList<Curve> curveArray = new List<Curve>();
foreach (Tuple<XYZ,XYZ> line_coord in grid)
{
Line line = Line.CreateBound(line_coord.Item1, line_coord.Item2);
curveArray.Add(line);
}
// Intersection ElementIds
IList<ElementId> intersectionElementIds = new List<ElementId>();
Frame frame = new Frame();
Plane plane = Plane.Create(frame);
SketchPlane divisionSketchPlane = SketchPlane.Create(doc, plane);
// commit curve array and plane
doc.Regenerate();
PartUtils.DivideParts(doc, to_divide, intersectionElementIds, curveArray, divisionSketchPlane.Id);
// get all associated parts
pieces = PartUtils.GetAssociatedParts(doc, floor.Id, true, true).ToList();
divisionSketchPlane.Dispose();
doc.Regenerate();
return pieces;
}
Thanks in advance.
Solved! Go to Solution.