C# revit api 在 Revit 中创建面板
C# revit api to Create panels in Revit
我是 Revit 新手 api。我想在 revit 空项目中创建一个面板。我可以创造墙壁。我想知道如何在墙上添加面板数据(螺柱、面板名称、开口等)。我也是建筑术语的新手。
这是我的代码:
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;
}
另外请建议我从哪里可以了解 revit APIS。
好吧,在尝试开始编程之前,从用户的角度理解 Revit 和 BIM 会有很大帮助,请参见。 before getting started. Then, you should work through the rest of the Revit API getting started material.
接下来,你应该自己学习how to research to find a Revit API solution。
第一步肯定是安装 RevitLookup interactive Revit BIM database exploration tool 以查看和导航元素属性和关系。
准备就绪后,您可以首先手动创建您希望在用户界面中以编程方式生成的模型。探索使用 RevitLookup 和其他工具(例如 BipChecker 和元素列表器)来发现手动过程生成的元素类型及其属性和关系。
一旦你理解了所有这些,你就可以使用 Revit 以编程方式生成相同的模型 API。
祝你好运,玩得开心!
我是 Revit 新手 api。我想在 revit 空项目中创建一个面板。我可以创造墙壁。我想知道如何在墙上添加面板数据(螺柱、面板名称、开口等)。我也是建筑术语的新手。
这是我的代码:
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;
}
另外请建议我从哪里可以了解 revit APIS。
好吧,在尝试开始编程之前,从用户的角度理解 Revit 和 BIM 会有很大帮助,请参见。 before getting started. Then, you should work through the rest of the Revit API getting started material.
接下来,你应该自己学习how to research to find a Revit API solution。
第一步肯定是安装 RevitLookup interactive Revit BIM database exploration tool 以查看和导航元素属性和关系。
准备就绪后,您可以首先手动创建您希望在用户界面中以编程方式生成的模型。探索使用 RevitLookup 和其他工具(例如 BipChecker 和元素列表器)来发现手动过程生成的元素类型及其属性和关系。
一旦你理解了所有这些,你就可以使用 Revit 以编程方式生成相同的模型 API。
祝你好运,玩得开心!