简体   繁体   English

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

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

Im learning to create addin for revit and was trying to create using example below. 我正在学习为revit创建插件,并尝试使用下面的示例创建。 So i got the code from revit api.chm, the question is how do i use it as revit Addin? 所以我从revit api.chm获得了代码,问题是我如何使用它作为revit Addin? Thanks you very much. 非常感谢你。

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;

        }
    }

The easiest place to start is to work through the Revit API getting started material . 最简单的方法是使用Revit API入门材料 That will lead you through the entire process step by step, including video tutorials. 这将引导您逐步完成整个过程,包括视频教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM