欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用revit api画垂直于风管的风管示例

程序员文章站 2023-12-20 12:11:46
复制代码 代码如下:/// /// 选择风管与风管外一点,画与风管垂直的风管。/// [transaction...

复制代码 代码如下:

/// <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;
    }
}

上一篇:

下一篇: