bvn-architecture / RevitBatchProcessor

Fully automated batch processing of Revit files with your own Python or Dynamo task scripts!
GNU General Public License v3.0
277 stars 75 forks source link

Error using pyrevit modules #124

Open baaswietse opened 3 weeks ago

baaswietse commented 3 weeks ago

I am trying to use some modules I wrote for Pyrevit scripts. Everytime Pyrevit is imported, bellow exception occures. Seems like an issue with python hashlib module?

Exception: [ValueError] Illegal characters in path.
            - .NET exception: [ArgumentException] Illegal characters in path.

hashlib: 85: [128-128] 'hashlib.py'
urllib2: 39: [93-93] 'urllib2.py'
pyrevit.compat: 140: [25-25] 'C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\compat.py'
pyrevit: 96: [25-25] 'C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\__init__.py'

To reproduce:

import sys
sys.path += ["C:\Users\XX\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib",
             "C:\Users\XX\Documents\Github\my-tool\venv\RevitAPI stubs\RVT 23"]
from pyrevit import script
jchristel commented 2 weeks ago

hi baaswietse,

can you try to add an r in front of the path:

sys.path += [r"C:\Users\XX\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib",
            r"C:\Users\XX\Documents\Github\my-tool\venv\RevitAPI stubs\RVT 23"]

otherwise python might read this \r as a special character which is not allowed in a file path, hence the exception you are getting:

escape characters:

baaswietse commented 2 weeks ago

I changed the code as you suggested, now a different error occurs.

10:08:15 :  - ERROR: An error occurred while executing the task script! Operation aborted.
10:08:15 :  - 
10:08:15 :  - Exception: [IOError] System.IO.IOException: Could not add reference to assembly IronPython.SQLite
10:08:15 :  -    at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
10:08:15 :  -    at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
10:08:15 :  -    at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
10:08:15 :  -    at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
10:08:15 :  -    at IronPython.Compiler.Ast.CallExpression.Invoke0Instruction.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
10:08:15 :  -    at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
10:08:15 :  -    at IronPython.Modules.ResourceMetaPathImporter.load_module(CodeContext context, String fullname)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
10:08:15 :  -    at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
10:08:15 :  -    at IronPython.Runtime.PythonContext.Call(CodeContext context, Object func, Object arg0)
10:08:15 :  -    at IronPython.Runtime.Importer.FindAndLoadModuleFromImporter(CodeContext context, Object importer, String fullName, List path, Object& ret)
10:08:15 :  -    at IronPython.Runtime.Importer.TryLoadMetaPathModule(CodeContext context, String fullName, List path, Object& ret)
10:08:15 :  -    at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
10:08:15 :  -    at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
10:08:15 :  -    at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
10:08:15 :  -    at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:15 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
10:08:15 :  -    at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
10:08:15 :  -    at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
10:08:15 :  -    at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
10:08:15 :  -    at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, PythonModule module, String name, List path)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportModuleFrom(CodeContext context, Object from, String name)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
10:08:16 :  -    at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
10:08:16 :  -    at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
10:08:16 :  -    at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
10:08:16 :  -    at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
10:08:16 :  -    at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
10:08:16 :  -    at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
10:08:16 :  -    at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.ActionCallInstruction`3.Run(InterpretedFrame frame)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
10:08:16 :  -    at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
10:08:16 :  -    at IronPython.Compiler.Ast.CallExpression.Invoke2Instruction.Run(InterpretedFrame frame)
10:08:16 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
10:08:17 :  -    at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
10:08:17 :  -    at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
10:08:17 :  - .NET exception: [IOException] Could not add reference to assembly IronPython.SQLite
10:08:17 :  - 
10:08:17 :  - Further exception information:
10:08:17 :  - 
10:08:17 :  -   _$164: 63: [28-28] 'sqlite3\__init__.py'
10:08:17 :  -   sqlite3: 32: [29-29] 'sqlite3\__init__.py'
10:08:17 :  -   pyrevit.framework: 1763: [126-126] 'C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\framework.py'
10:08:17 :  -   pyrevit: 1008: [96-96] 'C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\__init__.py'
10:08:17 :  -   <unnamed>: 44: [4-4] 'C:\Users\Wietse_d\Documents\Github\WYC-addins\WYC-addins-v2.extension\lib\BatchProcessor\berekende_parameters.py'
10:08:17 :  -   ExecuteScript$111: 57: [82-82] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\script_util.py'
10:08:17 :  -   executeTaskScript$108: 155: [214-214] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:17 :  -   WithErrorHandling$25: 89: [49-49] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\script_host_error.py'
10:08:17 :  -   processDocument$106: 76: [224-229] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:17 :  -   WithOpenedCloudDocument$96: 254: [284-284] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:17 :  -   revitAction$94: 55: [340-349] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:17 :  -   WithDocumentOpeningErrorReporting$93: 61: [370-370] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:17 :  -   action$92: 37: [363-363] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:17 :  -   WithDialogBoxShowingHandler$91: 103: [88-88] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_dialog_util.py'
10:08:17 :  -   action$90: 38: [384-384] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:17 :  -   WithFailuresProcessingHandler$88: 118: [176-176] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_failure_handling.py'
10:08:17 :  -   action$87: 49: [386-386] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:17 :  -   WithExceptionLogging$86: 66: [165-165] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:18 :  -   WithAutomatedErrorHandling$85: 66: [388-388] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:18 :  -   WithErrorReportingAndHandling$84: 66: [365-365] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:18 :  -   RunCloudDocumentAction$83: 114: [351-351] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_util.py'
10:08:18 :  -   RunBatchTaskScript$63: 1349: [238-247] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  -   <lambda$3>$62: 30: [384-384] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  -   WithErrorHandling$25: 89: [49-49] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\script_host_error.py'
10:08:18 :  -   DoRevitSessionProcessing$46: 316: [383-388] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  -   <lambda$4>$45: 36: [419-425] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  -   WithErrorHandling$25: 89: [49-49] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\script_host_error.py'
10:08:18 :  -   outputStreamWriterAction$42: 66: [418-429] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  -   UsingStream$39: 61: [84-84] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\stream_io_util.py'
10:08:18 :  -   outputStreamAction$40: 73: [432-432] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  -   UsingStream$39: 61: [84-84] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\stream_io_util.py'
10:08:18 :  -   Main$26: 205: [435-435] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  -   WithErrorHandling$25: 89: [49-49] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\script_host_error.py'
10:08:18 :  -   <unnamed>: 451: [447-451] 'C:\Users\Wietse_d\AppData\Local\RevitBatchProcessor\Scripts\revit_script_host.py'
10:08:18 :  - 
10:08:18 :  - Closed cloud model.
10:08:18 :  - 
10:08:18 :  - Operation completed.
jchristel commented 2 weeks ago

Hi @baaswietse

Halfway down that list it says:

.NET exception: [IOException] Could not add reference to assembly IronPython.SQLite

Maybe that module is not on your path and therefore when you trying to load it, IronPython can not find it and RBP reports a crash?

Your second path seems to indicate that your are working in a virtual env... RBP will not know about that and hence a script may work just fine there but not when run in RBP

I'm guessing a little here...

baaswietse commented 2 weeks ago

@jchristel thank you for your suggestion. I already opened an issue on the pyrevit forms, since I feel this is more an issue related to PyRevit. Here you can find more information.

Would be great if PyRevit and RBP where able to work together.