简体   繁体   English

C#Revit API在Revit中创建面板

[英]C# revit api to Create panels in Revit

I am new to revit api . 我是revit api的新手。 I want to create a panel in revit empty project. 我想在revit空项目中创建一个面板。 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 . 另外,请从可以从何处了解有关revit APIS的建议。

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. 好吧,在您尝试对其进行编程之前,从用户角度了解Revit和BIM将大有帮助。 before getting started . 在开始之前 Then, you should work through the rest of the Revit API getting started material . 然后,您应该研究Revit API的其余入门资料

Next, you should learn how to research to find a Revit API solution for yourself. 接下来,您应该学习如何进行研究以找到适合自己的Revit API解决方案

The first step is always definitely to install the RevitLookup interactive Revit BIM database exploration tool to view and navigate element properties and relationships. 始终绝对要做的第一步就是安装RevitLookup交互式Revit BIM数据库浏览工具,以查看和导航元素属性和关系。

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. 使用RevitLookup和其他工具(例如BipChecker和元素列表器)进行探索,以发现手动流程及其属性和关系生成了哪种元素。

Once you understand all that, you will be all set to generate the same model programatically using the Revit API. 一旦了解了所有内容,就可以使用Revit API以编程方式生成相同的模型。

Good luck and have fun! 祝好运并玩得开心点!

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

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