简体   繁体   English

如何在 Revit Api 的 IronPython 中从 Elements ID 中创建列表

[英]How to make a list from Elements ID's in IronPython in Revit Api

I am trying to make a python list with the selected elements ID's in Revit API.我正在尝试使用 Revit API 中的选定元素 ID 创建一个 python 列表。 I've tried to collect ID's of the grids in the sample structural file and then use this list back in Visual Studio Code.我尝试在示例结构文件中收集网格的 ID,然后在 Visual Studio Code 中使用此列表。 I am using Revit 2020 and IronPython 2.7.7 (2.7.7.0) on .NET 4.0.30319.42000 (64-bit).我在 .NET 4.0.30319.42000(64 位)上使用 Revit 2020 和 IronPython 2.7.7 (2.7.7.0)。

I get a list of the ID's that I want when I run the code in IronPython, but how to make a list of the printed ID's for further use back in Visual Studio Code?当我在 IronPython 中运行代码时,我得到了我想要的 ID 列表,但是如何制作打印 ID 的列表以便在 Visual Studio Code 中进一步使用?

Attached image of result附上结果图

Screenshot of code代码截图

My code:我的代码:

from Autodesk.Revit.DB import *
import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')

app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document

transaction = Transaction(doc, "Get grids")
transaction.Start()

new_list = DB.FilteredElementCollector(doc) \
    .OfCategory(DB.BuiltInCategory.OST_Grids) \
    .ToElementIds()

for x in range(len(new_list)):
    new_list[x]
    print(new_list[x])


transaction.Commit()

If I understand correctly, you're getting the list of Element IDs, but need to reference that information in another part of your logic, or a separate script altogether.如果我理解正确,您将获得元素 ID 列表,但需要在逻辑的另一部分或单独的脚本中引用该信息。 I'd recommend saving this data to a file at the end of this operation, and then consuming that file in any other logic/script which needs the data.我建议在此操作结束时将此数据保存到文件中,然后在需要数据的任何其他逻辑/脚本中使用该文件。

Personally, I prefer saving/reading data to the JSON format.就个人而言,我更喜欢将数据保存/读取为 JSON 格式。 Here are some resources to help you get started:以下是一些可帮助您入门的资源:

  1. Read & Write JSON with Python 使用 Python 读写 JSON
  2. How do I write JSON data to a file? 如何将 JSON 数据写入文件?
  3. Reading JSON from a file? 从文件中读取 JSON?

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

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