Isotropix Forums

I'm discovering Python :) Noob blog !

Clarisse Scripting related topics

Re: I'm discovering Python :) Noob blog !

Unread postby bvaldes » Fri Jan 20, 2017 10:34 am

Hi,

Like Daaims said, there is no secret documentation, you have examples of GUI in the start page of the SDK documentation.
To access to it, inside Clarisse press F1 then on the left menu of the web page go to Reference> Scripting/API.
On the Main page you can find an "Introduction to GUI library" link (the last link of the page). This is a good start for GUI understanding.

Daaims' script show how to create most part of GUI items, it is always the same way:

python code

itemVar = ix.api.THE_GUI_ITEM(parent_widget, x_position, y_position, width, height, "label") 
# some GUI items do not have label or height parameter it is written in the SKD doc

To find a GUI item, search in the SDK documentation the key work "GUI" and you will find all the GUI items.

I hope that these information can help you to make beautiful GUI ;)

Cheers
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 101
Joined: Mon Sep 26, 2016 11:44 am

Re: I'm discovering Python :) Noob blog !

Unread postby atnreg » Fri Jan 20, 2017 10:46 pm

daaims wrote:Hi,

No secret documentation for me, i just ask around like is this topic for the button and pick some code here and there in the forum.

Cheers ;)


Ok, thanks, I had not seen that :)

Antti
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5RC2,Blender,(3D-Coat,ZBrush,Lightwave+Octane etc.)
Clarisse since 2016-09-29, Python since 2016-11-10 (Clarisse Py 2017-01-04)
I do all 3D stuff for fun, no business
atnreg
 
Posts: 171
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: I'm discovering Python :) Noob blog !

Unread postby atnreg » Fri Jan 20, 2017 11:01 pm

Like Daaims said, there is no secret documentation, you have examples of GUI in the start page of the SDK documentation.
To access to it, inside Clarisse press F1 then on the left menu of the web page go to Reference> Scripting/API.
On the Main page you can find an "Introduction to GUI library" link (the last link of the page). This is a good start for GUI understanding.


Thank you, yes I have read that and it is good START yes :)

Daaims' script show how to create most part of GUI items, it is always the same way:

python code

itemVar = ix.api.THE_GUI_ITEM(parent_widget, x_position, y_position, width, height, "label") 
# some GUI items do not have label or height parameter it is written in the SKD doc

To find a GUI item, search in the SDK documentation the key work "GUI" and you will find all the GUI items.


Yes I have managed to show various GuiWidgets but the problem is that for example the Daaim's list button code is totally different from the SDK docs :O According to the docs, Daaim's code should not even work but of course it works fine. So as the SDK doc is obviously not for Python, it is very hard to find out how to really use different widgets...

For example, I show a GuiListView and populate the list with text rows using Daaim's method i.e. .add_item('text).
But when I try to use that, the items are not selected by click and I have no idea what events that widget gets and how to react to them.

I hope that these information can help you to make beautiful GUI ;)


Well, not quite yet but if you kindly will help me more, then I might ;)

So could you (or anyone :)) please give simple code how to handle selection (single and multi) in GuiListView so that when I click a row, I get the row's index or some id to know what row was clicked on. It is probably not complicated but because I cannot guess the events, there is not much I can do. And as the list does not even highlight the clicked item, I'm wondering is this widget even meant or this kind of things? If not, please tell me how I can do such thing i.e. normal listbox with text items and handle the selection :)

Thank you very much!

Antti
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5RC2,Blender,(3D-Coat,ZBrush,Lightwave+Octane etc.)
Clarisse since 2016-09-29, Python since 2016-11-10 (Clarisse Py 2017-01-04)
I do all 3D stuff for fun, no business
atnreg
 
Posts: 171
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: I'm discovering Python :) Noob blog !

Unread postby bvaldes » Mon Jan 23, 2017 10:58 am

Hi Antti,

I made a new topic for your question, you can find it there: http://forum.isotropix.com/viewtopic.php?f=21&t=2817

Regards,
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 101
Joined: Mon Sep 26, 2016 11:44 am

Re: I'm discovering Python :) Noob blog !

Unread postby atnreg » Mon Jan 23, 2017 11:34 am

Thanks :)
Intel i7(6-core),32GB RAM,NVIDIA GTX690 (2GPU)+GTX Titan Black,Win10Pro 64bit
Clarisse 3.5RC2,Blender,(3D-Coat,ZBrush,Lightwave+Octane etc.)
Clarisse since 2016-09-29, Python since 2016-11-10 (Clarisse Py 2017-01-04)
I do all 3D stuff for fun, no business
atnreg
 
Posts: 171
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: I'm discovering Python :) Noob blog !

