DB.ViewSchedule.CreateSchedule() freezes Revit application

Hello!

I am struggling with an issue for at least a week. I have tried many different options, but still no effect. Basically i am trying to create new Schedule instance using Revit API in GHPython, here is the complete code:

import clr
clr.AddReference('System.Core')
clr.AddReference('RhinoInside.Revit')
clr.AddReference('RevitAPI') 
clr.AddReference('RevitAPIUI')

from System import Enum

import rhinoscriptsyntax as rs
import Rhino
import RhinoInside
import Grasshopper
from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
from RhinoInside.Revit import Revit, Convert
from Autodesk.Revit import DB

# access the active document object
doc = Revit.ActiveDBDocument

def show_warning(msg):
    ghenv.Component.AddRuntimeMessage(RML.Warning, msg)

def show_error(msg):
    ghenv.Component.AddRuntimeMessage(RML.Error, msg)

def show_remark(msg):
    ghenv.Component.AddRuntimeMessage(RML.Remark, msg)

with DB.Transaction(doc, 'creating_schedule') as t:
    t.Start()
    template_from =  DB.ViewSchedule.CreateSchedule(doc,category.Id)
    template_from.Name = "temp_schedule"

    t.Commit()

tttt

Category entrance has Item Acces with no type hint

Once being enabled the whole Revit application freezes forever in 80% of cases.

After several tries with several files and on different machines, i guess this issue is related to some internal bug.

Could you tell me please if this issue is resolvable?

By the way Dynamo’s python doesn’t crash the application at all :tipping_hand_man::

import sys
import clr

clr.AddReference('RevitAPI') 
clr.AddReference('ProtoGeometry')
clr.AddReference("RevitServices")

from RevitServices.Persistence import DocumentManager
from Autodesk.Revit import DB
doc = DocumentManager.Instance.CurrentDBDocument

category = IN[0]

# Place your code below this line
with DB.Transaction(doc, 'creating_schedule') as t:
    t.Start()
    template_from =  DB.ViewSchedule.CreateSchedule(doc,DB.ElementId(category.Id))
    template_from.Name = "temp_schedule 7"

    t.Commit()
# Assign your output to the OUT variable.
OUT = 0

Magda, In your dynamo script it looks like you changed the name. The current script you have now will indefinitely fail if the name isn’t unique.

Depending on your workflow you may want to check existing names first.

This example starts and stops and provides a name input.


Re_AddSchedule.gh (10.6 KB)

no, this is not an issue.

Even if i will use only the first line of the code (with no rename):
template_from = DB.ViewSchedule.CreateSchedule(doc,DB.ElementId(category.Id))
it will freeze in 80% of cases. When it doesn’t crash, each new Schedule instance obtains a new unique name (Room Schedule, Room Schedule 1, Room Schedule 2…)

Besides that i usually use the following construction:

try:
    #transaction....
except:
    t.RollBack()

The code was working well at least 3 months ago. Moreover, the rest of views types (floor plan, section, etc.) are being created properly

The transaction you provided works fine if a stop is enabled and it’s not hitting the unique name error.

To understand the issue a full example would be helpful. Thanks