不囉嗦,直接上程式碼
import clr
# Import Revit API
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
# Import RevitServices
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Current Revit Document
doc = DocumentManager.Instance.CurrentDBDocument
# Unwrap the inputs
sheet = UnwrapElement(IN[0])
view = UnwrapElement(IN[1])
point = IN[2] # Point where the view will be placed on the sheet (as a list [x, y])
# Convert the point to XYZ
placement_point = XYZ(point[0], point[1], 0)
# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for s in sheet:
# Create the viewport
viewport = Viewport.Create(doc, s.Id, view.Id, placement_point)
# End the transaction
TransactionManager.Instance.TransactionTaskDone()
OUT = viewport
下面提供影片Demo
Comments