如何使用 Revit SDK 示例创建 revit-addon?

How to use Revit SDK example in creating revit-addon?

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

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;

        }
    }

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