blog/
Распечатать дерево проекта в ArchiCAD 23 через Python
Рассказываю про скрипт, который выводит список всех элементов из дерева проекта ArchiCAD 23 в текстовый файл — таблицу. После сохранения, его можно импортировать Excel как csv (разделители — знаки табуляции). Чтобы скрипт запустить, вам понадобится ArchiCAD 23 python API плагин, который можно скачать бесплатно с сайта Graphisoft. Справка о которой идёт речь в ролике — в архиве с плагином. Этот скрипт я написал на основе программы, которая идёт в примерах, но сделал вывод другого списка (в оригинале там выводится список макетов), и вывожу в файл, потому что это быстрее и мне нужно получить из этого таблицу, в результате.
Все сказано в ролике, текст программы ниже listtheproject.py.
Ещё про питон — см. в рубрике программирование.
import sys
# import os
# Этот скрипт выводит дерево проекта через AC23 PY API
# порядок вывода дерева проекта:
# This script saves the project tree as a CSV file via ArchiCAD23 PY API
# the order is this:
# uiId
# name
# autoTextedName
# floorNum
# intendedPlanConn
# isIndependent
# Посмотрите справку AC23 python API, там есть описание этих полей, и ещё пары возможных — в статье про вызов GetNavigatorTree.
# Look into the AC23 python API reference for info on more available fields in GetNavigatorTree call article.
# sys.stdout = sys.__stdout__ # reset the input to standard to avoid ac23 py using the last output in case of error
original_stdout = sys.stdout # save the current output so to revert to it later
stringToWrite = ""
path = "D:\\ProjectTree.txt"
print('Starting saving the tree to file ' + path)
with open(path, "w+", encoding="utf-8") as f:
sys.stdout = f # Change the standard output to the file we created.
def PrintTree(tree, level=0):
try: # here we do try-except, so that we don't ruin the closef in the end, otherwize the file won'be closed, and the output flow too, thus cousing errors on other runs.
levelStr = "\t" * level
for k in tree.keys():
# print(levelStr + k.name)
output = ""
output += levelStr
global stringToWrite
if level > 1:
if k.uiId != "":
output += str(k.uiId) + "\t"
else:
output += "<empty>" + "\t"
if k.name != "":
output += str(k.name) + "\t"
else:
output += "<empty>" + "\t"
if k.autoTextedName != "":
output += "/" + str(k.autoTextedName) + "/\t"
else:
output += "<empty>" + "\t"
if k.floorNum != "":
output += str(k.floorNum) + "\t"
else:
output += "<empty>" + "\t"
if k.intendedPlanConn != "":
output += str(k.intendedPlanConn) + "\t"
else:
output += "<empty>" + "\t"
if k.isIndependent != "":
output += str(k.isIndependent) + "\t"
else:
output += "<empty>" + "\t"
if k.guid != "":
output += str(k.guid)
# stringToWrite += output + os.linesep // можно вот так, но мне удобнее \n
stringToWrite += output + "\n"
PrintTree(tree[k], level + 1)
except:
print("Couln't do.")
PrintTree(GetNavigatorTree(API_ProjectMap))
# PrintTree (GetNavigatorTree (API_LayoutMap))
print(stringToWrite) # write to file
f.close() # close file
sys.stdout = original_stdout # Reset the standard output to its original value ! this is very important, as AC23 PY does not clear variables after the script execution
print('Output end.')
Может быть интересно:
- Про Python и ArchiCAD: удалить лишние слои
- Как скачать картинки с сайта с помощью Python
- Select all images urls and download them
- Вывод дерева файлов через Питон
- Задаём свойства объектам в ArchiCAD 23 через Python
▨