其他分享
首页 > 其他分享> > PyRevit开发第一步:获取Revit文档Document

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

作者:互联网

1.安装PythonShell插件

image

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
image


2.通过Dynamo节点

image

右键在搜索窗口中输入 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文档的方法,
接下来就是了解后续文档数据的过程.

标签:AddReference,Autodesk,PyRevit,import,Document,Revit,clr
来源: https://www.cnblogs.com/zedmoster/p/15258232.html