EaBIM
标题: 元素的移动MoveElement() [打印本页]
作者: 萧闫子 时间: 2014-1-9 13:02
标题: 元素的移动MoveElement()
对元素的基本操作,比如镜像,偏移,移动,复制等,都是通过
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;
}
}
作者: missyou_n2bW7 时间: 2018-4-10 14:17
谢谢老大学习了,谢谢分享
欢迎光临 EaBIM (https://eabim.net/) |
Powered by Discuz! X3.2 |