Isotropix Forums

Let clarisse "catch up" to script execution?

Clarisse Scripting related topics

Let clarisse "catch up" to script execution?

Unread postby bvz2000 » Mon Feb 11, 2019 11:09 pm

I am trying to programatically convert material linking into a shading layer.

Use this scene as an example:

Code: Select all
#Isotropix_Serial_Version 1.1

#Isotropix_Clarisse_Version 3.5
#Isotropix_Clarisse_Project_Version 0.94
GeometrySphere {
    name "sphere"
    #version 0.9
    #created 1549922559
    #modified 1549922576
    uv_maps "parametric"
    uv_maps_loaded yes
    shading_groups "surface"
    materials "matte"
    clip_maps ""
    displacements ""
    sg_shading_variables ""
    visibles yes
}
MaterialMatte {
    name "matte"
    #version 0.91
    #created 1549922564
    #modified 1549922567
    color 1 0.0 0.0
}


And here is a short version of my code:

Code: Select all
# ============== FIRST PART =======================
def create_image_node():

    # Create the image node
    image_node = ix.cmds.CreateObject("image", "Image", "Global", "project:/")
    ix.cmds.AddLayer(image_node.get_full_name() + ".layers", "Layer3d")

create_image_node()
# ============== FIRST PART =======================


# ============== SECOND PART =======================
def create_shading_layer():

    # Create the shading layer
    ix.cmds.CreateShadingLayerForItems(["project://image"], 1, "project:/")

create_shading_layer()
# ============== SECOND PART =======================



If I run this all at once, it does not work. The shading layer will be empty.

But if I select the first part and "Run Selection" that, then immediately select the second part and "Run Selection" on that, it does work. The shading layer contains the proper information.

So it appears that if the script runs as a single entity, somehow clarisse isn't "all caught up". I have to stop running in order for some key information to be processed, and only then can I get the second part to work.

So, how can I get something like the above code to work?

Thanks!
bvz2000
 
Posts: 402
Joined: Thu Nov 13, 2014 6:05 pm

Re: Let clarisse "catch up" to script execution?

Unread postby bvaldes » Tue Feb 12, 2019 10:31 am

Hi,

When you perform action in Clarisse, updates are triggered. Sometime in python, the updates are not done at the end of the function (to avoid freezing of the interface), the update are delayed.
That could occurs issues like yours, another example is create a box and try to add a material on it. It's impossible because the shading group is not created for now. To avoid these issues you can force Clarisse to update by using the following function:

python code

ix.application.check_for_events()

In you code, you have to set this function between part 1 and 2 and everything will works perfectly.

Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 315
Joined: Mon Sep 26, 2016 10:44 am

Re: Let clarisse "catch up" to script execution?

Unread postby dboude » Tue Feb 12, 2019 10:34 am

God Valdes strikes again !
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 699
Joined: Mon Jul 03, 2017 10:51 am

Re: Let clarisse "catch up" to script execution?

Unread postby bvz2000 » Tue Feb 12, 2019 6:54 pm

That is exactly what I was looking for! Thanks!
bvz2000
 
Posts: 402
Joined: Thu Nov 13, 2014 6:05 pm


Return to Scripting