Isotropix Forums

My scriptedclass items won't work in 3.5, please help! (CID)

Clarisse Scripting related topics

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby bvaldes » Mon Jun 05, 2017 11:41 am

Hello,

You are right, the "folder" attribute do not work with seed. We have added an issue in our bug tracker (#6981). Sorry for the inconvenience.

About CID, there is a tiny tip to find faster the way to reproduce custom attribute using CID:
Create the custom attribute like usual, then copy the icon with the custom attribute and paste it in a text editor. You should have something like this:

python code

#Isotropix_Clarisse_Clipboard_Serialization 0.94
my_scripted_class {
name "the_object_name"
#version 0.0
copy_from "project://scene/the_object_name"
custom_attributes {
rgb "MyCustomAttr" {
value 0.0 0.0 0.0
}
}
}


You can see bellow the custom_attribute section you have your custom attribute.

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

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby atnreg » Mon Jun 05, 2017 12:18 pm

You are right, the "folder" attribute do not work with seed. We have added an issue in our bug tracker (#6981). Sorry for the inconvenience.


Oh ok, so I did understand the CID usage, it just doesn't work for folder :)
But now that I also understand how to use the add_attribute in 3.5, that is not a problem and my old code already works :)
Actually, it was my fault it broke with 3.5 :oops:
I had used NUMBERS in add_attribute and then when I compared the old constants I noticed that VISUAL_HINT_DEFAULT was 34 in 3.0 but now it is 35, all I needed to do was to change that 34 to 35 in my code, no other changes were needed :) But of course now I also changed them to use the constants so from now on it works even if those constants change in the future :)

About CID, there is a tiny tip to find faster the way to reproduce custom attribute using CID:
Create the custom attribute like usual, then copy the icon with the custom attribute and paste it in a text editor. You should have something like this:
<snip>
You can see bellow the custom_attribute section you have your custom attribute.


Yes this is nice tip, I still have some code that I might change to CID and this way it will be a lot easier. Thanks!

BTW, I use PyCharm for Python development and of course I cannot debug the Clarisse code but other than that it works fine. BUT there is some strange things I would like to get fixed to make coding even easier:
In my code, I have
import ix
import ix.api
from ix.api import OfAttr

That works in Clarisse but PyCharm claims it cannot find OfAttr in the last import. And still it gives the code completion for OfAttr members, like those TYPE_ etc. Of course as I don't run the code in PyCharm that does not matter but now I cannot be sure my code is clean as there is always that error status.
Can you explain how should I do the imports so that it would be correct? It may be PyCharm-specific thing but if you have any ideas, please tell :)

But one thing I really miss in Clarisse is to see the Python error messages when running code. Usually those errors are shown in popup and log but sometimes Clarisse just crashes and I have no clue what happened.
I use logging so I can figure out where the crash happened but still no cause for it until I find out by examining my code. Usually those kind of errors come when some object is None and it is used but why those will not pop up the error but crash Clarisse?
Is it possible to make some general log that lists all errors and warnings regardless of Clarisse crashing or not? :)
I have tried to find solution to that in Python in general but it seems without Python console it is not possible. But is it possible to somehow direct the Clarisse Python 'internal' log to some file or something like that?

Thank you again!

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: 254
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby bvaldes » Mon Jun 05, 2017 1:57 pm

Hi again,

About import, you needn't import ix, ix.api... Import the module ix should be enough to get the autocompletion. The error you get by importing: "from ix.api import OfAttr" is due that python can't find a module called ix.api of can't find a package ix containing a module called api. For me this error is normal and I have no idea to solve it.

About the crashes, if the crash is due to python code, the code won't be launched. But if the crash is due to a Clarisse function that didn't work, you can't know it until Clarisse tries to execute it. In my view, there is no way to avoid this behavior.

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

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby atnreg » Mon Jun 05, 2017 3:23 pm

About import, you needn't import ix, ix.api... Import the module ix should be enough to get the autocompletion. The error you get by importing: "from ix.api import OfAttr" is due that python can't find a module called ix.api of can't find a package ix containing a module called api. For me this error is normal and I have no idea to solve it.


