Isotropix Forums

Only allow one instance of custom ModuleScriptedClassEngine

Clarisse Scripting related topics

Only allow one instance of custom ModuleScriptedClassEngine

Unread postby Braden99 » Mon Jan 14, 2019 7:25 pm

Hey

I was wondering if you create a custom ModuleScriptedClassEngine, with some configuration options, and you really only want to allow for one instance of this item to be created, is it possible?

I'm thinking it might be nice for the class / item to act as a singleton in this particular case.

The expectation might be that if another item is attempted to be created, the return value is the existing item (otherwise new item).

Cheers
Braden
Braden99
 
Posts: 47
Joined: Mon Jan 08, 2018 3:05 am

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby Braden99 » Tue Jan 15, 2019 10:23 pm

I don't require this now, however it was more of a curiosity.

I see the method create_instance_data of ModuleScriptedClassEngine which seems responsible for returning new items on demand. Though I can't see a way to make it return an existing ModuleScriptedClassEngineData of the possibly already existing item in the project.
Braden99
 
Posts: 47
Joined: Mon Jan 08, 2018 3:05 am

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby sam » Wed Jan 16, 2019 8:25 am

Hi there,

No there is no concept of singleton in Clarisse. However, you shouldn't never have to call ModuleScriptedClassEngine::create_instance_data it is automatically called when you call ModuleScriptedClass::get_instance_data() which is associated to the OfObject you are manipulating.

You should never manipulate a ModuleScriptedClassEngine.

The thing is that ModuleScriptedClassEngine is the Python implementation bound to your custom ModuleScriptedClass. It is then used internally by your custom ModuleScriptedClass to call the appropriate Python callbacks in your custom ModuleScriptedClassEngine.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1358
Joined: Fri Jan 25, 2013 11:33 pm

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby Braden99 » Wed Jan 16, 2019 8:38 pm

So just to clarify in Python you don't implement ModuleScriptedClass, rather you implement ModuleScriptedClassEngine (and possibly ModuleScriptedClassEngineData).

Clarisse itself then has a matching ModuleScriptedClass, which is defined by the ModuleScriptedClassEngine Python implementation.
Braden99
 
Posts: 47
Joined: Mon Jan 08, 2018 3:05 am

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby sam » Wed Jan 16, 2019 9:05 pm

Yes. Look at the Extending classes in script topic in the SDK docs.
Cheers,
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1358
Joined: Fri Jan 25, 2013 11:33 pm

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby Braden99 » Thu Jan 17, 2019 3:36 am

I couple of quick things I noticed about scripted class and CID.

The CID keyword locked didn't work as expected on Clarisse 3.6sp5. When an item is created with "locked yes", it still shows unlocked. Even if the attribute is set to locked in the declare_attributes method, the item is still created with unlocked attribute.

The API documentation called extending_classes_in_script.html shows an example implementation of ModuleScriptedClassEngine, using a CID which does not start with the class name and inheritance definition, as shown on the cid_intro.html document.

When I tried to use the CID example shown in cid_intro.html document on Python class to either make entire new class, or inherit from another, I get this error.
OfClassfactory.add: (2:1) Wrong number of values.
An error has occured while trying to set attributes on MaterialTest. The registration is incomplete!


Using a CID that does not specify the class or possibly inheritance works as expected, but then it's not possible to set the overall items doc for example.
Braden99
 
Posts: 47
Joined: Mon Jan 08, 2018 3:05 am

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby sam » Thu Jan 17, 2019 7:27 am

Hi Braden,

Mhhhh where did you see the lock keyword? I can't find it in the documentation of the CID. I just woke up though :D

The full CID syntax (with class definition etc...) can only be used when creating C++ modules where you can create a class from scratch.
Python doesn't allow to create such classes. You can only provides Python implementation to engines. Then the register_scripted_class helper derives a new class with the name you give and stuff it with the python implementation engine.

We just offer the support for CID syntax to declare attributes to avoid declaring all your attributes with tedious lines of code in the declare_attributes method. So full CID isn't supported in Python.

Hope this makes thing clearer
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1358
Joined: Fri Jan 25, 2013 11:33 pm

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby Braden99 » Thu Jan 17, 2019 10:44 am

Thanks for the clarification.

I think I was looking at a Clarisse project file with the locked argument in it, and assumed it was supported by CID syntax as well.
Braden99
 
Posts: 47
Joined: Mon Jan 08, 2018 3:05 am

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby sam » Thu Jan 17, 2019 11:29 am

You're welcome.

I see. Actually while very close, because they are relying on the same parser, CID and project files aren't the same.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1358
Joined: Fri Jan 25, 2013 11:33 pm

Re: Only allow one instance of custom ModuleScriptedClassEng

Unread postby Braden99 » Thu Jan 17, 2019 12:04 pm

So is it possible to extend an existing Clarisse class, as a new scripted class, given that the inheritance which might be defined in CID syntax cannot be used for Python scripted class?

I also noticed the built in classes / items have basic documentation strting which can be queried via cls.get_class_doc() which returns a const CoreString & in C++, and a string in Python. The set_class_doc doesn't appear to be exposed in Python. It doesn't appear this string is exposed to user anywhere in Clarisse UI. Which might be useful to indicate to user what custom item does.
Braden99
 
Posts: 47
Joined: Mon Jan 08, 2018 3:05 am


Return to Scripting
cron