Revit开发之通过墙的位置线和柱子的位置点进行旋转

API提供了旋转方法来旋转一个或者几个元素,使用ElementTransformUtils类下的
void RotateElement(Document document, ElementId elementToRotate, Line axis, double angle);使用给定的轴线和角度对一个元素进行旋转
void RotateElements(Document document, ICollection<ElementId> elementsToRotate, Line axis, double angle);使用给定的轴线和角度对元素进行旋转

在旋转方法中,旋转角度是用弧度计量。

正值是围绕轴线做逆时针的旋转,负值是做顺时针旋转。

使用RotateElement和RotateElements方法对元素进行旋转时,需要注意下面几点

当旋转一个元素时,旋转轴应该是有限线段,如果是无限线作为旋转轴线,会导致旋 
转失败。
旋转轴一般要求与元素LocationCurve所在的平面垂直,否则很可能会导致旋转失败。
代码片段3-19获取了一堵墙,并创建了一条和墙位置线垂直的旋转轴,然后对这堵墙 进行了逆时针60°的旋转。

如果一个元素的Location 可以向下转型为LocationCurve或者LocationPoint,那么就可以直接旋转元素对应的曲线或者点。

如何通过墙的位置线和柱子的位置点对它们分别进行旋转,可以参考以下代码:

Document projectDoc = ActiveUIDocument.Document; 
                         
using(Transaction tran = new Transaction(projectDoc, "Rotate the wall and the column.")) 
{ 
   tran.Start(); 
                                 
   Wall wall = projectDoc.GetElement(new ElementId(184163)) as Wall; 
                                 
   XYZ aa = XYZ.Zero; 
   XYZ cc = XYZ.Zero; 
    // 通过元素的位置线来旋转元素 
   LocationCurve curve = wall.Location as LocationCurve; 
   if (null != curve) 
   { 
              Curve line = curve.Curve; 
              aa = line.GetEndPoint(0); 
              cc = new XYZ(aa.X, aa.Y, aa.Z + 10); 
              Line axis = Line.CreateBound(aa, cc); 
              curve.Rotate(axis, Math.PI / 2.0); 
   } 
                                 
   FamilyInstance column = projectDoc.GetElement(new ElementId(184150)) as FamilyInstance; 
                                 
   // 通过元素的位置点来旋转元素 
   LocationPoint point = column.Location as LocationPoint; 
   if (null != point) 
   { 
                aa = point.Point; 
                cc = new XYZ(aa.X, aa.Y, aa.Z + 10); 
                Line axis = Line.CreateBound(aa, cc); 
                point.Rotate(axis, Math.PI / 3.0); 
   } 
   tran.Commit(); 
}

=========【更多高级应用请关注公众号】========


===================================

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值