简体   繁体   English

访问Revit元素数据-Python Revit API

[英]Access revit element data - python revit api

I'm a little confused about how you get access to Revit's element data, such as an element's parameters, location, Id, etc.. If I have this code: 对于您如何访问Revit的元素数据(例如元素的参数,位置,ID等),我有些困惑。如果我有以下代码:

collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_Walls)
walls = collector.OfClass(FamilySymbol)
return walls

It will print: Autodesk.Revit.DB.FilteredElementCollector object at 0x0000000000000038 [Auto...]. 它将打印:0x0000000000000038 [Auto ...]上的Autodesk.Revit.DB.FilteredElementCollector对象。 Where do I go from here? 我从这里去哪里? For instance, How do I get a return of the walls' location? 例如,如何获得墙壁的位置?

There might be a lot in here, and multiple steps for each item. 这里可能有很多,每个项目都有多个步骤。 I am mainly looking for a general concept of getting and/or setting new element data. 我主要是在寻找获取和/或设置新元素数据的一般概念。

Any thoughts? 有什么想法吗?

I can't help with the Python, but I'm pretty familiar with Revit's API + C#. 我无法使用Python,但是我对Revit的API + C#非常熟悉。

You are using the collector to list all the walls on the project. 您正在使用收集器列出项目上的所有墙。 What you want (to get the locations) is the FamilyInstance objects of these walls. 您想要(获取位置)的是这些墙的FamilyInstance对象。

In C# would be something like this: 在C#中将是这样的:

new FilteredElementCollector(uidoc.Document).OfClass(FamilyInstance).ToElements();

Next, you should loop the result to get each individual Element and convert it to a Wall: 接下来,您应该循环结果以获取每个单独的元素并将其转换为Wall:

foreach (Wall i in instances)
{
   var location = i.Location as LocationCurve;

   // The Curve element is a Line - 2 points defining it's position
   var p0 = location.Curve.GetEndPoint(0);
   var p1 = location.Curve.GetEndPoint(1);
}

Most of the information you want is on this FamilyInstance Object -> http://wikihelp.autodesk.com/Revit/enu/2014/Help/3665-Developers/0074-Revit_Ge74/0083-Family_I83/0086-FamilyIn86 您想要的大多数信息都在此FamilyInstance对象上-> http://wikihelp.autodesk.com/Revit/enu/2014/Help/3665-Developers/0074-Revit_Ge74/0083-Family_I83/0086-FamilyIn86

The Revit API documentation points out that a FilteredElementCollector is an IEnumerable<Element> . Revit API文档指出, FilteredElementCollectorIEnumerable<Element> So you actually have a list of wall objects. 因此,您实际上有一个墙对象列表 I like to add these to a python list to make working with them easier: 我喜欢将它们添加到python列表中,以使其更容易使用:

walls = list(collector)

Behind the scenes, list(collector) will do something like: 在后台, list(collector)将执行以下操作:

walls = []
for w in collector:
    walls.append(w)

(note, that this is not really how it works, but sort of explains it). (请注意,这实际上并不是它的工作原理,而是对其进行了解释)。

You can use the .NET inner workings to enumerate the walls in the collector by doing this: 您可以执行以下操作,使用.NET内部工作枚举collector的墙:

enumerator = collector.GetEnumerator()
walls = []
while not enumerator.IsDone():
    walls.append(enumerator.Current)
    enumerator.MoveNext()

You will want to check if the collector.OfClass(FamilySymbol) line is correct - in my example document, that yielded an empty list - but maybe you do have walls that are FamilySymbol s... 您将要检查collector.OfClass(FamilySymbol)行是否正确-在我的示例文档中,该行生成了一个空列表-但也许您确实有使用FamilySymbol s的墙。

Next, you want to work with a wall object. 接下来,您要使用墙对象。 So, take the first wall: 因此,以第一堵墙为例:

wall = walls[0]
interior_type_parameter = wall.Parameter['Interior Type']

And then work with the parameter... If you install the Revit SDK, you will find a tool for snooping objects and finding their parameters and values. 然后使用参数...如果安装Revit SDK,您将找到一个侦听对象并查找其参数和值的工具。 Use this! 用这个! Explore! 探索! Have fun! 玩得开心!

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

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