Pyrevit: Print Sheets can not overwrite existing files and crashes

Created on 23 Jan 2020  路  6Comments  路  Source: eirannejad/pyRevit

Can't deal with files already existing

To Reproduce
Steps to reproduce the behavior:

  1. Setup the PDF plot where a file already exists
  2. See error
IronPython Traceback:
Traceback (most recent call last):
 File "C:\Users\dli\AppData\Roaming\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Drawing Set.panel\Print Sheets.pushbutton\script.py", line 1133, in <module>
 File "C:\Users\dli\AppData\Roaming\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Drawing Set.panel\Print Sheets.pushbutton\script.py", line 1117, in print_sheets
 File "C:\Users\dli\AppData\Roaming\pyRevit-Master\extensions\pyRevitTools.extension\pyRevit.tab\Drawing Set.panel\Print Sheets.pushbutton\script.py", line 778, in _print_sheets_in_order
Exception: The files already exist!

Script Executor Traceback:
Autodesk.Revit.Exceptions.InvalidOperationException: The files already exist!
 at Microsoft.Scripting.Interpreter.ThrowInstruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
 at IronPython.Runtime.Method.MethodBinding`1.SelfTarget(CallSite site, CodeContext context, Object target, T0 arg0)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at IronPython.Compiler.PythonCallTargets.OriginalCallTarget3(PythonFunction function, Object arg0, Object arg1, Object arg2)
 at CallSite.Target(Closure , CallSite , Object , Object , RoutedEventArgs )
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at _Scripting_(Object[] , Object , RoutedEventArgs )
 at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
 at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
 at System.Windows.Controls.Primitives.ButtonBase.OnClick()
 at System.Windows.Controls.Button.OnClick()
 at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
 at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
 at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
 at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
 at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
 at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
 at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
 at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
 at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
 at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
 at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
 at System.Windows.Input.InputManager.ProcessStagingArea()
 at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
 at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
 at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
 at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
 at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
 at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
 at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
 at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
 at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
 at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
 at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
 at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
 at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
 at System.Windows.Window.ShowHelper(Object booleanBox)
 at System.Windows.Window.ShowDialog()
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)`

Desktop (please complete the following information):

  • Win10
  • pyRevit Version 4.7.4
  • pyRevit Environment:
C:\Users\dli>pyrevit env
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.7.4" | Path: "C:\Users\dli\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "2020.1 Update" | Engine: 277 | Path: "C:\Users\dli\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\dli\AppData\Roaming\Autodesk\Revit\Addins\2020\pyRevit.addin"
master | Product: "2019.2.2 Hotfix" | Engine: 277 | Path: "C:\Users\dli\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\dli\AppData\Roaming\Autodesk\Revit\Addins\2019\pyRevit.addin"
master | Product: "2018.3.3 Security Fix" | Engine: 277 | Path: "C:\Users\dli\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\dli\AppData\Roaming\Autodesk\Revit\Addins\2018\pyRevit.addin"
master | Product: "2017.2.5 Security Fix" | Engine: 277 | Path: "C:\Users\dli\AppData\Roaming\pyRevit-Master" | Manifest: "C:\Users\dli\AppData\Roaming\Autodesk\Revit\Addins\2017\pyRevit.addin"
==> Installed Extensions
==> Default Extension Search Path
C:\Users\dli\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
2020.1 Update | Version: 20.1.0.81 | Build: 20190725_1135(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020"
2019.2.2 Hotfix | Version: 19.2.20.24 | Build: 20190808_0900(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2019"
2018.3.3 Security Fix | Version: 18.3.3.18 | Build: 20190510_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2018"
2017.2.5 Security Fix | Version: 17.0.1169.0 | Build: 20190508_0315(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2017"
==> Running Revit Instances
PID: 14732 | 2018.3.3 Security Fix | Version: 18.3.3.18 | Build: 20190510_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2018"
==> User Environment
Microsoft Windows 10 [Version 10.0.17763]
Executing User: [redacted]\DLI
Active User: [redacted]\DLI
Admin Access: No
%APPDATA%: "C:\Users\dli\AppData\Roaming"
Latest Installed .Net Framework: 4.8
No .Net Target Packs are installed.
No .Ne-Core Target Packs are installed.
pyRevit CLI 0.17.0.0

C:\Users\dli>

Additional context
That's about it. Thanks

Enhancement Intended Behaviour Revit Bug

All 6 comments

He @DuncanLithgow
So pyRevit uses the PrintManager provided byt the Revit API to SubmitPrint. It's the Revit print handler that is throwing the exception and can not deal with existing files. I can not see any option on the print manager to push for overwriting files. The other option was to delete the existing files before print but that sounded a bit intrusive. I can however add this as a checkbox in the interface to delete the existing before print maybe. Is this something that would help you?

I'm hesitant to suggest anything without knowing how other software deals with this under the hood. Because clearly they are managing it somehow. We should of course only implement something that is safe to use for important jobs with potentially hundreds of sheets. If that's not possible with the API available then maybe pyRevit should just always print to a new date stamped folder. That's almost what I do anyway. Also maybe good to write somewhere in the interface where the files are being sent ...

I suggest it writes to a date stamped folder in the selected folder. This has to be more intuitive than crashing if there are already files in the folder.

Tested this. Could not figure out a way to force the file path to Revit print mechanism. Seems like it follows what's in the native print settings menu

so what's the current expected behavior in this situation? a good sheet plotter is such a missing feature in Revit that a good & robust solution in pyRevit would just be so popular.

I'm working on it. I need to understand how Revit print mechanism works a bit better. It seems very inconsistent to me and kinda depends on the type of output printer selected in most cases. I have this item on my list but since it is an "Enhancement" I closed this issue for now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jkcameron picture jkcameron  路  5Comments

thumDer picture thumDer  路  4Comments

pmcmm picture pmcmm  路  3Comments

kuldeep3618x picture kuldeep3618x  路  4Comments

Arsany123 picture Arsany123  路  4Comments