1

I am new to revit api . I want to create a panel in revit empty project. I can create walls . I want to know how can I add panel data (studs , panel name , openings etc ) in the wall . Also I am new to construction terminologies.

here is my code:

        UIApplication uiapp = commandData.Application;
        UIDocument uidoc = uiapp.ActiveUIDocument;
        Document doc = uiapp.ActiveUIDocument.Document;

        WallType w = getWallType(doc);

        RetrievingLevels(doc);

        Level newLevel = CreateLevels(doc);
        if(newLevel != null)
        {
            IList<Curve> curves = new List<Curve>();

            XYZ first = new XYZ(0, 0, 0);
            XYZ second = new XYZ(20, 0, 0);
            XYZ third = new XYZ(20, 0, 15);
            XYZ fourth = new XYZ(0, 0, 15);

            curves.Add(Line.CreateBound(first, second));
            curves.Add(Line.CreateBound(second, third));
            curves.Add(Line.CreateBound(third, fourth));
            curves.Add(Line.CreateBound(fourth, first));

            //Line l = Line.CreateBound(a1, b1);

            Transaction trans = new Transaction(doc);
            try
            {
                trans.Start("create walls");
                Wall.Create(doc, curves, w.Id,newLevel.Id,  true);
                trans.Commit();
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                trans.Dispose();
                return Result.Failed;
            }
        }
        return Result.Failed;
        //IList<Curve> curves = new List<Curve>();
    }

    private WallType getWallType(Document doc)
    {
        FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(WallType));
        IList<Element> WallTypes = collector.ToElements();
        return WallTypes.First() as WallType;
    }

    private Level CreateLevels(Document document)
    {
        double elevation = 33.0;

        Transaction t = new Transaction(document);
        // Begin to create a level
        t.Start("create Level");
        try
        {
            Level level = Level.Create(document, elevation);



            if (null == level)
            {
                throw new Exception("Create a new level failed.");
            }
            // Change the level name
            level.Name = "New level";
            t.Commit();
            return level;
        }
        catch (Exception e)
        {

        }
        return null;
    }

Also please suggest me from where can I learn about revit APIS .

1 Answer 1

0

Well, it will help a lot to understand Revit and BIM from a user point of view before you try to start programming it, cf. before getting started. Then, you should work through the rest of the Revit API getting started material.

Next, you should learn how to research to find a Revit API solution for yourself.

The first step is always definitely to install the RevitLookup interactive Revit BIM database exploration tool to view and navigate element properties and relationships.

With that in place, you can start by manually creating the model that you wish to generate programmatically in the user interface first. Explore that using RevitLookup and other tools such as BipChecker and the element lister to discover what kind of elements have been generated by the manual process and their properties and relationships.

Once you understand all that, you will be all set to generate the same model programatically using the Revit API.

Good luck and have fun!

2
  • Thanks Jeremy. These links are helping me a lot. But its taking time and I am stuck in a problem which require urgent solution. Which is i need to create panels in my empty project. If you can help me with that. Thank you again Mar 25, 2019 at 6:37
  • The approach to research and solve a Revit API programming task always follows the same steps: implement the desired result manually in the user interface first; analyse the result from a programmatic point of vie, e.g., using RevitLookup; determine what elements, properties and relationships are generated by the manual construction; recreate the same programmatically, cf. thebuildingcoder.typepad.com/blog/2017/01/… Mar 26, 2019 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.