Page 1 of 1

Getting imported volume file object

Unread postPosted: Wed Apr 10, 2019 10:08 pm
by jboissinot
Hi,

I was wondering if it'd be possible to get the newly created object of an imported volume file.

Basically, I import a volume file with the import_volume() method, which returns the context that contains the volume file for some reason, while I was expecting to get the volume file object instead so that I can rename it and set some of its attributes.

Any idea on how I could get the volume file object?

In the meantime, I was also wondering why we need to use the IOHelpers API - ix.api.IOHelpers.import_volume() - while we can simply do ix.reference_file() for importing a reference file. I tried importing a volume file with ix.import_volume() but got an argument error.

Code: Select all
TypeError: import_volume() takes exactly 1 argument (2 given)


Thanks,
Jeremy

Re: Getting imported volume file object

Unread postPosted: Thu Apr 11, 2019 1:04 am
by sam
Hi Jeremy,

Have you looked at the documentation of IOHelpers? https://clarissewiki.com/4.0/sdk/class_i_o_helpers.html

I admit I'm also a little bit puzzled by the fact that the method returns a OfContext and not a OfObject. While it can make sense for the import_volumes it doesn't for import_volume

It looks to me that it's a typical case of copy/paste...

We should definitely improve it.

Anyway, that being said, I advise you to create the Volume Object yourself using the API and set the attribute.

python code

my_vdb = ix.application.get_current_context().add_object("my_vdb", "GeometryVolumeFile")

Re: Getting imported volume file object

Unread postPosted: Thu Apr 11, 2019 3:00 pm
by jboissinot
Hi Sam,

I did look at the IOHelpers doc and this is how I found out about the import_volume() method returning the context instead of the volume file object, and was therefore curious to ask about it.

Maybe this is something you could improve indeed.

I was thinking to get it by getting the objects of the context with the get_objects() method, but adding the volume file to a given context with add_object() and set its filename attribute seems to be a good workaround to me and does work fine.

Thanks for your advice,
Jeremy

Re: Getting imported volume file object

Unread postPosted: Thu Apr 11, 2019 6:42 pm
by sam
It's actually calling the low level API and it's fairly straight forward. So you should use this when creating items in Clarisse.

Re: Getting imported volume file object

Unread postPosted: Thu Apr 11, 2019 7:48 pm
by jboissinot
Ok thanks for the info Sam.

Quick questions though regarding your comment:

So you should use this when creating items in Clarisse.


- if add_object() works fine for importing a volume file, do you mean that it'd be better use rather than reference_file() for importing an alembic file?
- and generally speaking, will you use add_object() instead of create_object(), or it doesn't really make a difference?

Thanks,
Jeremy

Re: Getting imported volume file object

Unread postPosted: Thu Apr 11, 2019 7:55 pm
by sam
No, referencing is something else. Referencing creates a context (and not an object) of type Reference. Here you create an object of type GeometryVolumeFile inside a specified context.

Internally create_object uses at somepoint OfContext::add_object

Re: Getting imported volume file object

Unread postPosted: Thu Apr 11, 2019 8:14 pm
by jboissinot
Oh yes that's right, I was simply curious to see if we could use add_object() for alembic files just as the same way we could for volume files, but yes since there's no such object type for alembic files as they are created as contexts, we have no choice to use reference_file() then, which I'll keep using.

Ok thanks for the create_object() vs add_object() info.

Jeremy

Re: Getting imported volume file object

Unread postPosted: Fri Apr 12, 2019 12:41 am
by sam
Well you can if you use Alembic Bundles.