Isotropix Forums

Get Matching Context

Clarisse Scripting related topics

Get Matching Context

Unread postby jessvfx » Thu Oct 17, 2019 4:49 am

Hi,

I'm trying to create a script and I need to check if a context already exists inside the scene. I'm using the get_matching_contexts but I keep getting error. I tried and broke it down only to this and I still get error.
Code: Select all
result = ix.api.OfObjectVector()

ix.application.get_matching_contexts(result,"chr*", "project:/")


This is the error that I get :
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "C:/Program Files/Isotropix/Clarisse iFX 4.0 SP2/Clarisse/python\framework.py", line 14641, in get_matching_contexts
return _framework.AppObject_get_matching_contexts(self, result, filter, base_context)
TypeError: in method 'AppObject_get_matching_contexts', argument 2 of type 'CoreSet< OfContext * > &'

Any idea why ? Or is there a better way for me to do this ? Help please, thank you.

Cheers,
Jess
jessvfx
 
Posts: 11
Joined: Wed Nov 28, 2018 2:43 am

Re: Get Matching Context

Unread postby dcourtois » Thu Oct 17, 2019 9:00 am

This should work:

python code

result = ix.api.OfContextSet()
ix.application.get_matching_contexts(result, "chr*", ix.application.get_factory().get_root())


And for future reference, here are a few things to know about the Python API:
- The types reported in the errors are C++ types. They have equivalent in Python. For instance, if in an error message you see `CoreVector< OfObject * >` then the equivalent Python type is`ix.api.OfObjectVector`.
- The index of the arguments in the Python error start at 1

And here is how I fixed your script:
Knowing those 2 facts, read again the error that you got: the last line tells you that it is expecting a `CoreSet< OfContext * >` as the second argument. The line just before the last tells you that the second argument is `result`. So first fix, change result to `ix.api.OfContextSet()`
Then you get another error telling you that the 4th argument should be a `OfContext`. So instead of a path, pass a context.
User avatar
dcourtois
 
Posts: 68
Joined: Tue Jul 25, 2017 3:15 pm

Re: Get Matching Context

Unread postby jessvfx » Thu Oct 17, 2019 10:53 am

It works perfectly now !
Thank you so much for the help and for the explanation :D
jessvfx
 
Posts: 11
Joined: Wed Nov 28, 2018 2:43 am


Return to Scripting