Hi all,
I’m trying to place panelscheduleviews on existing sheets with the given script.
I retrieved the existing sheets and the panelscheduleviews. Also get the origin point in Dynamo with the node point.by coordinates, could I believe are the inputs that need to use the methods of create a ScheduleSheetInstance or viewport but not of them allows me to place panelscheduleview into sheets. I notice on Revit API we do have a class for Panelschedulesheetinstance but on their inputs do not have any arguments to include a location, so when I run the code, it just creates those but not placing on the sheet. I am using on Revit 2024 and Dynamo 2.19.
Here is the code to create Viewport.
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
sheets = [UnwrapElement(sheet) for sheet in IN[0]]
views = [UnwrapElement(view) for view in IN[1]]
points = IN[2]
viewports = []
# Start transaction
TransactionManager.Instance.EnsureInTransaction(doc)
# Iterate through sheets, views, and points
for sheet, view, point in zip(sheets, views, points):
try:
# Check if view is a PanelScheduleView and can be added to the sheet
if isinstance(view, View) and view.ViewType == ViewType.PanelSchedule:
if Viewport.CanAddViewToSheet(doc, sheet.Id, view.Id):
location = XYZ(point.X, point.Y, point.Z)
# Create viewport
viewport = Viewport.Create(doc, sheet.Id, view.Id, location)
if viewport:
wviewport = viewport.ToDSType(False)
viewports.append(wviewport)
else:
viewports.append("Failed to create viewport")
else:
viewports.append("Cannot add view to sheet")
else:
viewports.append("The view is not a PanelScheduleView")
except Exception as e:
viewports.append(f"Error creating viewport for sheet {sheet.Id} and view {view.Id}: {e}")
# Regenerate document once after all viewports are created
doc.Regenerate()
TransactionManager.Instance.TransactionTaskDone()
OUT = viewports
and here is for meths to create ScheduleSheetInstance
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference("RevitAPIUI")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import Autodesk
from Autodesk.Revit.UI import *
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Electrical import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
sheets = [UnwrapElement(sheet) for sheet in IN[0]]
views = [UnwrapElement(view) for view in IN[1]]
points = IN[2]
scheduleview = []
# Start transaction
TransactionManager.Instance.EnsureInTransaction(doc)
try:
# Iterate through sheets, views, and points
for sheet, view, point in zip(sheets, views, points):
try:
# Check if view is a PanelScheduleView and can be added to the sheet
if isinstance(view, View) and view.ViewType == ViewType.PanelSchedule:
location = XYZ(point.X, point.Y, point.Z)
# Create viewschedule
viewschd = ScheduleSheetInstance.Create(doc, sheet.Id, view.Id, location)
if viewschd:
wviewschd = viewschd.ToDSType(False)
scheduleview.append(wviewschd)
else:
scheduleview.append("Cannot add view to sheet")
else:
scheduleview.append("The view is not a PanelScheduleView or is an internal schedule")
except Exception as e:
scheduleview.append(f"Error creating viewport for sheet {sheet.Id} and view {view.Id}: {e}")
finally:
# Regenerate document once after all viewports are created
doc.Regenerate()
TransactionManager.Instance.TransactionTaskDone()
OUT = scheduleview
and finally, here is for the metod of PanelscheduleSheet Instance
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument
# Unwrap inputs
panel_schedule_views = UnwrapElement(IN[0]) # Second input: list of panel schedule view IDs
# Initialize lists to store the IDs and views
panel_schedule_view_ids = []
panel_schedule_views_ = []
# Loop through each Panel Schedule View and get its ID and View
for panel_sch_v in panel_schedule_views:
panel_sch_v_id = panel_sch_v.Id
panel_schedule_view_ids.append(panel_sch_v_id)
panel_schedule_views_.append(panel_sch_v)
# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)
# Create multiple Panel Schedule Sheet instances
panel_schedule_sheets = []
for view_id, view_ in zip(panel_schedule_view_ids, panel_schedule_views_):
panel_schedule_sheet = Electrical.PanelScheduleSheetInstance.Create(doc, view_id, view_)
W_panel_schedule_sheet = panel_schedule_sheet.ToDSType(False)
panel_schedule_sheets.append(W_panel_schedule_sheet)
# Commit the transaction
TransactionManager.Instance.TransactionTaskDone()
# Output the Panel Schedule Sheet instances
OUT = panel_schedule_sheets
The last one does not give me any errors, but I am still does not see the panelscheduleviews placing into the sheets.
Is there another method or there something that I am missing in order to achieve this. Any advice I really appreciate. Thanks.
Regards.