Revit API 开发 (6): 构件的移动旋转操作 - ElementTransformUtils Class

摘要

通过 Revit API 来对模型中的构件进行移动和旋转等操作是一个非常基本的需求。Revit API 当然也提供了这个功能,并且把它打包在一个类中,方便开发者使用。这个类就是 ElementTransformUtils

细节

先从一个例子开始,然后介绍类 ElementTransformUtils

例子

可以直接打开 Revit 的“宏”这项功能,把下面这段代码贴上去,编译完成之后,就可以使用了。他们分别完成了移动和旋转的功能:ElementTransformUtils.MoveElementElementTransformUtils.RotateElement

public void MoveElement()
{
	Reference refer = Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);
	Transaction tran = new Transaction(Document, "Move Element");
	tran.Start();
	ElementTransformUtils.MoveElement(Document, refer.ElementId, new XYZ(10, 10, 10));
	tran.Commit();
}

public void rotateElement()
{
	Reference refer = Application.ActiveUIDocument.Selection.PickObject(ObjectType.Element);
	Line zAxis = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 0, 1));
	Transaction tran = new Transaction(Document, "Move Element");
	tran.Start();
	ElementTransformUtils.RotateElement(Document, refer.ElementId, zAxis, 90);
	tran.Commit();
}

ElementTransformUtils

可以实现四种操作:

名称 接口
复制 ElementTransformUtils::CopyElement(s)
镜像 ElementTransformUtils::MirrorElement(s)
移动 ElementTransformUtils::MoveElement(s)
旋转 ElementTransformUtils::RotateElement(s)

每种操作都是大同小异,并且都会对文档进行修改。

发布了33 篇原创文章 · 获赞 12 · 访问量 9579

猜你喜欢

转载自blog.csdn.net/weixin_44153630/article/details/103884784
今日推荐