Isotropix Forums

OfContext.resolve_contexts() does not return disabled ones

Clarisse Scripting related topics

OfContext.resolve_contexts() does not return disabled ones

Unread postby mhamid3d » Tue Feb 25, 2020 7:20 pm

Hello,

I am trying to resolve all contexts in a context by using
Code: Select all
OfContext.resolve_context()
but it only returns the contexts' that are enabled. Is there a way to retrieve all contexts in a contexts, regardless of whether or not they are enabled?
mhamid3d
 
Posts: 8
Joined: Wed Dec 04, 2019 5:20 pm

Re: OfContext.resolve_contexts() does not return disabled on

Unread postby anemoff » Wed Feb 26, 2020 2:22 pm

Hi,

By default, get_contexts, resolve_contexts, and resolve_all_contexts (and many other getters) will return only enabled objects (because they use a default mask for enabled objects only). To customize the result, you need to specify a mask, in this case, an empty mask to get all objects.

See these doc pages:

OfItem: https://www.clarissewiki.com/4.0/sdk/class_of_item.html
  • OfItem::Flag
  • OfItem::empty_flags_mask -> predefined mask with no flag filter (i.e. get all objects)
  • OfItem::enabled_flags_mask -> predefined mask to get enabled objects only

OfContext: https://www.clarissewiki.com/4.0/sdk/cl ... ntext.html
  • get_contexts: returns only direct sub-contexts of the current calling context
  • resolve_contexts: resolves all direct sub-contexts (i.e. solves instances)
  • resolve_all_contexts: resolves all sub-contexts recursively (i.e. solves instances)
  • These functions have 2 parameters, the 2nd is the mask and its default value is OfItem::enabled_flags_mask.

However, there's a bug in the Python bindings causing OfItem predefined masks to not work in Python (#10538).
But you can create your own. For example:

python code

ctx = ix.get_item('path/to/context')
result = ix.api.OfContextArray()

# this should work but doesn't (bindings bug)
ctx.get_contexts(result, ix.api.OfItem.empty_flags_mask)

# this works: here we create by hand a mask equivalent to `ix.api.OfItem.empty_flags_mask`
mask = ix.api.CoreBitFieldHelper(ix.api.OfItem.FLAG_NONE, ix.api.OfItem.FLAG_NONE, ix.api.CoreBitFieldHelper.MODE_DISABLE, ix.api.CoreBitFieldHelper.MODE_DISABLE)
ctx.get_contexts(result, mask)


I hope this helps.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 282
Joined: Wed Jan 13, 2016 10:10 am

Re: OfContext.resolve_contexts() does not return disabled on

Unread postby mhamid3d » Tue Mar 03, 2020 7:42 pm

Thanks Anthony.

Could you explain what the inclusive and exclusive test modes are? You have "ix.api.CoreBitFieldHelper.MODE_DISABLE", there's also MODE_ONE_BIT, MODE_ALL_BITS. What exactly do these do? Can't see any documentation on them.

Thanks!
mhamid3d
 
Posts: 8
Joined: Wed Dec 04, 2019 5:20 pm

Re: OfContext.resolve_contexts() does not return disabled on

Unread postby anemoff » Wed Mar 04, 2020 7:43 pm

Indeed, more detailed documentation would be welcome. We'll improve it.

In short, the CoreBitFieldHelper stores internally:
- an inclusive bits mask
- an exclusive bits mask
- a test mode for the inclusive bits
- a test mode for the exclusive bits

Modes: specifies how to compare the stored mask (inclusive or exclusive) against input bits
- MODE_DISABLE: the test always succeeds, the mask is ignored
- MODE_EXACT_BITS: the test succeeds if mask and bits match exactly: `mask == bits`
- MODE_ALL_BITS: the test succeeds if all bits are present: `(bits & mask) == mask`
- MODE_ONE_BIT: the test succeeds if at least one bit is present in the mask: `(bits & mask) != 0`

The various constructors allow you to fully specify all members, or an inclusive-only or exclusive-only mask.

Methods:
- is_disabled(): returns true if inclusive and exclusive mode are set to MODE_DISABLE
- test_include(bits): tests the member inclusive mask against the input bits, using the inclusive test mode
- tests_exclude(bits): tests the member exclusive mask against the input bits, using the exclusive test mode
- test_bits(bits): returns `test_include(bits) && test_exclude(bits) == false`

By the way, there's a shorter code to define an empty mask:

python code

# this:
mask = ix.api.CoreBitFieldHelper()
# ... is equivalent to this:
mask = ix.api.CoreBitFieldHelper(ix.api.OfItem.FLAG_NONE, ix.api.OfItem.FLAG_NONE, ix.api.CoreBitFieldHelper.MODE_DISABLE, ix.api.CoreBitFieldHelper.MODE_DISABLE)


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


Return to Scripting