Isotropix Forums

I would like to modify all of the filename attrs in a node

Clarisse Scripting related topics

I would like to modify all of the filename attrs in a node

Unread postby bvz » Fri Feb 28, 2020 4:30 am

Hello,

I am trying to write a function that will modify the filename attrbute (the path) of any nodes selected.

For example, if I have a referenced alembic, an obj node, a texture map node, (or any other nodes that may refer to a file on disk), I want to be able to read and then change the paths that any of these nodes may have.

I also need this to work on alembic references where there may be more than one path listed in the the Filename attribute, even if some of these paths may be disabled (the eyeball is turned off).

I have this simplified code at the moment, but it does not list any referenced alembic files if that reference is "turned off" (i.e. no eyeball is present).

Code: Select all
item = ix.selection[0]
attr = item.get_attribute("filename")

core_array = ix.api.CoreStringArray()
attr.get_raw_values(core_array)
for path in core_array:
    print path


Any help greatly appreciated.
bvz
 
Posts: 69
Joined: Tue Dec 03, 2013 9:55 am

Re: I would like to modify all of the filename attrs in a no

Unread postby dupevfx » Fri Feb 28, 2020 10:33 am

Hey mate, have a look in this post: viewtopic.php?f=21&t=6049

I did a bunch of file management tools with this kinda thing so you should find what you need in there for your own
dupevfx
 
Posts: 29
Joined: Mon Oct 01, 2018 6:08 pm

Re: I would like to modify all of the filename attrs in a no

Unread postby bvz » Fri Feb 28, 2020 9:12 pm

This is super helpful, thanks. I'll probably steal a bunch of that code.

Unfortunately, as far as I can tell you are using the command:

context.get_attribute("filename").get_string()

to extract the file name. But this does not work with alembic references that have more than a single file in the reference list. That was why I used the get_raw_values() command to get all of the items in the list. But unfortunately this command only lists those items that are active. If any of those referenced files are disabled (the eye icon is off) then it is not included in the list.
bvz
 
Posts: 69
Joined: Tue Dec 03, 2013 9:55 am

Re: I would like to modify all of the filename attrs in a no

Unread postby sam » Fri Feb 28, 2020 10:11 pm

Hi Ben

You just need to use get_value_count() to return the number of strings in the attribute and then iterate using get_string(index)

python code

attr = ctx.get_attribute("filename")
for i in range(attr.get_value_count()):
print attr.get_string(i)
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1500
Joined: Fri Jan 25, 2013 11:33 pm

Re: I would like to modify all of the filename attrs in a no

Unread postby bvz » Fri Feb 28, 2020 11:04 pm

Excellent. Thank you!
bvz
 
Posts: 69
Joined: Tue Dec 03, 2013 9:55 am

Re: I would like to modify all of the filename attrs in a no

Unread postby bvz » Wed Mar 04, 2020 1:49 am

Hey Sam,

I finally got around to testing this, and it does not appear to work.

I have a referenced alembic file. In the Filename attribute I have 5 alembic files listed, but only one of them is "active" (i.e. the others have the eyeball turned off). When I run the following code, I still only get a value count of 1, and only the "active" alembic file is listed.

If I enable more than one alembic file in the list, then those will be listed correctly. But only files that have the eyeball enabled are ever listed.

Here is my code.

Code: Select all
ctx = ix.selection[0]
attr = ctx.get_attribute("filename")
for i in range(attr.get_value_count()):
    print attr.get_string(i)


and here is a sample file to test it on. Note how the code only returns the "visible" alembic files.

Code: Select all
#Isotropix_Serial_Version 1.2

#Isotropix_Clarisse_Version 4
#Isotropix_Clarisse_Project_Version 0.94
Reference "foo1" {
    #created 1583282585
    options {
        filename {
            value "/volatile/bvz/foo1.abc" "/volatile/bvz/foo2.abc" "/volatile/bvz/foo3.abc"
            value_disabled 2 1
        }
    }
}
bvz
 
Posts: 69
Joined: Tue Dec 03, 2013 9:55 am

Re: I would like to modify all of the filename attrs in a no

Unread postby anemoff » Wed Mar 04, 2020 6:21 pm

There are 2 traps here. :?

By default, get_value_count and get_string will ignore disabled values. To get them you must use them like this:

python code

ignore_disabled = False
for i in range(attr.get_value_count(ignore_disabled)):
print attr.get_string(i, ix.api.OfAttr.VALUE_PAGE_CURRENT, ignore_disabled)


There's some missing documentation that will be fixed in a future version.
See: https://www.clarissewiki.com/4.0/sdk/class_of_attr.html

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

Re: I would like to modify all of the filename attrs in a no

Unread postby bvz » Thu Mar 05, 2020 7:32 am

Thanks Anthony. That worked exactly as needed.
bvz
 
Posts: 69
Joined: Tue Dec 03, 2013 9:55 am


Return to Scripting