Yes I tried different combinations of imports but that was the only one that works in PyCharm so that I get the code completion to work for Clarisse functions and constants. Are you familiar with PyCharm? If so, can you give me details how to set up PyCharm project to work with Clarisse? :)

About the crashes, if the crash is due to python code, the code won't be launched. But if the crash is due to a Clarisse function that didn't work, you can't know it until Clarisse tries to execute it. In my view, there is no way to avoid this behavior.


Ok, pity. But for example when I tried the folder in CID, I got popup error but when I accidentally tried to use the object instead of str(object) in SetValues, Clarisse crashed. That logic I have not been able to figure out :D Can you explain that?

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: 254
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby bvaldes » Mon Jun 05, 2017 4:57 pm

Hi,

I don't use PyChar, so I can't help you on that side.

About set an object in SetValue(), it is because this function needs a string to work. I am not an engineer but I think that several things are done with this string inside of the function SetValue() and the code can't do it with an OfObject class.
To avoid this kind of issue I can give you a simple rule: if you have to put an object in function 99% of the time you have to set it as a string. If you have to get information from an object, you have to use the object itself (like the classes in Python)

Hope that helps, regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 141
Joined: Mon Sep 26, 2016 11:44 am

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby atnreg » Mon Jun 05, 2017 6:29 pm

bvaldes wrote:About set an object in SetValue(), it is because this function needs a string to work. I am not an engineer but I think that several things are done with this string inside of the function SetValue() and the code can't do it with an OfObject class.
To avoid this kind of issue I can give you a simple rule: if you have to put an object in function 99% of the time you have to set it as a string. If you have to get information from an object, you have to use the object itself (like the classes in Python)


Yes I know that, I just used the object by mistake :)
But that also means Clarisse internal code has no checking for parameter types which is very potential cause for many crashes ;)

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: 254
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby atnreg » Tue Jun 06, 2017 5:34 pm

CID works fine for attributes but I cannot get any CID action to work.

When I run the code below and add 'cidtest' scripted class item, the 'Dynamic Action' works fine but 'Cid Action' does nothing. Why?

Thanks! :)

Antti

Code: Select all
# sample code to make CID action but it does not work

from string import Template as TPL # just to make variables inside CID string easier

import ix
import ix.api
from ix.api import OfAttr

GRP="test"

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

    def on_attribute_change(self, object, attr, dirtiness, dirtiness_flags):
        # Do something when an attribute value is changing. To check
        # which attribute is changing use the attribute name.
        print "The attribute", attr.get_name(), "is changing"

    def on_action(self, action, object, data):
        # Called each time an action is pressed by the user
        actname=action.get_name()
        print "action:",actname

    def declare_attributes(self, cls):
        # Declare attributes and actions to the newly class
        # This method just after the class has been created with the optional CID
        attr = cls.add_attribute(
            'dynamic_attr_name',
            OfAttr.TYPE_LONG,
            OfAttr.CONTAINER_SINGLE,
            OfAttr.VISUAL_HINT_DEFAULT,
            'test'
        )
        self.add_action(cls, "dynamic_action", GRP)


# string using the CID syntax to declare attributes
my_cid = TPL('''
attribute_group "$GRP" {
   action "cid_action"
   color "testcolor"
}
''').substitute(globals())

ix.api.ModuleScriptedClass.register_scripted_class(
    ix.application, "cidtest", cidtest(), my_cid)
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: 254
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby bvaldes » Wed Jun 07, 2017 11:36 am

Hi,

This is a normal behavior, to set an action button working, you have to add this button like you did with "Dynamic Action".
If you want to a button on the top of your class, you have to declare all of yours attribute in the declare_attribute() function.

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

Re: My scriptedclass items won't work in 3.5, please help! (

Unread postby atnreg » Wed Jun 07, 2017 1:53 pm

bvaldes wrote:Hi,

This is a normal behavior, to set an action button working, you have to add this button like you did with "Dynamic Action".
If you want to a button on the top of your class, you have to declare all of yours attribute in the declare_attribute() function.

Regards


Hmm...but then why there is the 'action' keyword in CID and it is explained in CID manual page if it does nothing? :D
Or is that only for C++? :(

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: 254
Joined: Mon Sep 19, 2016 5:20 pm
Location: Helsinki, Finland

Previous

Return to Scripting