Revit 使用 Python 绘制楼梯:仅适用于一级

问题描述

我正在开发一个 Dynamo 图形,该图形使用 Python 节点通过导入 CAD 几何图形来创建带平台的楼梯。您可以在 Dynamo 论坛帖子 here

中查看图表和其他信息

当设置为 Base Level 1(到 Level 2)时它工作正常,但任何更高并且它在它应该创建的一个完整的级别之上并给出错误Warning1 Warning2

任何更低(B1 到第 1 层)都会出现错误并且不会创建楼梯。PythonScriptError

无法调整 Revit 和 Dynamo 设置、CAD 文件或将 CAD 导入置于不同级别。 Python 脚本是唯一剩下的:

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import StairsRun
from Autodesk.Revit.DB.Architecture import StairsLanding
from Autodesk.Revit.DB import CurveLoop

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

doc = DocumentManager.Instance.CurrentDBDocument    
class StairsFailurePreprocessor( IFailuresPreprocessor ):
    def PreprocessFailures(self,failuresAccessor):
        return FailureProcessingResult.Continue

baseLevel = UnwrapElement(IN[0])
nextLevel = UnwrapElement(IN[1])
b1Curves = IN[2]
r1Curves = IN[3]
p1Curves = IN[4]
b2Curves = IN[5]
r2Curves = IN[6]
p2Curves = IN[7]
elCurves = IN[8]

TransactionManager.Instance.ForceCloseTransaction()

newStaiRSScope = StairsEditScope(doc,'New Stairs')
newStairsId = newStaiRSScope.Start(baseLevel.Id,nextLevel.Id)

trans = Transaction(doc,'Add Runs and Landings to Stairs')
trans.Start()

bdryCurves1 = list(b1Curves)
riserCurves1 = list(r1Curves)
pathCurves1 = list(p1Curves)

bdryCurves2 = list(b2Curves)
riserCurves2 = list(r2Curves)
pathCurves2 = list(p2Curves)

landingLoop = CurveLoop.Create(elCurves)

r1Count = len(r1Curves)
r2Count = len(r2Curves)

newRun1 = Autodesk.Revit.DB.Architecture.StairsRun.CreateSketchedRun(doc,newStairsId,baseLevel.Elevation,bdryCurves1,riserCurves1,pathCurves1)
newLanding = Autodesk.Revit.DB.Architecture.StairsLanding.CreateSketchedLanding(doc,landingLoop,newRun1.TopElevation)
newRun2 = Autodesk.Revit.DB.Architecture.StairsRun.CreateSketchedRun(doc,newLanding.BaseElevation,bdryCurves2,riserCurves2,pathCurves2)
trans.Commit()
newStaiRSScope.Commit(StairsFailurePreprocessor())

OUT = newStairsId

感谢任何帮助。

谢谢, 露露

解决方法

海拔是 0。否则就是海拔 + 海拔!

"newRun1 = StairsRun.CreateSketchedRun(doc,newStairsId,0,bdryCurves,RiserCurves,pathCurves )"

import clr #.NET Laden
import sys #sys is de fundamentele Python bibliotheek
#the standard IronPython libraries
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib') #Imports the
#standard IronPython libraries,which cover everything from servers and
#encryption through to regular expressions.
import System #The System namespace at the root of .NET
from System import Array #.NET class for handling array information
import System.Collections.Generic as MGen #Module kan nu benaderd worden met MGen.xxxx
#from System.Collections.Generic import * #Lets you handle generics. Revit's API
#sometimes wants hard-typed 'generic' lists,called ILists. If you don't need
#these you can delete this line.
clr.AddReference('ProtoGeometry')  #A Dynamo library for its proxy geometry
#classes. You'll only need this if you're interacting with geometry.
import Autodesk.DesignScript.Geometry as AGeo #Module kan worden opgeroepen a=met AGeo.xxxx
#from Autodesk.DesignScript.Geometry import * #Loads everything in Dynamo's
#geometry library
clr.AddReference("RevitNodes") #Dynamo's nodes for Revit
import Revit #Loads in the Revit namespace in RevitNodes
clr.ImportExtensions(Revit.Elements) #More loading of Dynamo's Revit libraries
clr.ImportExtensions(Revit.GeometryConversion) #More loading of Dynamo's
#Revit libraries. You'll only need this if you're interacting with geometry.
clr.AddReference("RevitServices") #Dynamo's classes for handling Revit documents
import RevitServices 
from RevitServices.Persistence import DocumentManager #An internal Dynamo class
#that keeps track of the document that Dynamo is currently attached to
from RevitServices.Transactions import TransactionManager #A Dynamo class for
#opening and closing transactions to change the Revit document's database

