應用revit api畫垂直於風管的風管示例。本站提示廣大學習愛好者:(應用revit api畫垂直於風管的風管示例)文章只能為提供參考,不一定能成為您想要的結果。以下是應用revit api畫垂直於風管的風管示例正文
/// <summary>
/// 選擇風管與風管外一點,畫與風管垂直的風管。
/// </summary>
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
UIApplication uiApp = cmdData.Application;
Document doc = uiDoc.Document;
Selection selection = uiDoc.Selection;
Transaction ts = new Transaction(doc, "http://www.jb51.net");
ts.Start();
//獲得一種風管類型
DuctType ductType = null;
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(DuctType));
foreach (Element el in collector.ToElements())
{
ductType = el as DuctType;
break;
}
//
Reference refDuct = selection.PickObject(ObjectType.Element, "選擇一根風管:");
Duct duct = doc.GetElement(refDuct) as Duct;
XYZ xyz = selection.PickPoint();//選擇一點
LocationCurve lCurve = duct.Location as LocationCurve;
IntersectionResult interResult = lCurve.Curve.Project(xyz);//點在直線上的投影
if (interResult != null)
{
doc.Create.NewDuct(xyz, interResult.XYZPoint, ductType);
}
ts.Commit();
return Result.Succeeded;
}
}