Isotropix Forums

How can I get a list of all Image nodes in a project?

Clarisse Scripting related topics

How can I get a list of all Image nodes in a project?

Unread postby bvz2000 » Tue Feb 10, 2015 9:53 pm

I see from other examples here how to step through a list of all selected items, but how do I either:

get a list of all items of type Image

or

simply get a list of all items which I can then filter using "is_kindof("image")


Thanks!
bvz2000
 
Posts: 404
Joined: Thu Nov 13, 2014 6:05 pm

Re: How can I get a list of all Image nodes in a project?

Unread postby bvz2000 » Tue Feb 10, 2015 10:26 pm

Ok, I managed to get this far:

ix.application.get_factory().get_classes().get_classes("Image")

but the issue is that I am running my code via the command port and this command just returns a string:

<framework.OfClassArray; proxy of <Swig Object of type 'CoreArray< OfClass * > *' at 0x5662cf0> >

Which is, of course, just the metadata about this actual object. I cannot access the object itself from my external python script. Any ideas where to go from here?

Also, could you explain the structure of the above command and how I would understand what each section does (i.e. how would I get to the above command by reading the existing docs?)

Thanks!


Edit:

Uggh. That doesn't work either. That simply lists all possible classes. For example, running this code in the script editor:

Code: Select all
itemsL = ix.application.get_factory().get_classes().get_classes()
for item in itemsL:
    print item.get_name()



will print a list of every class, not every object (which makes sense from the name of the methods I am calling).

But when I try to figure out how to get all object names (using get_all_objects), I just keep getting errors.

I think what I need is some guidance on how to decipher the docs with regard to what the "get_factory()" method returns, then what the first of the two "get_classes()" method returns and where to find that in the docs.
Last edited by bvz2000 on Tue Feb 10, 2015 11:02 pm, edited 1 time in total.
bvz2000
 
Posts: 404
Joined: Thu Nov 13, 2014 6:05 pm

Re: How can I get a list of all Image nodes in a project?

Unread postby sam » Tue Feb 10, 2015 10:59 pm

Hi,

What you are calling is not returning the actual image instances in your project. Instead it returns OfClasses
To achieve what you want:

Code: Select all
objects = ix.api.OfObjectArray()
ix.application.get_factory().get_objects("Image", objects)
result = []
for i in range(objects.get_count()):
    result.append(objects[i].get_full_name())
print result


ix.application inherits from AppObject. Look in the SDK/API documentation for all the methods available for this class.
Creatable classes and object model classes are available through ix.api.NameYourClass

For example if you need to create a GMathVec3d you need to do ix.api.GMathVec3d() in Python.
Hope this helps,
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1281
Joined: Fri Jan 25, 2013 11:33 pm

Re: How can I get a list of all Image nodes in a project?

Unread postby bvz2000 » Tue Feb 10, 2015 11:39 pm

It is helping, thank you. I had been trying to run the following command but it wasn't working:

Code: Select all
emptyList = list()
ix.application.get_factory().get_all_objects("Image", emptyList)


This makes more sense in that get_all_objects kept complaining about the python list.

Code: Select all
objects = ix.api.OfObjectArray()
ix.application.get_factory().get_objects("Image", objects)


There seems to be an issue with your code. get_objects does not return anything. get_all_objects, however, does work.

Thanks!
bvz2000
 
Posts: 404
Joined: Thu Nov 13, 2014 6:05 pm

Re: How can I get a list of all Image nodes in a project?

Unread postby bvz2000 » Tue Feb 10, 2015 11:43 pm

There is one more question though.

How would I access his information via the command port.

I am trying something like this:

Code: Select all
cl.run('objects = ix.api.OfObjectArray()')
iNodes = cl.evaluate('ix.application.get_factory().get_all_objects("Image", objects)')
print iNodes


but iNodes just comes back as "None"
bvz2000
 
Posts: 404
Joined: Thu Nov 13, 2014 6:05 pm

Re: How can I get a list of all Image nodes in a project?

Unread postby sam » Tue Feb 10, 2015 11:59 pm

get_objects doesn't return anything indeed (as in my code). The result is passed as argument. It requires a OfObjectArray (as in my example) :)

Passing a Python list to the method won't work.

Finally the method get_all_objects returns nothing. The result must be passed as argument (in your example it is objects). To see the result you must do something like evaluate("objects") and remember, the command port returns value as strings.
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1281
Joined: Fri Jan 25, 2013 11:33 pm

Re: How can I get a list of all Image nodes in a project?

Unread postby bvz2000 » Wed Feb 11, 2015 12:10 am

Aha! Thanks. I think I have it for the moment.


For anyone else, here is my code (this is meant to be run from a script external to clarisse):

Code: Select all
import clarisse_net as ix
cl = ix.ClarisseNet()

cl.run('objects = ix.api.OfObjectArray()')
cl.run('ix.application.get_factory().get_all_objects("Image", objects)')
iCount = cl.evaluate('objects.get_count()')
iNodesL = list()
for count in range(int(iCount)):
    iNodesL.append(cl.evaluate('objects[' + str(count) + ']'))
print iNodesL
bvz2000
 
Posts: 404
Joined: Thu Nov 13, 2014 6:05 pm


Return to Scripting