Error when trying to store_data in doc-opening.py

Hi All,

I’m trying to get the opening time when opening up a project, my logic is, in the hook folder, use doc-opening.py and doc-opened.py to get the open_start_time and open_end_time. I’m trying to store_data of open_start_time and load it in doc-opened so I can do the math to get the duration. (I did this for sync time and that works)

However I’m not able to store_data the open_start_time in doc-opening.py and here is the error:

AttributeError: ‘NoneType’ object has no attribute ‘PathName’

Here is my doc-opening.py:


from datetime import datetime

#Get the time

time = datetime.now()

opening = time.strftime("%y-%m-%d %H-%M-%S")

#Save data for Open Start time

script.store_data("Open Start", opening, this_project=True)

print("Open Start", opening)

Hi @Rflash25,
it’s difficult to understand what went wrong from the information that you posted.

Generally speaking, the exception thrown by Python (and by any other language for that matter) include also the stack trace (the “path” of the lines of code executed prior to the error) that is really helpful to diagnose the error and suggest solutions. So it would be really helpful to see the entire message thrown by pyrevit.

That sais, my guess is that the document/project is not yet ready during the opening, and the code inside store_data tries to get the PathName of an object that is still empty (None).

As a side note: for better readability, please enclose the code between triple backticks (```) or simply use the <\>button in the editor toolbar :wink:

Thanks for the tips! I just edited the post :slightly_smiling_face:

Below is the entire message and I’m pretty sure it’s exactly what you mentioned, the document/project is not opened so the pathname is Nonetype.

I’m wondering what’s the workaround for this, maybe use a local txt/excel file as a temp storage for the data?

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.FastPropertyGet1.GetProperty(CallSite site, TSelfType target, CodeContext context) at Microsoft.Scripting.Interpreter.DynamicInstruction3.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 Microsoft.Scripting.Interpreter.DynamicInstruction3.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 Microsoft.Scripting.Interpreter.DynamicInstruction3.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.FuncCallInstruction6.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 Microsoft.Scripting.Interpreter.DynamicInstruction6.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.FuncCallInstruction6.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.DynamicInstruction6.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)

That can happen if you run on a unsaved document

Internally, the store_data with this_project set to True calls get_project_info that calls pyrevit.revit.db.ProjectInfo.filename, that in turn calls self._doc.PathName.

To me it seems that the ProjectInfo is not initialized with the correct document, hence the _doc attibute is None.

Maybe you should check if the document object is reachable before trying to store the data.

I did have other files like sync-opened.py and sync-opening.py that do able to reach the document and store_data.