前言
这个例子展示如何计算距离,并将距离的值设置为参数。
内容
选中球形,运行程序,会设置控制高度的参数,距离越远参数值越大。效果如下所示:
核心逻辑:
- 得到选中物体的位置
- 遍历分割表面内部的 Panel
- 计算距离并设置参数
核心代码:
// 得到选中物体的位置
LocationPoint targetLocation = targetElement.Location as LocationPoint;
// 遍历分割表面 DividedSurface ds 内部的 Panel
GridNode gn = new GridNode();
int u = 0;
while (u < ds.NumberOfUGridlines){gn.UIndex = u;int v = 0;while (v < ds.NumberOfVGridlines){gn.VIndex = v;if (ds.IsSeedNode(gn)){FamilyInstance familyinstance = ds.GetTileFamilyInstance(gn, 0);param = familyinstance.LookupParameter("Distance");LocationPoint loc = familyinstance.Location as LocationPoint;XYZ panelPoint = loc.Point;// 计算距离并设置参数double d = Math.Sqrt(Math.Pow((targetPoint.X - panelPoint.X), 2) + Math.Pow((targetPoint.Y - panelPoint.Y), 2) + Math.Pow((targetPoint.Z - panelPoint.Z), 2));param.Set(d);}v = v + 1;}u = u + 1;
}
其它
相关博客:Dynamo For Revit: DividedPath & DividedSurface 分割路径和分割表面