PyRevit开发第一步:获取Revit文档Document

1.安装PythonShell插件

PyRevit开发第一步:获取Revit文档Document

PythonShell 2018 插件下载

交流QQ群: 17075104

新建项目后,运行功能Python Shell,
在弹出的窗口中复制或输入以下引用代码模块:

#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time      : 2021-01-01
# @Author    : ZedMoster1@gmail.com

from Autodesk.Revit.UI import *
from Autodesk.Revit.DB import *
import Autodesk
import math
import os
import re
import sys

import clr
from System import Array

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
clr.AddReference("System")

doc = __revit__.ActiveUIDocument.Document
uidoc = __revit__.ActiveUIDocument
uiapp = __revit__.Application

在上次命令行输入 doc 即可获取当前项目文档Document
PyRevit开发第一步:获取Revit文档Document


2.通过Dynamo节点

PyRevit开发第一步:获取Revit文档Document

右键在搜索窗口中输入 python script 选择节点,
双击节点后弹出输入脚本窗口,复制或输入一下引用代码模块:

#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time      : 2021-01-01
# @Author    : ZedMoster1@gmail.com

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPIUI')
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# 默认参数
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
doc = DocumentManager.Instance.CurrentDBDocument

# 输出
OUT = doc

点击完成编辑后,运行节点即可查看当前所在项目的Document


至此我们已经学会两种通过python获取Revit文档的方法,
接下来就是了解后续文档数据的过程.

上一篇:疯狂的ASP.NET系列-第一篇:啥是ASP.NET后续


下一篇: