DreamWall-Animation / dwpicker

Animation picker.
MIT License
159 stars 31 forks source link

Changing namespace does not change targets in actions #93

Closed kalemas closed 2 weeks ago

kalemas commented 3 months ago

To reproduce, 1. reference a character, 2. setup a picker, 3. add action to, say, switch visibility, 4. load same character and change namespace picker namespace to that character namespace

visibility will be still switched on first character but nodes will be selected on second

Here is what i got

image

Expected to switch visibility for second character as i explicitly switched namespace for the picker.

kalemas commented 3 months ago

First idea is to generate replacement pairs when switching namespace and changing shape targets, then do substitution in shape.actions.

We may substitute only words that look like absolute maya node path :| or only string literals: node = 'pCube1' will be changed to node = 'geom:pCube1'.

Or explicitly define namespace in script text: cmds.getAttr('{namepsace}:pCube1.v').

kalemas commented 3 months ago

By the way would we exec in any useful context?

https://github.com/DreamWall-Animation/dwpicker/blob/f02354f92e052ab12cb53d8e9e4cb3cb5be3ce02/dwpicker/languages.py#L36

exec(code, {'cmds': maya.cmds, 'mel': maya.mel}) or application context import __main__; exec(code, vars(__main__)) or even exec(code, vars(maya.cmds)) so we would optimize our scripts using direct getAttr('pCube1.v') and etc.

kalemas commented 3 months ago

making separate field for holding a namespace in picker data would solve several cases. I still thinking about referencing pickers and if there would be such field and mechanics, it would be as easy as override single field rather than changing targets of all the shapes in #67

luckylyk commented 3 months ago

To reproduce, 1. reference a character, 2. setup a picker, 3. add action to, say, switch visibility, 4. load same character and change namespace picker namespace to that character namespace

visibility will be still switched on first character but nodes will be selected on second

Here is what i got

image

Expected to switch visibility for second character as i explicitly switched namespace for the picker.

Yeah off course it is not working ^^ as the script is an hardcoded string. It is not going to read the script and detect what could be a target or not inside the code. That seems impossible to automate. I guess your best shot is to

cmds.getAttr(f'{dwpicker._dwpicker.namespace_combo.currentText()}:cube')

I guess I should add a shortcut to set user able to do: dwpicker.active_namespace()

making separate field for holding a namespace in picker data would solve several cases. I still thinking about referencing pickers and if there would be such field and mechanics, it would be as easy as override single field rather than changing targets of all the shapes in #67

Yeah that probably a cleaner solution less hacky than how it is now.

By the way would we exec in any useful context?

https://github.com/DreamWall-Animation/dwpicker/blob/f02354f92e052ab12cb53d8e9e4cb3cb5be3ce02/dwpicker/languages.py#L36

exec(code, {'cmds': maya.cmds, 'mel': maya.mel}) or application context import __main__; exec(code, vars(__main__)) or even exec(code, vars(maya.cmds)) so we would optimize our scripts using direct getAttr('pCube1.v') and etc.

globals() is necessary, if you remove removable, it is almost impossible to execute long code. It creates a lot of "variable not defined" errors, despite you define it 2 line above. I'm affraid of predefining maya.cmds because some studio use other aliases than cmds (mc for instance). To me, using vars(main) seems even worst, because it means same picker could work or fail depend of what was imported somewhere else at some moment. You will test on your machine, it work, you provide to animator and boom, it fails because you imported in your script editor some variables during dev and not the animator.

luckylyk commented 1 month ago

Hi, FYI I just exposed a dwpicker.current_namespace() function which is now the safest way to gather the current namespace.

luckylyk commented 2 weeks ago

Hey I think I can close that ticket :)