Profile Picture

Is there an event or a way to know when an RDockWidget has Activated?

Posted By Data Juggler 4 Years Ago
You don't have permission to rate!

Is there an event or a way to know when an RDockWidget has Activated?

Author
Message
Data Juggler
Data Juggler
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)

Group: Forum Members
Last Active: 9 Months Ago
Posts: 1.8K, Visits: 5.6K
OK, thanks. I still think in C#.




Creator of the free website:
PixelDatabase.Net
A Free Online Text Based Image Editor
https://forum.reallusion.com/uploads/images/6e6663e2-0ecf-447a-ab3d-d49d.png

Victor.Soupday
Victor.Soupday
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 569, Visits: 9.0K
if you put the classes in something like: classes.py

then you could either:
from . classes import PropInfo

prop = PropInfo()
or
from . import classes

prop = classes.PropInfo()
Data Juggler
Data Juggler
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)

Group: Forum Members
Last Active: 9 Months Ago
Posts: 1.8K, Visits: 5.6K
Moving the class up worked.

I didn't even have to change my code about disabling / enabling the buttons, because the method I called handled that.

Thanks again, I will check in the latest version now, and once I get the wheels spinning, post a demo of it. Here is a preview of the way it drives cars.

https://forum.reallusion.com/uploads/images/a3f95b82-075c-4075-8cab-90d4.png


Creator of the free website:
PixelDatabase.Net
A Free Online Text Based Image Editor
https://forum.reallusion.com/uploads/images/6e6663e2-0ecf-447a-ab3d-d49d.png

Data Juggler
Data Juggler
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)

Group: Forum Members
Last Active: 9 Months Ago
Posts: 1.8K, Visits: 5.6K
I was just about to reply I thought about that while in the shower.

I will try that here in a few minutes. Do you by chance know how to import a python class, if the file is in the same directory?

That was my next thought as to importing the class at the top might make it globally available like the other libraries.

I will google that after I do a little real work.

Thanks for the reply. 

Creator of the free website:
PixelDatabase.Net
A Free Online Text Based Image Editor
https://forum.reallusion.com/uploads/images/6e6663e2-0ecf-447a-ab3d-d49d.png

Victor.Soupday
Victor.Soupday
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)Distinguished Member (5.8K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 569, Visits: 9.0K
You're trying to use the class PropInfo before it's been defined.

When you run ConvertProps() through the button, by the time you actually press the button the entire script has been parsed and the PropInfo class is defined. Python runs the code as it finds it, it doesn't process the script before hand to find classes and functions.

Move the class definitions to the top of the script, it should work as intended.


Data Juggler
Data Juggler
Posted 4 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)Distinguished Member (13.9K reputation)

Group: Forum Members
Last Active: 9 Months Ago
Posts: 1.8K, Visits: 5.6K
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.py

I 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.

https://forum.reallusion.com/uploads/images/45e99e10-093e-4bae-89e1-c850.png

After clicking, I enable the other buttons.

https://forum.reallusion.com/uploads/images/477800bc-79a4-4a13-b76b-c1da.png

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
https://forum.reallusion.com/uploads/images/6e6663e2-0ecf-447a-ab3d-d49d.png




Reading This Topic