使用Python的Revit草图楼梯:仅适用于一级



我正在研究一个Dynamo图,它使用Python节点通过导入CAD几何图形来创建带有着陆的楼梯。你可以在Dynamo论坛的帖子中看到图表和其他信息

当设置为基础级别1(到级别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, newStairsId, landingLoop, newRun1.TopElevation)
newRun2 = Autodesk.Revit.DB.Architecture.StairsRun.CreateSketchedRun(doc, newStairsId, newLanding.BaseElevation, bdryCurves2, riserCurves2, pathCurves2)
trans.Commit()
newStairsScope.Commit(StairsFailurePreprocessor())
OUT = newStairsId

任何帮助都是感激的。

谢谢,LoRue

标高为0。否则将是海拔+海拔!

newRun1 = StairsRun。CreateSketchedRun(doc, newStairsId,0)

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.7Lib') #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, 0, Hoogte)
pnt2 = XYZ(Traplengte, 0, Hoogte)
pnt3 = XYZ(0, 6, Hoogte)
pnt4 = XYZ(Traplengte, 6, 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), 0, Hoogte)
end1 = XYZ(pnt3.X + (NX * Aantrede), 6, 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,3,Hoogte)
pathCurves.Add(Line.CreateBound(pathEnd0, pathEnd1))

newRun1 = StairsRun.CreateSketchedRun(doc, newStairsId , 0 , bdryCurves, riserCurves, pathCurves )
#locationLine = Line.CreateBound(XYZ(20, -5, newRun1.TopElevation), XYZ(35, -5, newRun1.TopElevation))
#newRun2 = StairsRun.CreateStraightRun(doc, newStairsId, locationLine, StairsRunJustification.Center)
#newRun2.ActualRunWidth = 10
'''
#Add a landing between the runs
landingLoop = CurveLoop()
p1 = XYZ(15, 10, 0)
p2 = XYZ(20, 10, 0)
p3 = XYZ(20, -10, 0)
p4 = XYZ(15, -10, 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, newStairsId, landingLoop, newRun1.TopElevation)
'''
trans.Commit()
trans.Dispose()

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

相关内容

  • 没有找到相关文章

最新更新