Revit二次开发之“创建直线”并显示出来
直接用NewLine();显示不了,需要一个草图平面。
from:http://revit.5d6d.com/thread-913-1-4.html
[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(5, 5, 0);
XYZ pt2 = new XYZ(5, 10, 0);
Line line = doc.Application.Create.NewLine(pt1, pt2,true);
XYZ origin = new XYZ(0, 0, 0);
XYZ normal = new XYZ(0, 0, 1);
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;
}
}
[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(5, 5, 0);
XYZ pt2 = new XYZ(5, 10, 0);
Line line = doc.Application.Create.NewLine(pt1, pt2,true);
XYZ origin = new XYZ(0, 0, 0);
XYZ normal = new XYZ(0, 0, 1);
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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。