dynamo作为revit的利器,相当有用。而且它里面的好多类库是revit的api里没有的,那有没有什么办法可以直接用dynamo里的类?当然有啦!
步骤:1、在二次开发的引用中,引用“ProtoGeometry.dll”这个dll文件和“LibG.Interface.dll”这两个类。这两个类在dynamo的安装文件里可以找到。按理说有更多问题可以挖掘。
2、运行插件的时候必须把dynamo给打开才可以正常运行。
示例代码:
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class DynamoCmd : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document document = commandData.Application.ActiveUIDocument.Document;
try
{
DG.Point startPoint = DG.Point.ByCoordinates(0,0,0);
DG.Point endPoint = DG.Point.ByCoordinates(1000, 0, 0);
DG.Line line = DG.Line.ByStartPointEndPoint(startPoint,endPoint);
Line revitLine= line.ToRevitType() as Line; //将Dynamo的Geometry转化为Revit的Geometry
using (Transaction transaction=new Transaction(document,"Create Line"))
{
transaction.Start();
ModelCurve modelCurve = document.Create.NewModelCurve(revitLine,
SketchPlane.Create(document, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero)));
transaction.Commit();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.StackTrace,ex.Message);
}
return Result.Succeeded;
}
}