对元素的基本操作,比如镜像,偏移,移动,复制等,都是通过 ElementTransformUtils类。[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdMove : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string messages, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Transaction ts = new Transaction(uiDoc.Document, "revit.5d6d.com");
ts.Start();
//这里好像只能选择一个族实例,比如弯头,风管就不行。
Reference refelem = uiDoc.Selection.PickObject(ObjectType.Element, "选择一个元素");
Element elem = uiDoc.Document.GetElement(refelem);
//当前位置
LocationPoint elemLocation = elem.Location as LocationPoint;//familyInstance.Location;
XYZ oldPlace = elemLocation.Point;
//新位置
XYZ newPlace = new XYZ(10, 20, 30);
ElementTransformUtils.MoveElement(uiDoc.Document, elem.Id, newPlace);
//
elemLocation = elem.Location as LocationPoint;
XYZ newActual = elemLocation.Point;
string info = "Original Z location:" + oldPlace.Z
+ "\nNew Z location:" + newActual.Z;
TaskDialog.Show("revit.5d6d.com", info);
ts.Commit();
return Result.Succeeded;
}
}
|