Hello all, I have a script that when running from CLI crashes moments after it starts to run the script. I have attempted to save some logs to a text file but nothing is saved and no warning is given. The first write to txt is on line 3.
First 3 lins:
import os, sys
with open ("C:\\users\\shansen\\Desktop\\File.txt", 'w')as f:
f.write(repr(list(sys.path)))
Since it was crashing with no errors I started commenting out large chunks of the script from the bottom up. I finally got to the point where only definitions and imports were left. I commented out one of the definitions and all of my writes started working. At this point, the definition is not being called anywhere in the script but still causing it to crash leading me to think it’s a compiling error.
The definition is just under 700 lines long. I continued with the above method of commenting out lines from the bottom up. Eventually, the script started working again. This is where things start to get strange. Once I comment out line 426 (of the definition, not the overall script, and assuming the definition starts at line 1 and has no blanks or commented lies) it starts working.
Line 425 and 426:
text = FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.TextNoteType).ToElements()
textCount = len(text)
Nothing on these two lines looks incorrect to me. I then added “hi = 1” before textCount and commented out textCount and the script crashes. Anything I add past line 425 causes the script to crash. I can add comments and blank lines before or after to increase the line count but any code past line 425 crases it.
crashies
text = FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.TextNoteType).ToElements()
#textCount = len(text)
hi = 1
crashes
#text = FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.TextNoteType).ToElements()
#textCount = len(text)
hi = 1
by = 2
works fine
text = FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.TextNoteType).ToElements()
#textCount = len(text)
#hi = 1
#by = 2
If I open Revit and run the tool from the ribbon it executes the script as expected with no warnings.
Is there a way I can get an error report when running from the CLI? Since it is crashing during the compiling phase I am not able to write anything to a text file.