Isotropix Forums

Correct use of enable_command_history() in scripted class ?

Clarisse Scripting related topics

Correct use of enable_command_history() in scripted class ?

Unread postby atnreg » Mon Mar 27, 2017 12:02 pm

Hi!

I actually reported this as general Clarisse import bug (again sorry for that) but then I realized that Clarisse works fine with normal import.
But I have my own scripted class that uses the code from menus/file/import_geometry.py but when using that with action button in that scripted class Attribute editor, it somehow messes the status of modified project :o
If I load that import_geometry.py to Script Editor and run from there, it works.

But when I click on button on my own scripted class Attribute editor, the import works fine but then strange behaviour starts:
If I change imported mesh (OBJ, no materials loaded on import), any change to that item's attributes does not add '*' to title and if I close Clarisse window, there is no warning about modified project :o
Even more strange is that even if I add a material and change its attributes, still no '*' in title :o
Only when I manually click on the imported mesh in 3D view AND use translate/rotate/scale, then finally the '*' appears and from that on everything works normally i.e. any change triggers that '*' even if I save the project until I use that script to import again.
And in some cases even moving the object later does not help, no change or add or anything in the project will trigger the '*' :o

I have found the reason and solution:
The rows that do enable_command_history() and disable_command_history(). If I comment those out, everything works fine.
Somehow it seems that enable_command_history() somehow locks commands from showing in log and also Clarisse stops reacting to any changes :o But still the import_geometry.py works when run as separate script and it has those commands as well :o

Please help, I'm lost! :)

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: Correct use of enable_command_history() in scripted clas

Unread postby bvaldes » Mon Mar 27, 2017 4:09 pm

Hi,

The command "enable_command_history()" is here to undo your work. You "open" the piece of code by this command (and "close" it with disable_command_history()) and if you press CTRL+Z, Clarisse will undo the action generated by the code between these commands.

I tried to reproduce your issue without success. I wrote this tiny script to reproduce what you described:

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")

classe = ix.api.ModuleScriptedClass.register_scripted_class(ix.application, "my_scripted_class", MyScriptedClassAction())

This is a simple scripted class with a button that execute the script contained in import_geometry.py. After importing the geo, if you click on the icon to close Clarisse, the warning window appears as usual.

Maybe the error is somewhere else. Could you please send us your script to investigate further?

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

Re: Correct use of enable_command_history() in scripted clas

Unread postby atnreg » Mon Mar 27, 2017 6:10 pm

Hi!

Thank you very much again for fast and thorough reply!

Actually, I was able to reproduce the problem with your code as well :o :)

But I found out that there is something you need to do to make it happen, so here is the exact procedure, using your code:
1. Start Clarisse and just in case do File/New/Empty
2. Open script editor and paste your code and run it
3. New/my_scripted_class
4. NOW *SAVE* the project so that the * disappears
5. Use the added my_scripted_class to import geometry. Still no * in title which is ok
6. Now go to imported object and change Translate X value
Object moves but STILL no * in title and of course no warning on close :o
You can add materials, geometry, do anything and none of those actions cause the * to appear :o

So having scripted class item saved with project and then using enable/disable command history causes weird behaviour :o
The problem goes away if those lines are commented out so it is not something else (or may be but not in that script).

Now you should be able to get the same result :)

Any ideas?

Thank you!

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: Correct use of enable_command_history() in scripted clas

Unread postby bvaldes » Tue Mar 28, 2017 10:33 am

Hi,

After more investigation, we've been able to reproduce your issue. However, this is not considered as an issue but as a limitation. Indeed, only commands can set the project's state as modified (the small *). So what's happen is expected about the import.

Could you try again something please:
- Try to import by using: menu>file>import>geometry => no * should be appear
- Create a material => * should be here now
- New project
- Use you script to import => no * should be appear
- Create a material = > * should be here now

Please could you also check if in your preference the History size is not set to 0: preference>general>History Size

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

Re: Correct use of enable_command_history() in scripted clas

Unread postby atnreg » Tue Mar 28, 2017 2:40 pm

Hi!

After more investigation, we've been able to reproduce your issue. However, this is not considered as an issue but as a limitation. Indeed, only commands can set the project's state as modified (the small *). So what's happen is expected about the import.


Hmm...I am not quite sure what you mean but it cannot be only limitation as it messes the whole detection of changes throughout the project :)

Could you try again something please:
- Try to import by using: menu>file>import>geometry => no * should be appear
- Create a material => * should be here now


Yes this works normally.

- New project
- Use you script to import => no * should be appear
- Create a material = > * should be here now


I cannot do that like this because the script creates the scriptedclass that needs to be added to project which of course adds the *. So I need to save the project and then do as you asked. And if the script has those enable/disable comand history commands, it behaves like I explained and you were able to reproduce :)

Please could you also check if in your preference the History size is not set to 0: preference>general>History Size


Definitely not, it's 1000 :)

So using enable/disable command history in scriptedclass or any script that is part of a loaded(or just saved) project causes Clarisse to behave VERY strangely (no change anywhere in project triggers the *) . So I removed those commands and now it is working fine.

But this cannot be accepted 'limitation' so please explain more :)

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


Return to Scripting