Isotropix Forums

GUI sub-category

Clarisse Scripting related topics

GUI sub-category

Unread postby jessvfx » Mon Sep 09, 2019 10:18 am

Hi,

How do you create a sub category/folder like the General tab in the attachment with python ? What GUI command do I need to use to do that ?

Thank you,
Jess
Attachments
Screenshot_1.jpg
Screenshot_1.jpg (10.26 KiB) Viewed 2416 times
jessvfx
 
Posts: 14
Joined: Wed Nov 28, 2018 2:43 am

Re: GUI sub-category

Unread postby anemoff » Mon Sep 09, 2019 11:28 am

Hi,

You can't create a group only. You need to create a new attribute along with its new group.
The command is:

python code

ix.cmds.CreateCustomAttribute(["path/to/item"], "attr_name", attr_type, [["container", "vhint", "group", "count", "allow_expression"], [container_type, visual_hint, group_name, attribute_value_count, allow_expression])


Where:
- attribute_type is a ix.api.OfAttr.TYPE_* from OfAttr::Type
- container_type is a ix.api.OfAttr.CONTAINER_* from OfAttr::Container
- visual_hint is a ix.api.OfAttr.VISUAL_HINT_* from OfAttr::VisualHint
- allow_expression is 0 or 1 to disable/enable expression

You can play with the Custom Attribute creator to see the commands that are used.

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

Re: GUI sub-category

Unread postby jessvfx » Mon Sep 09, 2019 11:39 am

Hi,
Thanks for the reply. I get that we have to create a custom attribute for this instance. However, I still have no idea where I should append the attribute to. Say I have this code right now :
Code: Select all
#Define default values
result = {'find_name' : "  ", "replace_name" : "  ", "remove_name" : "   "}

class EventRewire(ix.api.EventObject):
    def removeNameRefresh(self, sender, evtid):
        result['remove_name'] = sender.get_text()

    def findNameRefresh(self, sender, evtid):
        result['find_name'] = sender.get_text()

    def replaceNameRefresh(self, sender, evtid):
        result['replace_name'] = sender.get_text()

    def rename(self, sender, evtid):
        sel = ix.selection
        findName = result['find_name']
        replaceName = result['replace_name']
        removeName = result['remove_name']
        for sl in sel:

        #get name
            name = sl.get_name()

        #remove string
            name = name.replace(removeName, "")

        #replace string
            name = name.replace(findName, replaceName)
            ret = ix.cmds.RenameItem(sl.get_full_name(), name)


clarisse_win = ix.application.get_event_window()
window = ix.api.GuiWindow(clarisse_win, 900, 600,250, 150)
window.set_title('Multi Renamer')
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)

# Init variable
event_rewire = EventRewire()

attr = ix.add_attribute(panel,ix.api.OfAttr.VISUAL_HINT_FOLDER, "settings")
removeName = ix.api.GuiLineEdit(panel, 10, 10, 200, 22, "Remove :")
findName = ix.api.GuiLineEdit(panel, 10, 40, 200, 22, "Find :")
replaceName = ix.api.GuiLineEdit(panel, 10, 70, 200, 22, "Replace :")
runBtn = ix.api.GuiPushButton(panel, 110, 104, 100, 22, "Rename")

event_rewire.connect(removeName, 'EVT_ID_LINE_EDIT_VALUE_EDITED', event_rewire.removeNameRefresh)
event_rewire.connect(findName, 'EVT_ID_LINE_EDIT_VALUE_EDITED', event_rewire.findNameRefresh)
event_rewire.connect(replaceName, 'EVT_ID_LINE_EDIT_VALUE_EDITED', event_rewire.replaceNameRefresh)
event_rewire.connect(runBtn, 'EVT_ID_PUSH_BUTTON_CLICK', event_rewire.rename)


window.show()
while window.is_shown():
    ix.application.check_for_events()
window.destroy()


I have a pop up window which is not a project item, I suppose. So where should I add the attribute to ?

Thank you.

Regards,
Jess
jessvfx
 
Posts: 14
Joined: Wed Nov 28, 2018 2:43 am

Re: GUI sub-category

Unread postby anemoff » Mon Sep 09, 2019 1:37 pm

Could you explain what you want to do with your widget?

Attributes belong to an OfItem (e.g a Camera, a geometry, a Context, a Texture, etc.).
You can't add OfAttributes to Gui elements.

