使用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, "//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;
}
}