【问题标题】:How to use Revit SDK example in creating revit-addon?如何使用 Revit SDK 示例创建 revit-addon?
【发布时间】:2019-08-14 10:12:48
【问题描述】:

我正在学习为 revit 创建插件,并尝试使用下面的示例进行创建。所以我从 revit api.chm 获得了代码,问题是我如何将它用作 revit Addin?非常感谢。

namespace somenamespace
{
    [TransactionAttribute(TransactionMode.Manual)]
    public class CreateFloor : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get UIDocument
            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            //Get Document
            Autodesk.Revit.DB.Document doc = uidoc.Document;

            Floor CreateFloor(UIApplication application, Level level)
            {
                // Get the Revit document
                Autodesk.Revit.DB.Document document = application.ActiveUIDocument.Document;

                // Get the application creation object
                Autodesk.Revit.Creation.Application appCreation = application.Application.Create;

                // Get a floor type for floor creation
                FilteredElementCollector collector = new FilteredElementCollector(document);
                collector.OfClass(typeof(FloorType));
                FloorType floorType = collector.FirstElement() as FloorType;

                // Build a floor profile for the floor creation
                XYZ first = new XYZ(0, 0, 0);
                XYZ second = new XYZ(20, 0, 0);
                XYZ third = new XYZ(20, 15, 0);
                XYZ fourth = new XYZ(0, 15, 0);
                CurveArray profile = new CurveArray();
                profile.Append(Line.CreateBound(first, second));
                profile.Append(Line.CreateBound(second, third));
                profile.Append(Line.CreateBound(third, fourth));
                profile.Append(Line.CreateBound(fourth, first));

                // The normal vector (0,0,1) that must be perpendicular to the profile.
                XYZ normal = XYZ.BasisZ;

                return document.Create.NewFloor(profile, floorType, level, true, normal);
            }

            return Result.Succeeded;

        }
    }

【问题讨论】:

    标签: c# revit-api


    【解决方案1】:

    最简单的起点是通过Revit API getting started material 开始工作。这将引导您逐步完成整个过程,包括视频教程。

    【讨论】:

      猜你喜欢
      • 2019-08-06
      • 2019-05-01
      • 1970-01-01
      • 2021-06-01
      • 2019-10-17
      • 2013-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多