Unread postby daaims » Thu Apr 13, 2017 10:53 am

Hi there !

Here is a render with 4 point lights wich have different intensity and falloff mode.
OptimLight_Normal.jpg
OptimLight_Normal.jpg (14.5 KiB) Viewed 313 times

We can notice a big black area where nothing is visible, but lights rays still hitting the objects, they are evaluated...


Of course if you push up the exposure, you will see the black area
OptimLight_Exposure.jpg
OptimLight_Exposure.jpg (36.76 KiB) Viewed 313 times



But in the case (most of) you don't need to push too far the exposure you don't need the lights to be evaluated in those black area. So to speed up the render i use attenuation mode "Far Only" to stop lights rays. For this example the render time drop from 15 sec to 2.4 sec with the same result. But now i can't push up the exposure because i will see the limit between evaluated area and "pure" black area.

OptimLight_Optim_Exposure.jpg
OptimLight_Optim_Exposure.jpg (17.05 KiB) Viewed 313 times



I made a script to auto configure the attenuation for all legacy lights in the scene. It set the start and end attenuation automaticly depending on the falloff mode and the intensity to stop rays when the intensity is negligible.

Code: Select all
# Set a automatic falloff on all lights to Optimise render time.

result = {'treshold' : 8}

'''
------------------------------------------------------------------------------------------------------------------------------------------------------------
UI CLASS
------------------------------------------------------------------------------------------------------------------------------------------------------------
'''
class EventRewire(ix.api.EventObject):
    #These are the called functions by the connect. It is more flexible to make a function for each button
    def tresholdRefresh(self, sender, evtid):
        result['treshold'] = sender.get_value()

    def cancel(self, sender, evtid):
        sender.get_window().hide() #Hide the window, if it is done, the window is destroyed

    def run(self, sender, evtid):
        treshold = float(result['treshold'])/10000
        objects = ix.api.OfObjectVector()
        filter = "*"
        typeL = ["LightPoint", "LightSpot", "LightArea", "LightLinear"]
        for j in range(len(typeL)):
            ix.application.get_matching_objects(objects, filter, typeL[j])

        for i in range (objects.get_count()):
            is_disabled = ix.get_item(str(objects[i])).is_disabled()
            intensity = float(str(objects[i].attrs.intensity).split("[")[1].split("]")[-2])
            falloff = str(objects[i].attrs.falloff_mode)
            if falloff == "[2]":
                distOpti = (intensity/treshold)
            elif falloff == "[3]":
                distOpti = (intensity/treshold)**(1.0/2)
            elif falloff == "[4]":
                distOpti = (intensity/treshold)**(1.0/3)
            elif falloff == "[5]":
                distOpti = (intensity/treshold)**(1.0/4)
            if is_disabled == False:
                objects[i].attrs.attenuation_mode = 2
                objects[i].attrs.attenuation_far_end = round(distOpti, 1)
                objects[i].attrs.attenuation_far_start = round((distOpti - (distOpti/10.0)), 1)
        ix.log_warning(str(objects.get_count()) + " lights were optimised") #Display the result

'''
------------------------------------------------------------------------------------------------------------------------------------------------------------
UI GENERATION
------------------------------------------------------------------------------------------------------------------------------------------------------------
'''
#Window creation
clarisse_win = ix.application.get_event_window()
window = ix.api.GuiWindow(clarisse_win, 900, 450, 240, 140) #Parent, X position, Y position, Width, Height
window.set_title('Light Optimisation') #Window name

#Main widget creation <= this is the correct way to make a GUI, make a default widget and add inside what you want
panel = ix.api.GuiPanel(window, 0, 0, window.get_width(), window.get_height())
panel.set_constraints(ix.api.GuiWidget.CONSTRAINT_LEFT, ix.api.GuiWidget.CONSTRAINT_TOP, ix.api.GuiWidget.CONSTRAINT_RIGHT, ix.api.GuiWidget.CONSTRAINT_BOTTOM)

#Form generation
treshold = ix.api.GuiNumberField(panel, 90, 10, 140, "Optimisation : ")#Clarrisse_function(parent, X_position, Y_position, Width, Height, "label", 'this is a custom param to get the value without duplicate the CLASS')
description  = ix.api.GuiLabel(panel, 10, 30, 200, 40, "Higher is the value,") #Clarrisse_function(parent, X_position, Y_position, Width, Height, "label")
description2  = ix.api.GuiLabel(panel, 10, 50, 200, 40, "higher is the optimisation") #Clarrisse_function(parent, X_position, Y_position, Width, Height, "label")
cancelBtn = ix.api.GuiPushButton(panel, 10, 90, 100, 22, "Cancel") #The cancel button (destroy the script window)
runBtn = ix.api.GuiPushButton(panel, 130, 90, 100, 22, "Run") # The run button to run your script

