Beginner’s Guide to Move Point and Line Elements
This video is an example of moving point and line based Revit elements. Point based elements such as columns, doors etc. have a point with an XYZ coordinate location. This can be reassigned with “ElementTransformUtils.MoveElement(document, xyz);”. Line base elements such as walls, framing etc. have a start and end point. Begin by creating a “Line” with your new location of start XYZ and end XYZ. Once you have a line you can reassign it to your “element.Curve".
Sample code - Point Base:
Element e = SelectElement(uidoc, doc);
FamilyInstance familyInstance = e as FamilyInstance;
LocationPoint locationPoint = familyInstance.Location as LocationPoint;
XYZ currentLocation = locationPoint.Point;
XYZ newLocation = new XYZ(0, 10, 10);
using (Transaction t = new Transaction(doc, "move"))
{
t.Start("move");
ElementTransformUtils.MoveElement(doc, familyInstance.Id, newLocation);
t.Commit();
string info = "old " + currentLocation + " new " + newLocation;
TaskDialog.Show("Revit", info);
}
Sample code - Line Base:
Element e = SelectElement(uidoc, doc);
Wall wall = e as Wall;
LocationCurve wallLine = wall.Location as LocationCurve;
XYZ sXYZ = new XYZ(10, 20, 0);
XYZ eXYZ = new XYZ(20, 20, 0);
Line newWallLine = Line.CreateBound(sXYZ, eXYZ);
using (Transaction t = new Transaction(doc, "move"))
{
t.Start("move");
wallLine.Curve = newWallLine;
t.Commit();
}
Comments
Post a Comment