Page 1 of 1

Maintaining context hierarchy upon import

Unread postPosted: Tue Jan 14, 2020 5:19 pm
by shadow92
Hey folks,
I was wondering if there is a way how to maintain a context hierarchy of imported project into another one instead of it collapsing into a context named after imported project.
Im not sure if it's clear enough like this, so I will provide an example:

In my scenes I use a predefined set of contexts, such as:

<==== these are on same level, couldn't think of better way how to describe the structure

Now let's say I have an empty scene with context set up like on example above. I have another project, let's say KB3D_Assets. This project would contain only KB3D buildings, textures and materials, structured according the same hierarchy as above (geometry in "objects", materials in "materials", etc). Purpose of it is to act as import-ready project, so I can create it once and then put it into my projects whenever I need without the need of starting from scratch.

My problem is that when I import this KB3D project into my main one, instead of "merging" the same contexts together (just like folders in Windows, for example), it creates a new context under Project/Scene called "KB3D_Assets", with it's hierarchy and all the content inside of it.

I hope it's clear what Im attempting to do from this. Can it be achieved? How would you go about it?

Entire purpose of this is to have a library of import-ready assets such as those from KB3D, or some set of trees, whatever. Just to create it once and then just import it whenever needed, without breaking the context structure etc.


EDIT: I tried also using a command ix.cmds.MergeProject, but it doesnt merge the contexts together, instead it creates context named like "objects1", "materials1", etc...

EDIT2: It looks like using commands to rename and move contexts to correct place could be the way to do it (I want use commands instead of doing it manually so I can save that script to shelf). I can import project, rename context, delete context using ix.cmds commands, however I cant figure out how to Copy/Paste or cut/paste context from one location to another using ix.cmds. Any idea? I cant find it anywhere.

Re: Maintaining context hierarchy upon import

Unread postPosted: Wed Jan 15, 2020 9:54 am
by dboude

Copy, Cut, Paste are application commands. It starts with ix.application.

You have some example here :


Re: Maintaining context hierarchy upon import

Unread postPosted: Sat Jan 18, 2020 11:08 am
by shadow92
Hey dboude,
thanks for you reply. And sorry for a delay in my answer - I did not actually understand the function of those scripts in link you provided, to be honest. I could not make it work that way,
however I managed it to work with ix.cmds.MoveItemsTo, which does exactly what I was looking for. And, what is important, it does not break the link between assigned materials.

But I have other question related to this - I'm using my dropbox path to import these scenes and I noticed clarisse messes up the file path upon import:

Script says
ix.cmds.ImportProject(["C:\Dropbox\my name\Clarisse Scenes\..."])

And I get an error:
Failed to import project 'C:\Dropboxmy name\Clarisse Scenes\...'.

As you can see it replaces part of the path with  for some reason

Re: Maintaining context hierarchy upon import

Unread postPosted: Sat Jan 18, 2020 6:21 pm
by shadow92
Found the answer on discord (thanks Yanik):

proper path should be like:
ix.cmds.ImportProject([r"C:\Dropbox\my name\Clarisse Scenes\..."])

notice the r added before the opening quotation mark of the filename. It is a raw string, otherwise it can mess up the path name

Re: Maintaining context hierarchy upon import

Unread postPosted: Mon Jan 20, 2020 9:24 am
by dboude
Cool that you found a way to do what you want.