#init values
treshold.set_value(result['treshold'])
treshold.set_range(5, 10)
treshold.enable_range(1)

#Connect to function
event_rewire = EventRewire() #init the class

event_rewire.connect(treshold, 'EVT_ID_NUMBER_FIELD_VALUE_CHANGING', event_rewire.tresholdRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(treshold, 'EVT_ID_NUMBER_FIELD_VALUE_CHANGED', event_rewire.tresholdRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(cancelBtn, 'EVT_ID_PUSH_BUTTON_CLICK', event_rewire.cancel) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(runBtn, 'EVT_ID_PUSH_BUTTON_CLICK', event_rewire.run) #connect(item_to_listen, what_we_are_listening, function_called)

#Send all info to clarisse to generate window
window.show()
while window.is_shown():
    ix.application.check_for_events()
window.destroy()


Cheers ;)
User avatar
daaims
 
Posts: 423
Joined: Fri Mar 22, 2013 1:17 am

Re: I'm discovering Python :) Noob blog !

Unread postby daaims » Thu Apr 27, 2017 4:22 pm

Hello there !

Here is a script to convert all map files called in your scene to .tx. The script set the created .tx files to all the TextureMapFile node present in your scene. Work with udim convention files too.

Just change the path of the folder that contain the maketx.exe

Code: Select all
# Convert textures to .tx and set them to the MapFiles in the scene

MakeTx = "\\\\192.168.20.3\ZTransfert\_Daims\Clarisse\_Scripts\MakeTx\maketx.exe"
import os

objects = ix.api.OfObjectVector()
filter = "*"
type = ["TextureMapFile", "TextureStreamedMapFile"]

udim_files = []

for j in range(len(type)):
    ix.application.get_matching_objects(objects, filter, type[j])

for i in range (objects.get_count()):
    tex_path = objects[i].get_attribute("filename").get_string()
    file = tex_path.split("/")[-1]
    ext = tex_path.split(".")[-1]

    if "<UDIM>" in file:
        name = file.split("<UDIM>")[0]
        dir = os.path.dirname(tex_path)
        list_dir = os.listdir(dir)
        matching = [s for s in list_dir if name in s]
        udim_files.extend(matching)
        if ext != "tx":
            for j in range(len(udim_files)):
                os.system(MakeTx + " --oiio " + dir + "/" + udim_files[j])
        udim_files = []

    else:
        if ext != "tx":
            os.system(MakeTx + " --oiio " + tex_path)

    if ext != "tx":
        ix.cmds.SetValues([objects[i].get_full_name() + ".filename[0]"], [tex_path.replace(ext, "tx")])


Let me know if the script don't work in some case, thanks.

Cheers ;)
User avatar
daaims
 
Posts: 423
Joined: Fri Mar 22, 2013 1:17 am

Re: I'm discovering Python :) Noob blog !

Unread postby jandersunstar » Thu Jun 08, 2017 10:07 pm

thanks for the script daaims, don't know why it was not working for me, maybe the network path, so I search in the internet and found another way to execute the maketx.exe, I use the IMPORT subprocess, and change it in your code:
Code: Select all
subprocess.call([MakeTx, '-v', '--oiio', tex_path])


cheers!

-Luis
User avatar
jandersunstar
 
Posts: 153
Joined: Fri Jun 06, 2014 9:21 pm
Location: Mexico City

Re: I'm discovering Python :) Noob blog !

Unread postby paq » Fri Jun 09, 2017 1:16 am

Hi daaims,

Today i want to share you a light scatterer.


I need to get a closer look at it, but I think this will saved me tons of time for my next project.
I need to lit a stadium 'by night', and I was scared I had to place thousands of lights by hand 8-)

So thanks a lot !
User avatar
paq
 
Posts: 301
Joined: Sat Jan 26, 2013 12:33 am
Location: Montréal

Re: I'm discovering Python :) Noob blog !

Unread postby paq » Fri Jun 09, 2017 3:50 am

Hi daaims,

So I have modified the lightscatter script to make it working with physical lights (easy), but do you have an idea how we could align spotlight type to match point normals from a Clarisse point cloud ? (some sort of 'use support normals' option like we have in Clarisse scatterer).

My goal would be to create support geometry in Houdini, and using Clarisse Point Cloud based on primitive center to generate lots of spotlights.

Otherwise I will deal with spherelights only if I can control spot orientation ;)
Again thanks a lot of the script !

ScatterScatterLights.jpg
ScatterScatterLights.jpg (57.24 KiB) Viewed 102 times
User avatar
paq
 
Posts: 301
Joined: Sat Jan 26, 2013 12:33 am
Location: Montréal

PreviousNext

Return to Scripting