Revit二次开发之“创建直线”并显示出来

直接用NewLine();显示不了,需要一个草图平面。
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class NewLine : IExternalCommand
{
    
public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
    {

        Document doc 
= revit.Application.ActiveUIDocument.Document;
        
//需要启动一个事务
        Transaction tr = new Transaction(doc, "test");
        tr.Start();

        XYZ pt1 
= new XYZ(550);
        XYZ pt2 
= new XYZ(5100);

        Line line 
= doc.Application.Create.NewLine(pt1, pt2,true);
        XYZ origin 
= new XYZ(000);
        XYZ normal 
= new XYZ(001);

        Plane plane 
= doc.Application.Create.NewPlane(pt2.CrossProduct(pt1), pt1);//平面
        SketchPlane skplane = doc.Create.NewSketchPlane(plane);//草图平面
        ModelCurve modelcurve1 = doc.Create.NewModelCurve(line, skplane);//模型曲线

        tr.Commit();

        
return Autodesk.Revit.UI.Result.Succeeded;
    }
}
from:http://revit.5d6d.com/thread-913-1-4.html
posted @ 2011-08-05 11:51  大气象  阅读(3995)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com