Isotropix Forums

Drop callbacks to execute Python function

Clarisse Scripting related topics

Drop callbacks to execute Python function

Unread postby Braden99 » Mon Dec 10, 2018 8:27 pm

It would be great if Clarisse had drop callbacks to execute Python code, for example the user dropped a string on to the Clarisse Image or 3d viewport.

This is pseudo code

Code: Select all
def my_drop_handler(data, *args, **kwargs):
    if data and isinstance(data, basestring):
        import my_asset_module
        result = my_asset_module.add_asset(str(data))
        return bool(result)
    return False

ix.api.callbacks.Callbacks.imageViewportDrop.connect(my_drop_handler)
ix.api.callbacks.Callbacks.3dViewportDrop.connect(my_drop_handler)


The string dropped could be for example some custom pipeline identifier of object and version (or just a file path).
Braden99
 
Posts: 52
Joined: Mon Jan 08, 2018 3:05 am

Re: Drop callbacks to execute Python function

Unread postby Braden99 » Tue Dec 11, 2018 8:23 am

It would also be very useful to have callbacks to run after a particular item creation.

This is pseudo code

Code: Select all
def image_created_callback(image_item, *args, **kwargs):
    if not image_item:
        return False
    import image_setup
    image_item.setup(image_item)
    return True

ix.api.callbacks.Callbacks.addCallback('ImageCreated', image_created_callback)
Braden99
 
Posts: 52
Joined: Mon Jan 08, 2018 3:05 am

Re: Drop callbacks to execute Python function

Unread postby sam » Tue Dec 11, 2018 9:49 am

Hi there,

This has been already discussed in the past. While I understand how cool that can be for a TD, I'm personally against this feature which is why it hasn't been implemented yet. One main reason besides the fact that there no persistent Python host in Clarisse:

Attaching Python callbacks to Clarisse evaluation engine would cripple Clarisse because of the GIL (Python can't be executed in parallel YET so that would potentially slowdown dramatically Clarisse dependency graph) Ultimately, attaching any Python code to things that are called many times in Clarisse is a very bad idea. This is the reason why for example we went down the road of SEExpr for Clarisse Expression language coming in 4.0. Honestly I wasn't a big fan of integrating a completely new language to Clarisse (we have Python, OSL and now SEExpr) but for performance reasons we had no other choices. Moreover, SEExpr is pretty simple to learn while very powerful.

All this to say that until the GIL issue isn't solved in Python, this is not likely to happen.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1401
Joined: Fri Jan 25, 2013 11:33 pm

Re: Drop callbacks to execute Python function

Unread postby Braden99 » Tue Dec 11, 2018 10:52 am

Thanks Sam. Obviously any major slow down in Clarisse evaluation engine should be avoided.

However I'm not really sure how they get around exposing Python callbacks in other software. For example.
https://help.autodesk.com/cloudhelp/201 ... backs.html
https://learn.foundry.com/nuke/develope ... backs.html
https://learn.foundry.com/katana/dev-gu ... vents.html

The callbacks I'm envisaging would run rarely and it would be up to the TD to be responsible for performance implications.
Braden99
 
Posts: 52
Joined: Mon Jan 08, 2018 3:05 am

Re: Drop callbacks to execute Python function

Unread postby sam » Tue Dec 11, 2018 12:16 pm

They do because I guess the dependency graph is not evaluated in parallel ;). If they are, then each time there's a python code attached then there's a big global lock to avoid having Python interpreter executing code in parallel (it would crash otherwise).

For example in Clarisse even attributes values (driven by expression) are lazily evaluated in parallel.

But I guess that if the callbacks are limited to object creation and destruction we could get our way around. Indeed, as the evaluation DG is the same as the interactive one we already solved this case in way. The thing is what kind of callbacks would you like to see? If they are very limited to a few things (such as object creation,destruction, renaming etc...) then we may do something about it.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1401
Joined: Fri Jan 25, 2013 11:33 pm

Re: Drop callbacks to execute Python function

Unread postby Braden99 » Tue Dec 11, 2018 6:58 pm

For me running a callback at object creation is all that is required. But yes at deletion and rename could also be useful.

Also providing a mechanism of triggering some Python code when a string identifier is dropped on to Clarisse app. For example a user might drag and drop a pipeline asset or texture on to various native Clarisse windows, which would be encoded as identifier string. The callback would use this to execute some Python code (create Clarisse item and set attrs for example).
Braden99
 
Posts: 52
Joined: Mon Jan 08, 2018 3:05 am

Re: Drop callbacks to execute Python function

Unread postby sam » Tue Dec 11, 2018 7:47 pm

I see. Well adding these kind of callbacks could be feasible in the future.

I think the callback to execute python code on drop is already a feature request but can't find the tracking ID.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1401
Joined: Fri Jan 25, 2013 11:33 pm

Re: Drop callbacks to execute Python function

Unread postby Braden99 » Tue Dec 11, 2018 8:36 pm

Also on a somewhat related note. Is it possible to currently add a custom button to any Item (for example Image or Layer3d), and for it to execute some Python code. This could be used for example to add a custom pipeline 'Render' button to these items, or 'Register' and so fourth. I had a look a while ago, and it doesn't seem possible, even though there is some API that sounds promising.
Braden99
 
Posts: 52
Joined: Mon Jan 08, 2018 3:05 am

Re: Drop callbacks to execute Python function

Unread postby sam » Wed Dec 12, 2018 7:27 am

Unfortunately this is only possible in C++ for now. While you can add new attributes in Python, you can't add an attribute of type action to an existing class. This is the feature request #6138 FYI
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1401
Joined: Fri Jan 25, 2013 11:33 pm

Re: Drop callbacks to execute Python function

Unread postby mati » Thu May 09, 2019 12:37 am

Hi. Was a feature request submitted for the Python callbacks idea? I don't see it in the new feature request tracker. Wanted to express support for it or create a request.
mati
 
Posts: 26
Joined: Fri Apr 19, 2019 8:35 pm

Next

Return to Scripting