0

Im learning to create addin for revit and was trying to create using example below. So i got the code from revit api.chm, the question is how do i use it as 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;

        }
    }
Lucifer
  • 3
  • 2

1 Answers1

0

The easiest place to start is to work through the Revit API getting started material. That will lead you through the entire process step by step, including video tutorials.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17