Isotropix Forums

Using an overrides engine on arbitrary context

Clarisse Scripting related topics

Using an overrides engine on arbitrary context

Unread postby briansilva » Fri Feb 07, 2020 12:41 pm

Hello!

Is there a way to setup an arbitrary context and "lock" it, so it tracks overrides? I have a script that automates the setup of some objects in a context. I'd like to then allow the user to edit the attributes, but track them as overrides.

I know each context has an OfContextEngine, and I see there is an OfOverridesContextEngine class. But I can't quite figure out how/if I can set it on an arbitrary context through Python.

Is this possible? If so, any pointers in the right direction would be appreciated.

Thank you!
briansilva
 
Posts: 51
Joined: Mon Mar 25, 2019 12:43 pm

Re: Using an overrides engine on arbitrary context

Unread postby dboude » Fri Feb 07, 2020 5:39 pm

You could perhaps use a reference context. You create a context, populate it and export it as reference.

Then every change on object's attributes will be considered as overrides.

Let me know if this do the job.

Thanks
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1403
Joined: Mon Jul 03, 2017 10:51 am

Re: Using an overrides engine on arbitrary context

Unread postby briansilva » Mon Feb 10, 2020 3:35 pm

I would prefer not to have to export out a separate file, since the contents are generated dynamically. But that would be a workaround. Is there not a way to setup an OfOverridesContextEngine without a file reference?
briansilva
 
Posts: 51
Joined: Mon Mar 25, 2019 12:43 pm

Re: Using an overrides engine on arbitrary context

Unread postby anemoff » Mon Feb 10, 2020 6:11 pm

Hi,

You can create the context by script, with dynamic content, then convert that context into an external reference.
Here is a minimal example:

python code

# create a context with dynamic content
ctx = ix.cmds.CreateContext("context", "", "project://scene")
# add a cube for example
ix.cmds.CreateObject("box", "GeometryBox", ctx)
# ...

# now, convert the context as an external reference so that user edits are saved as overrides in the current project
# note: here you might want to check if the created output project file already exists, and maybe delete it if so
output_ref_file = "path/to/external/ref.project"
export_ok = ix.reference_export_context(ctx, output_ref_file )
print(export_ok)

This way your context will have overrides natively without having to mess with the engine manually.

In fact, OfOverridesContextEngine isn't designed to be used directly. It is just a base class to manage overrides and is meant to be derived. To be honest, we haven't tried this in Python and I can't guarantee that all the necessary bindings are defined to be able to define a new engine in Python.
But if you have the C++ SDK it is possible for sure. For example, the built-in Reference context engine (OfFileReferenceContextEngine) derives from it.

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

Re: Using an overrides engine on arbitrary context

Unread postby briansilva » Mon Feb 10, 2020 6:21 pm

Okay, thanks Anthony! And thanks for the example code.

For now we'll use an approach like this, just writing out to a file stashed in a safe place. Later down the road if I get the time to do it, I'll look at writing our own OfOverridesContextEngine subclass in C++ (and I'll get in touch again when that day comes. :)).

Cheers!
briansilva
 
Posts: 51
Joined: Mon Mar 25, 2019 12:43 pm


Return to Scripting
cron