Isotropix Forums

Set attribute or action doc string in Python?

Clarisse Scripting related topics

Set attribute or action doc string in Python?

Unread postby atnreg » Tue Aug 22, 2017 10:07 am

Hi!

CID is great for static attributes but its 'action' keyword does not work at all for Python (action appears but it is not detected by on_action event) and of course if the attributes/actions are dynamically created, CID cannot be used. There is the 'doc' keyword in CID which is great but how to set the doc string for any attribute/action in Python? I've found get_doc but not set_doc so I'm afraid that is not possible. As it would be very much needed, please tell me if there is way to do that in Python :)

And if currently not, then please add it to Python soon :)

Thanks!

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

Re: Set attribute or action doc string in Python?

Unread postby bvaldes » Mon Aug 28, 2017 12:26 pm

Hi,

The documentation is declared inside of the CID for a standard attribute (not action). For action, this is more complicated but this is an example for the both:

python code

class MyScriptedClassAction(ix.api.ModuleScriptedClassEngine):
def __init__(self):
ix.api.ModuleScriptedClassEngine.__init__(self)

def on_action(self, action, object, data):
if action.get_name() == "my_custom_action":
# ix.enable_command_history()

app = ix.application
title = "Import Geometry Files..."
filter = "Known Files\t*.{lwo,obj}\nLightWave Object Files\t*.lwo\nWavefront Object Files\t*.obj"
filenames = ix.api.GuiWidget.open_files(app, app.get_current_project_filename(), title, filter)
if filenames.get_count() > 0:
clarisse_win = app.get_event_window()
clarisse_win.set_mouse_cursor(ix.api.Gui.MOUSE_CURSOR_WAIT)
app.disable()
ix.import_geometries(filenames)
app.enable()
clarisse_win.set_mouse_cursor(ix.api.Gui.MOUSE_CURSOR_DEFAULT)

# ix.disable_command_history()

def declare_attributes(self, cls):
self.add_action(cls, "my_custom_action", "action_group")
# This is the line to set the documentation of the action button
ix.application.get_factory().get_classes().get("my_scripted_class").set_attr_doc("my_custom_action", "The Action Documentation")

def on_attribute_change(self, object, attr, dirtiness, dirtiness_flags):
print "The attribute", attr.get_name(), "is changing"


my_cid = """
color "ploupe"{
texturable yes
doc "This is a doc"
}
color "another_color"{
doc "This is another doc"
}
"""
ix.api.ModuleScriptedClass.register_scripted_class(ix.application, "my_scripted_class", MyScriptedClassAction(), my_cid)

At line 26, you can the command that enables the documentation for an Action attribute. This is a bit long because to set a doc on an attribute you have to use set_attr_doc() and this is a method of an OfClass object. To all the beginning of the line allow you to get the OfClass() object.
The function works like this: set_attr_doc("attr_name", "The documentation test").
About the classic attribute, you just have to add a line doc inside of the CID like lines 35 & 38.

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

Re: Set attribute or action doc string in Python?

Unread postby atnreg » Mon Aug 28, 2017 1:35 pm

Hi!
Thank you VERY much, yes it is a bit more complicated to use but with your excellent example I now have generic function (of course as function it is very simple but it hides that long class path) for that and it works perfectly :mrgreen:

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


Return to Scripting