However, you can create a custom OfItem with custom OfAttributes, and then inspect such object with an Attribute Editor. By doing this you would benefit of the Attribute Editor UI elements (like the folder picker, color picker, sliders, etc.).
Here is an example:

python code

ui_item = None

def create_ui_item(delete_existing = True):
item = ix.item_exists("project://ui_item")

if item and delete_existing:
ix.cmds.DeleteItems([item])

if not item:
# use ProjectItem as base classe
item = ix.cmds.CreateObject("ui_item", # item name
"ProjectItem", # item class
"project://") # parent context

# add a Filename Open attribute
file_attr = ix.cmds.CreateCustomAttribute([item],
"filename",
ix.api.OfAttr.TYPE_STRING,
["container", "vhint", "group", "count", "allow_expression"],
["CONTAINER_SINGLE", "VISUAL_HINT_FILENAME_OPEN", "My Group 1", "1", "1"])

# add a colro attribute
color_attr = ix.cmds.CreateCustomAttribute([item],
"color",
ix.api.OfAttr.TYPE_DOUBLE,
["container", "vhint", "group", "count", "allow_expression"],
["CONTAINER_ARRAY", "VISUAL_HINT_RGB", "My Group 2", "3", "1"])

return item

# Create the UI item
ui_item = create_ui_item()

# Open the UI item with an Attribute Editor
if ix.application.inspect(ui_item, ix.api.AppDialog.cancel(), ix.api.AppDialog.STYLE_OK_CANCEL, "My Custom UI With Attributes").is_ok():
print 'OK clicked: do something here ...'
print 'file: ', ui_item.attrs.filename
print 'color: ', ui_item.attrs.color
else:
print 'Cancel clicked'


For more complex things, I'd recommend a Scripted Class: https://www.clarissewiki.com/4.0/sdk/ex ... cript.html
This will allow you to use OfActions which are attributes that are shown as a button and perform an action when clicked.

You can check for more complex examples in the files process_uv_bake.py or export_alembic.py located in the folder in clarisse/python.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 369
Joined: Wed Jan 13, 2016 10:10 am

Re: GUI sub-category

Unread postby jessvfx » Tue Sep 10, 2019 4:40 am

Hi,

I'm just trying to create a simple multi renamer tool which has multiple functions such as find and replace, remove, as well as prefix sufix. I want to group the UI based on the function.
So, it means that I need to use the attribute editor instead of the GUI commands ?
jessvfx
 
Posts: 14
Joined: Wed Nov 28, 2018 2:43 am

Re: GUI sub-category

Unread postby anemoff » Tue Sep 10, 2019 9:41 am

Not necessarily. But you can't use OfAttr stuff in Gui stuff and vice versa.

Using the Attribute Editor has the advantage of creating UI items automatically based on OfAttr type (string, color, filename, etc.). But you need a ProjectItem to store the attributes. You have less control on how to place the UI elements: they are placed vertically automatically by the AE based on declaration order. But they are always placed nicely.

Using Gui objects needs a little bit more boilerplate (positions, events, etc.) but you are free to create almost anything you want.
However, not all Gui classes are exposed in Python, but essential types should be available.

To create a filename field you can use:

python code

fileEdit = ix.api.GuiFilenameField(panel, 100, 100, 100, "File :")
fileEdit.set_mode(ix.api.GuiFilenameField.MODE_OPEN)
fileEdit.set_browser_properties("Chose a file", "Alembic\t*.{abc}\nUSD\t*.{usd,usdc,usda}") # title and file filter
file = fileEdit.get_filename()

Available modes:
- MODE_SAVE: to chose a file to save into
- MODE_OPEN: to chose a file to open
- MODE_FOLDER: to chose a folder

Check the following links if you haven't already:
- https://www.clarissewiki.com/4.0/sdk/of_intro.html
- https://www.clarissewiki.com/4.0/sdk/cid_intro.html
- https://www.clarissewiki.com/4.0/sdk/gui_intro.html
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 369
Joined: Wed Jan 13, 2016 10:10 am

Re: GUI sub-category

Unread postby jessvfx » Tue Sep 10, 2019 12:19 pm

I see. Thank you so much for the explanation. I will surely check those links out. :)

cheers,
Jess
jessvfx
 
Posts: 14
Joined: Wed Nov 28, 2018 2:43 am


Return to Scripting