Isotropix Forums

open_items_in_widget() update selection

Clarisse Scripting related topics

open_items_in_widget() update selection

Unread postby atnreg » Mon Oct 19, 2020 5:34 pm

Hi!

I want to open my own ScriptedClass object in Attribute Editor. Inspect is otherwise fine but it does not allow using Clarisse while inspecting.
I found a promising function open_items_in_widget() and it works but it always changes the selection as well to show the ScriptedClass. There is option update_selection in that function but it has no effect.

What is the best way to show Attribute Editor for ScriptedClass so that it opens in floating window and does not change the global selection? In addition, if there is object reference attribute in it and I click on the arrow to jump to that object, it should not change the floating Attribute Editor's selection but the Clarisse Global selection.

Is that possible?
Also is it possible to control the Attribute Editor's Lock Selection state from Python?

Thank you!

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 5.0(always latest SP),Houdini,Blender,ZBrush,Fusion360,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 597
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: open_items_in_widget() update selection

Unread postby anemoff » Tue Oct 20, 2020 2:30 pm

Hi Antti,

The parameter "update_selection" should do what you guessed, but for some reason, it doesn't in this case. I haven't found out why.

Here is an alternative. Not very elegant but it works.

python code

# backup previous selection
prev = []
for item in ix.selection:
prev.append(item)

ix.application.open_items_in_widget('WidgetAttributeEditor', items, True, False)

# restore previous selection
ix.selection.deselect_all()
for item in prev:
ix.selection.add(item)


atnreg wrote:Also is it possible to control the Attribute Editor's Lock Selection state from Python?

Sadly no. The API of WidgetAttributeEditor is not exposed in Python. This is valid for all modules, including all Widget modules: no Python bindings.
And GuiViewPort, which is the class you would have needed, isn't exposed either.
Sorry.

Cheers,
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 391
Joined: Wed Jan 13, 2016 10:10 am

Re: open_items_in_widget() update selection

Unread postby atnreg » Tue Oct 20, 2020 4:02 pm

Hi!

Thank you very much, the selection trick is nice :)
But as the lock cannot be controlled, I cannot use this as I want to make floating window that stays on top and if I click on the link arrow, it should change the global selection but keep showing my ScriptedClass in the floating window.

So it seems that is not possible and so I'm afraid I will need to build my own Gui using the GuiXXX. I have done some simple testing with those but haven't done anything real with them but that way I can do much more so it will probably be worth the study :)

Is the Script Editor reliable in code completion i.e. if I find some GuiXXX there, can I trust that it can be used in Python?

And has debugging Python code in Clarisse improved? It has been impossible but it would make living SOOO much easier (I'm using VSCode).
BTW, is it possible to access the Script Editor code completion so that it would be possible to generate symbols for VSCode? That also would help a lot :)

Thank you!
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 5.0(always latest SP),Houdini,Blender,ZBrush,Fusion360,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 597
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: open_items_in_widget() update selection

Unread postby anemoff » Tue Oct 20, 2020 5:47 pm

atnreg wrote:Is the Script Editor reliable in code completion i.e. if I find some GuiXXX there, can I trust that it can be used in Python?

In theory yes. All symbols that appear in the autocompletion list have Python bindings. But we can't guarantee that all the existing bindings work 100% correctly. But the cases that don't work are sparse.

atnreg wrote:And has debugging Python code in Clarisse improved? It has been impossible but it would make living SOOO much easier (I'm using VSCode).
BTW, is it possible to access the Script Editor code completion so that it would be possible to generate symbols for VSCode? That also would help a lot :)


Nothing has been done yet to improve the scripting experience inside Clarisse. It's not a priority at the moment, to be honest.

If you can call Clarisse Python API from VS Code, you can run the following Python code to build and get the autocomplete list:

python code

# Get Python's scripting engine instance (OfObject)
py_engine = ix.application.get_scripting_engine_object("ScriptingPython")
assert py_engine

# Get Python's ModuleScripting
py_scripting_module = py_engine.get_module()

# Get Python's ModuleLanguage
py_language_module = py_scripting_module.get_language()
assert py_language_module

# Build the autocompletion list if not already built
if py_language_module.is_rebuild_completion():
if not py_scripting_module.build_completion_list():
ix.log_error('Failed to build Python autocompletion list.')

# Get the autocompletion list (ix.api.CoreStringVector)
list = py_language_module.get_completion()
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 391
Joined: Wed Jan 13, 2016 10:10 am

Re: open_items_in_widget() update selection

Unread postby atnreg » Wed Oct 21, 2020 4:57 pm

Hi!

Ok, thanks for the info!

I added this piece of code before your code:
Code: Select all
import sys

sys.path.append("C:/Program Files/Isotropix/Clarisse iFX 4.0 SP12/Clarisse/python")

if not "ix" in sys.modules:
    import ix
    import ix_helper
    ix = ix_helper.ix


I tried to run that code in VSCode but it failed (on import ix):
tmp_capture_01765.png


I tried different variations on the imports but always the same problem. I have tried to run Clarisse Python outside Clarisse before but even with help here it always fails.

Another problem is, what should I do with the 'list' IF I somehow get that code to work? :D

Any ideas?

Thank you!
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 5.0(always latest SP),Houdini,Blender,ZBrush,Fusion360,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 597
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: open_items_in_widget() update selection

Unread postby anemoff » Wed Oct 21, 2020 5:21 pm

The easiest way to go would be to run the code directly from Clarisse and then dump the list into a file. Then it's up to you to find what to do with it.

The file will need to be updated after each Clarisse. So it's not necessary to generate it on demand from VS Code. Just have VS Code get the updated file, or have one file per Clarisse release. These are just ideas.

I don't know how VS Code extension development works, but I'm pretty sure you'll find lots of tutorials on how to create an extension to suggest autocompletion for custom languages/APIs.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 391
Joined: Wed Jan 13, 2016 10:10 am

Re: open_items_in_widget() update selection

Unread postby atnreg » Wed Oct 21, 2020 5:48 pm

Ok, now I understand, will need to study how VSCode can use that list. Do you use such system or do you only use VSCode for some simple scripts? And how do you debug Python code for Clarisse? :)

Thank you!
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 5.0(always latest SP),Houdini,Blender,ZBrush,Fusion360,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 597
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: open_items_in_widget() update selection

Unread postby anemoff » Thu Oct 22, 2020 9:33 am

We don't do very complex Python development ourselves, it's mostly basic menu scripts, helpers, and some shelf tool scripts.
Generally, we end up debugging the C++ code called by Python. Otherwise, there's still the good old 'print' and try/except directly in the script.
:D
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 391
Joined: Wed Jan 13, 2016 10:10 am

Re: open_items_in_widget() update selection

Unread postby atnreg » Thu Oct 22, 2020 5:13 pm

Ok :)

Yes I know those but they (especially print) are quite hard to use as debug tools. I hope you will add this feature to next major version, or at least when Python3 will become the standard in Clarisse ;)

Antti
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 5.0(always latest SP),Houdini,Blender,ZBrush,Fusion360,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 597
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland


Return to Scripting
cron