Revit二次开发之“元素的移动MoveElement()”
对元素的基本操作,比如镜像,偏移,移动,复制等,都是通过ElementTransformUtils类。from:http://revit.5d6d.com/thread-1268-1-1.html
[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;
}
}
[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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。