简体   繁体   中英

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. 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. I am using Revit 2020 and IronPython 2.7.7 (2.7.7.0) on .NET 4.0.30319.42000 (64-bit).

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?

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. 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. Here are some resources to help you get started:

  1. Read & Write JSON with Python
  2. How do I write JSON data to a file?
  3. Reading JSON from a file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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