Revit二次开发——怎样使用dynamo的类

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

 

  • 3
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值