Change the boundary of floors/slabs

By Joe Ye

 

Revit didn’t expose the API to edit floors/slabs boundary. Here introduce a trick to edit the boundary.

For a Revit slab or floor, there are mapping model lines to representing the boundary of tha slab. If a floor boundary has 6 segments, there are 6 corresponding model lines for this floor. When we change those model line’s position or shape, the slab or floor’s shape will be updated accordingly.

There probably are many model lines in a document. How can we find the model lines that representing the slab is the key point.

Here is the solution: You need to create a tempt transaction. During this temp transaction, delete the target slab by Document.Delete() method. This method will return all the deleted elements’ ids after the slab is deleted. So the slab’s boundary model line can be find by iterating all the return id (get the element from those ids and compare the object type if they are ModelLine class). Finally abort this temp transaction.

After get the boundary’s boundary model lines, you can change the model line’s shape by changing those ModelLine object ( use this method

LocationCurve lCurve = modelLine.Location as LocationCurve;
lCurve.Curve = newcurve.

I just did a very quick test, this works.
 
Here is the complete command code.
For simplicity, it just moves the floor by creating new boundary lines by moving the old segment.  Here suppose the segment lines are all straight lines.

[Autodesk.Revit.Attributes.Transaction(              Autodesk.Revit.Attributes.TransactionMode.Manual)]            public class ChangeFloor : IExternalCommand            {              public Autodesk.Revit.UI.Result Execute(                ExternalCommandData commandData,                ref string message,                ElementSet elements)              {                Document doc = commandData.Application.ActiveUIDocument.Document;                Autodesk.Revit.UI.Selection.Selection sel =                   commandData.Application.ActiveUIDocument.Selection;                     Reference ref1 = sel.PickObject (Autodesk.Revit.UI.Selection.ObjectType.Element,                   "Please pick a floor to edit");                Floor f = doc.GetElement(ref1) as Floor;                     Transaction transTemp = new Transaction(doc);                transTemp.Start ("tempDelete");                ICollection ids = doc.Delete(f);                transTemp.RollBack ();                     List mLines = new List();                foreach (ElementId id in ids)                {                  Element ele = doc.GetElement (id);                  if (ele is ModelLine)                  {                    mLines.Add(ele as ModelLine);                  }                }                     Transaction trans = new Transaction(doc);                trans.Start("ChangeFloor");                     //                foreach (ModelLine mline in mLines)                {                  LocationCurve lCurve = mline.Location as LocationCurve;                  Line c = lCurve.Curve as Line;                  XYZ pt1 = c.GetEndPoint(0);                  XYZ pt2 = c.GetEndPoint(1);                       Transform transform = Transform.CreateTranslation(                    new XYZ(1, 1, 0)); //move the line.                  XYZ pt1New = transform.OfPoint (pt1);                  XYZ pt2New = transform.OfPoint (pt2);                  Line newLine = Line.CreateBound(pt1New, pt2New);                  lCurve.Curve = newLine;                     }                trans.Commit ();                return Result.Succeeded;              }            }             }

Comments

2 responses to “Change the boundary of floors/slabs”

  1. Hi Joe,
    I have to split floor slab for concrete pouring sequence. They have to be separate instance in order to add poring sequence ID’s etc, also I have slab edge hosted to the slabs.
    Is it possible to split floor slab without losing hosted slab edges?
    Will this work for it. I am getting errors while running this code. What reference am I missing?
    ‘Autodesk.Revit.DB.Line’ does not contain a definition for ‘GetEndPoint’ and no extension method ‘GetEndPoint’ accepting a first argument of type ‘Autodesk.Revit.DB.Line’ could be found (are you missing a using directive or an assembly reference?)
    ‘Autodesk.Revit.DB.Transform’ does not contain a definition for ‘CreateTranslation
    ‘Autodesk.Revit.DB.Line’ does not contain a definition for ‘CreateBound

  2. Good Evening,
    this another example of brilliant coding for a problem that can only occur made by Autodesk. Destroy the object so you will get the references to the sub-objects and start working with this. Incredible.
    Thanks a lot for sharing this Joe.
    Good night from Chicago
    Christian

Leave a Reply