clr.AddReference("RevitAPI") #Adding reference to Revit's API DLLs
clr.AddReference("RevitAPIUI") #Adding reference to Revit's API DLLs

import Autodesk #Loads the Autodesk namespace
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
from Autodesk.Revit.DB.Architecture import *

doc = DocumentManager.Instance.CurrentDBDocument #Dit is het actieve Revit document
uiapp = DocumentManager.Instance.CurrentUIApplication #Setting a handle to the active Revit UI document
app = uiapp.Application  #Setting a handle to the currently-open instance of the Revit application
uidoc = uiapp.ActiveUIDocument #Setting a handle to the currently-open instance of the Revit UI application
# Hieronder kan je dan gaan programmeren
#Gebruik boiler template
class StairsFailurePreprocessor( IFailuresPreprocessor ):
    def PreprocessFailures(self,failuresAccessor):
        return FailureProcessingResult.Continue
        
BL=UnwrapElement(IN[0])
TL=UnwrapElement(IN[1])
newStairsScope = StairsEditScope(doc,"New Stairs")

newStairsId = newStairsScope.Start( BL.Id,TL.Id)
trans = Autodesk.Revit.DB.Transaction(doc,"Trap maken")
trans.Start()

Traplengte=UnitUtils.Convert(3300,DisplayUnitType.DUT_MILLIMETERS,DisplayUnitType.DUT_DECIMAL_FEET)
Hoogte=BL.Elevation
#Lijnen maken voor een geschetste trap
bdryCurves=MGen.List[Curve]() #cl is een revittype lijst voor curves
pnt1 = XYZ(0,Hoogte)
pnt2 = XYZ(Traplengte,Hoogte)
pnt3 = XYZ(0,6,Hoogte)
pnt4 = XYZ(Traplengte,Hoogte)

#boundaries       
bdryCurves.Add(Line.CreateBound(pnt1,pnt2))
bdryCurves.Add(Line.CreateBound(pnt3,pnt4))

riserCurves=MGen.List[Curve]() #cl is een revittype lijst voor curves
#riser curves
Aantrede=Traplengte / 15
for NX in range(16):
    end0 = XYZ(pnt1.X + (NX * Aantrede),Hoogte)
    end1 = XYZ(pnt3.X + (NX * Aantrede),Hoogte)
    riserCurves.Add(Line.CreateBound(end0,end1))
    
pathCurves=MGen.List[Curve]() #cl is een revittype lijst voor curves
#stairs path curves
pathEnd0 = XYZ(0,3,Hoogte)
pathEnd1 = XYZ(Traplengte,Hoogte)
pathCurves.Add(Line.CreateBound(pathEnd0,pathEnd1))


newRun1 = StairsRun.CreateSketchedRun(doc,riserCurves,pathCurves )

#locationLine = Line.CreateBound(XYZ(20,-5,newRun1.TopElevation),XYZ(35,newRun1.TopElevation))

#newRun2 = StairsRun.CreateStraightRun(doc,locationLine,StairsRunJustification.Center)
#newRun2.ActualRunWidth = 10

'''
#Add a landing between the runs
landingLoop = CurveLoop()
p1 = XYZ(15,10,0)
p2 = XYZ(20,0)
p3 = XYZ(20,-10,0)
p4 = XYZ(15,0)
curve_1 = Line.CreateBound(p1,p2)
curve_2 = Line.CreateBound(p2,p3)
curve_3 = Line.CreateBound(p3,p4)
curve_4 = Line.CreateBound(p4,p1)
landingLoop.Append(curve_1)
landingLoop.Append(curve_2)
landingLoop.Append(curve_3)
landingLoop.Append(curve_4)
newLanding = StairsLanding.CreateSketchedLanding(doc,landingLoop,newRun1.TopElevation)
'''

trans.Commit()
trans.Dispose()


newStairsScope.Commit(StairsFailurePreprocessor())
newStairsScope.Dispose()
ele=doc.GetElement(newStairsId)
OUT=newStairsId,ele

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...