pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.32k stars 337 forks source link

ProjectInfo class loses reference to the currently opened document after transaction is closed #2006

Open baaswietse opened 1 year ago

baaswietse commented 1 year ago

Describe the bug ProjectInfo class loses reference to the currently opened document after a transaction is closed. This bug was discovered after running the functions script.data_exitst(“example”), script.store_data(“example”, dataClass) or script.load_data(“example”) after a transaction.

To Reproduce Running this snippet reproduces the error

from pyrevit import revit

with revit.Transaction("test"):
    pass
print script.data_exists("example")

Error:

**IronPython Traceback:**
Traceback (most recent call last):
File "C:\Users\Wietse_d\Documents\Github\WDE-addins\WYC-addins.extension\WYC.tab\Dev.panel\Test.pushbutton\script.py", line 51, in <module>
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 743, in data_exists
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 315, in get_document_data_file
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 297, in filename
File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 293, in path
AttributeError: 'NoneType' object has no attribute 'PathName'

**Script Executor Traceback:**
System.MissingMemberException: 'NoneType' object has no attribute 'PathName'
at Microsoft.Scripting.Interpreter.ThrowInstruction.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 IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.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.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.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.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.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 Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Microsoft.Scripting.Interpreter.DynamicInstruction`6.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.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.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Desktop:

==> Registered Clones (full git repos)
master | Branch: "master" | Version: "4.8.13.23182+2215:6aa2c49" | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
==> Registered Clones (deployed from archive/image)
==> Attachments
master | Product: "Autodesk Revit 2024" | Engine: IPY277 (277) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
master | Product: "Autodesk Revit 2023" | Engine: IPY277 (277) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
master | Product: "Autodesk Revit 2022" | Engine: IPY277 (277) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
master | Product: "Autodesk Revit 2021" | Engine: IPY277 (277) | Path: "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master"
==> Installed Extensions
WYC-addins | Type: Unknown | Repo: "" | Installed: "C:\Users\Wietse_d\Documents\Github\WDE-addins\WYC-addins.extension"
==> Default Extension Search Path
C:\Users\Wietse_d\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
C:\Users\Wietse_d\Documents\Github\WDE-addins
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
Autodesk Revit 2024 | Version: 24.1.11.26 | Build: 20230911_1230(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2024\"
Autodesk Revit 2023 | Version: 23.1.30.97 | Build: 20230828_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
Autodesk Revit 2022 | Version: 22.1.50.17 | Build: 20230915_1530(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
Autodesk Revit 2021 | Version: 21.1.90.15 | Build: 20230907_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"

Additional context More information can be found in the issue I created on the pyrevit forum

jmcouffin commented 12 months ago

@baaswietse Tried it on my side with latest installers and engine 2711

from pyrevit import revit, script, HOST_APP
script.store_data("example", "Hello World!", this_project=True)
with revit.Transaction("test"):
    pass
print(script.data_exists("example"))
print(script.load_data("example"))
print(HOST_APP.doc.PathName)

It works just fine image

github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 60 days with no activity.

sanzoghenzo commented 9 months ago

Sorry for my silence @jmcouffin , I forgot you asked for my help on this 😅

I also couldn't reproduce on my Windows 10 installation, revit 2022 (I need to ask my IT to install newer version!), both local and cloud models.

Could it be a Windows 11 related problem?

@baaswietse does the issue still occur on the latest pyRevit version? And is that a problem with a specific revit version (I see that you have installed 4 versions, but never mentioned which one you are using and/or if some version beahve differently)?

jmcouffin commented 9 months ago

I tend to think it was a false positive. File not saved or something. No reply from @baaswietse ...

baaswietse commented 9 months ago

I installed the latest PyRevit and this issue still persists. The Revit version does not matter, as I tried it with all of them. I think this might be related to engine 277.

Could you please test if you have this issue using engine 277? I have some issues switching to 2711.

jmcouffin commented 9 months ago

@baaswietse Changing the Iron Python engine from 277 to 2711 should not bring you more errors. There are no fundamental changes between the two, or none that I know of. I just tried it with 277, works like a charm. image

baaswietse commented 9 months ago

Thank you for trying. I switched to 2711 and ran your script (RVT2024).

# -*- coding: utf-8 -*-
__title__ = "Test"
__doc__ = "Test"

from pyrevit import revit, script, HOST_APP
script.store_data("example", "Hello World!", this_project=True)
with revit.Transaction("test"):
    pass
print(script.data_exists("example"))
print(script.load_data("example"))
print(HOST_APP.doc.PathName)

But still this error pops up

IronPython Traceback:
Traceback (most recent call last):
 File "C:\Users\Wietse_d\Documents\Github\WDE-addins\WYC-addins.extension\WYC.tab\Dev.panel\Test.pushbutton\script.py", line 9, in <module>
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 777, in data_exists
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\script.py", line 340, in get_document_data_file
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 303, in filename
 File "C:\Users\Wietse_d\AppData\Roaming\pyRevit\pyRevit\master\pyrevitlib\pyrevit\revit\db\__init__.py", line 299, in path
AttributeError: 'NoneType' object has no attribute 'PathName'

Script Executor Traceback:
System.MissingMemberException: 'NoneType' object has no attribute 'PathName'
 at Microsoft.Scripting.Interpreter.ThrowInstruction.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 IronPython.Runtime.Binding.PythonGetMemberBinder.FastPropertyGet`1.GetProperty(CallSite site, TSelfType target, CodeContext context)
 at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.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.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
 at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
 at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
 at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.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.Runtime.PythonProperty.__get__(CodeContext context, Object instance, Object owner)
 at IronPython.Runtime.PythonProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
 at IronPython.Runtime.Types.GetMemberDelegates.SlotOnly(CallSite site, Object self, CodeContext context)
 at IronPython.Compiler.Ast.DynamicGetMemberExpression.GetMemberInstruction.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 Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
 at Microsoft.Scripting.Interpreter.DynamicInstruction`6.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.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.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)
jmcouffin commented 9 months ago

Can you provide a screenshot of the output window and Revit? @baaswietse what kind of file is it? local, on server, BIM360, not saved file?

baaswietse commented 9 months ago

Here you go. I tried on a local saved model and cloud model (ACC). Same result. image

jmcouffin commented 9 months ago

ok, I will check it more in depth in the coming days.