Isotropix Forums

Starting Fresh with Python in Clarisse

Clarisse Scripting related topics

Starting Fresh with Python in Clarisse

Unread postby jrey » Thu Apr 17, 2014 7:32 am

Just trying to jump-start my Python tinkering I had to shelf a few months ago...
Could someone educate me on how to create a list of the selected objects? This is where I'm currently stuck.

Code: Select all

selCount = ix.selection.get_count()
myList=[]
for i in range(selCount):
    item = ix.selection[i]
    myList.append(item)
print myList



Best regards,
--Jon
jrey
 
Posts: 4
Joined: Thu Jan 02, 2014 11:00 pm

Re: Starting Fresh with Python in Clarisse

Unread postby julien » Thu Apr 17, 2014 8:51 am

Hi Jon,
your script looks fine, the variable myList gets filled with selection, and if you print item.get_name() inside the loop you will see all the items names.

Do you use the ple or a licensed version of Clarisse?

In PLE you can't iterate on more than 10 items of the selection, its a limitation of the script in PLE mode.

regards,

Julien
User avatar
julien
 
Posts: 306
Joined: Mon Nov 18, 2013 6:30 pm

Re: Starting Fresh with Python in Clarisse

Unread postby jrey » Fri Apr 18, 2014 5:51 pm

Thanks Julian, Appreciate your guidance :-) Previously I was learning python in maya but just dived back in with my interest in clarisse I was using the ple but now am on a license.

Ahhh item.get_name()... I think I was a bit out of my understanding of where to go next as it was outputting what appeared to be a list of the object types at the memory addresses which I'm not used to working with yet. I probably need to progress my script farther to see the actual results and not take such baby steps :-)

Basically what I'm hoping to create is a tool that will apply random bold coloured shaders to an imported alembic object for each face id to help expedite the lookdev process.

Thanks again,
--Jon
jrey
 
Posts: 4
Joined: Thu Jan 02, 2014 11:00 pm

Re: Starting Fresh with Python in Clarisse

Unread postby jrey » Fri Apr 18, 2014 9:12 pm

One other question I have is related to how the script editor seems to work in clarisse. Basically I,d like to execute one line at a time, have some feedback and then move to the next line while retaining the effect of the previous.
For instance, It seems that even trying to keep an imported module, typically at the top of a script, persistent after execution doesn't work. So I have to execute the entire script each time or copy all necessary parts into one consecutive script then execute it.

Any workflow hints would be greatly appreciated :-)

Best regards,
--Jon
jrey
 
Posts: 4
Joined: Thu Jan 02, 2014 11:00 pm

Re: Starting Fresh with Python in Clarisse

Unread postby sam » Fri Apr 18, 2014 9:40 pm

Hi Jon,

jrey wrote:Basically what I'm hoping to create is a tool that will apply random bold coloured shaders to an imported alembic object for each face id to help expedite the lookdev process.

I don't really see how you would achieve this. If you thought of creating a material in Python, well, you can't. What did you have in mind?

I believe, the easiest way would be that we add a Primitive ID (random color per primitive) mode to the Texture Utility. This is something we can do and which can be also useful.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1302
Joined: Fri Jan 25, 2013 11:33 pm

Re: Starting Fresh with Python in Clarisse

Unread postby sam » Fri Apr 18, 2014 9:48 pm

jrey wrote:For instance, It seems that even trying to keep an imported module, typically at the top of a script, persistent after execution doesn't work. So I have to execute the entire script each time or copy all necessary parts into one consecutive script then execute it.

What you are describing is more a interactive console (like running python in command line) rather than a script (executed once and non persistent)
Clarisse doesn't provide an interactive python mode but CNode does (cnode -interactive). I didn't thought it would be really useful in the GUI. Well as a matter of fact I guess you could use Clarisse Python Command port to do this. However, I warn you :) it's a non user friendly hack.

Take a look at the HTML documentation. There's a API/SDK reference part. You'll find in the Related Pages a section about using Clarisse Command Port. The command port allows you to send Python commands to the application while keeping everything persistent till the connection is closed.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1302
Joined: Fri Jan 25, 2013 11:33 pm

Re: Starting Fresh with Python in Clarisse

Unread postby jrey » Sun Apr 20, 2014 6:59 pm

Hi Sam, thanks for the great pointers, I was using 1.6 SP5 but when I installed Hyperion R4d I now see the Clarisse Command Port reference. Might take me a bit to set this up but I'm sure it will be extremely useful when it is up and running.

Though I haven't had a chance to sit down and start working on the tool again, this is the pseudocode I was going to work from. Correct me if I'm wrong but I thought all of this should be achievable via the ix module or with some other imported modules.

Get shader group count
For each do shader group
Create new material
Generate three random numbers 0-255
Apply to diffuse value
Assign shader to shading group
Repeat

I like your idea of having something like this as a built in utility. I'm sure you're aware that there is a definite possibility for the need to match lookdev from other production rendering engines to some extent and anything that would help expedite this process is always welcome :)
jrey
 
Posts: 4
Joined: Thu Jan 02, 2014 11:00 pm

Re: Starting Fresh with Python in Clarisse

Unread postby sam » Sun Apr 20, 2014 9:26 pm

Ok, at Shading Group level (face set) this is completely doable. I thought you meant at a random color for each face.
Your pseudo code is right. You need to look at ModuleSceneObject methods in the reference section of the html docs. You'll see assign_material() and get_shading_group_count() methods that will do the trick.

Instead of creating a Standard class material, I'll advise you to attach a Matte one (basically plain color + optional alpha)

The script you plan to do is pretty straight forward to write, once you get the basics.

In the Utility texture, we already provide Object ID, it wouldn't hurt to add Shading Group ID and Primitive ID
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1302
Joined: Fri Jan 25, 2013 11:33 pm

Re: Starting Fresh with Python in Clarisse

Unread postby sam » Tue Apr 22, 2014 9:51 am

Here's a small example:

Code: Select all
import random
obj = ix.selection[0]
geo = obj.get_module()
for i in range(geo.get_shading_group_count()):
    mat = ix.create_object(geo.get_shading_group(i) + "_mat", "MaterialMatte")
    mat.attrs.color[0] = random.random()
    mat.attrs.color[1] = random.random()
    mat.attrs.color[2] = random.random()
    geo.assign_material(mat.get_module(), i)
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1302
Joined: Fri Jan 25, 2013 11:33 pm


Return to Scripting