批量旋转所使用的ISET<ElementId>中的元素是ElementInstance的Id,使用Family或FamilySymbol均不可以

 1 public static void SelectionFamily(Autodesk.Revit.DB.Document document,XYZ p1,double rotating, ISet<ElementId> elementIds)
 2 {
 3     Transaction transaction = new Transaction(document);
 4 
 5     transaction.Start("旋转");
 6 
 7     XYZ p2 = new XYZ(p1.X, p1.Y, 100);
 8 
 9     //创建旋转轴
10     Line line = Line.CreateBound(p1, p2);  
11 
12     foreach (ElementId id in elementIds)
13     {
14         FamilyInstanceFilter familyInstanceFilter = new FamilyInstanceFilter(document, id);
15         FilteredElementCollector elements = new FilteredElementCollector(document);
16         elements = elements.WherePasses(familyInstanceFilter);
17         elements.Distinct();
18         foreach (FamilyInstance element in elements)
19         {
20             ElementTransformUtils.RotateElement(document, element.Id, line, rotating);
21 
22         }
23 
24     }
25     transaction.Commit();
26 }

困扰我的最大问题就是旋转角度,测试了好几个小时终于在无意中发现使用的角度为弧度制;

public static double rotating(UIDocument uiDocument, double[] p1)
{
    MessageBox.Show("选择方向点");

    XYZ p2 = Grid(uiDocument);
  // 此处P1获得的坐标被我换算成了mm,所以此处/304.8在换算成英尺,单位统一后计算
  //Atan2是反三角函数,返回的是弧度制的角度
  
double angleOfLine = Math.Atan2(p2.Y-p1[1]/304.8,p2.X - p1[0]/304.8); return angleOfLine; }

 

版权声明:本文为xt112233原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xt112233/p/9877068.html