I have some code that I know works, because if you call it in a button event, it works. If I call the same code before the dock widget has finished loading, I get a Class Name error.
I have this Python Script:
https://github.com/DataJuggler/PythonScripts/blob/main/CarDriver.pyI created a class called PropInfo, so I can load all the props into memory, and not have to call prop.GetName() more than once per prop.I had to rearrange my user interface to have a Load Props button, and after clicking that, the other buttons become enabled.
After clicking, I enable the other buttons.
I would much prefer to not force the users to click the Load Props button, since I know the call to get all_props works.For some reason, this method throws an error if called before the UI has finished loading.def ConvertProps(all_props):
# initial value
props = []
# counter
count = 0
# ensure the all_props exist
if (all_props is not None):
# iterate all_props
for i in range (len(all_props)):
# create a new class
prop = PropInfo()
# set the properties
prop.Prop = all_props[i]
prop.Name = prop.Prop.GetName()
prop.Index = count
# add this item
props.append(prop)
# increment
count = count + 1
# return value
return props
The error is from this line:
prop = PropInfo()
This works fine if I do it in a button click event.
If I try and call LoadProps or ConvertProps before the UI is shown, I get this:
Error:
<class 'NameError'>, File: C:/Projects/GitHub/PythonScripts/CarDriver/CarDriver.py, Line: 525
My work around works to enable the other buttons after they click the Load Props button, but I don't understand why I can't "Preload" the Props collection.
In Windows Forms I would look for an 'Activated' event, but I don't see a way in the RDockWidget.
Do duplicate this, call LoadProps() anywhere after all_props is loaded:
all_props = RLPy.RScene.FindObjects(RLPy.EObjectType_Prop)
# throws error before UI is shown
LoadProps()
Thanks, if anyone has any insight.
Creator of the free website:
PixelDatabase.Net
A Free Online Text Based Image Editor
