SOLVED How to deselect item in a fieldList

edit :
new question, forked from this thread

Hey @zipit,

Thanks for the detailed explanation about type, will try following it from now on.

Tested FIeldLists implementation and it seems to work very well so far, the only thing I struggle is with "half selected" (bold orange) elements in fieldlists, is there a way to deselect them all like with volumebuilder, where you simply call:

    for i in xrange(0, obj.GetListEntryCount()):
        obj.SetSelected(i, 0)

Thanks again,

Sandi

hello,

you have to set back the field list like so:

Warning : I discovered that GetSelected is actually bugged and if you set the includeChildren to False, it will crash.
I've opened a bug report for that.
you can use this with children or retrieves the layer using your own function as you can do with an object hierarchy (fieldlayer are BaseList2D)

import c4d


def main():
    if op is None:
        raise TypeError("no object selected")
    

    data = op.GetDataInstance()
    # Retrieves the fieldlist
    fl = data.GetCustomDataType(c4d.FIELDS)
    if fl is None:
        raise ValueError("no field list found")
    
    
    root = fl.GetLayersRoot()
    
    sel = list()
    # Retrieves the selected layers.
    fl.GetSelected(sel, True)
    
    for layer in sel:
        layer.SetStrength(0.5)
        layer.DelBit(c4d.BIT_ACTIVE)
        
    # Sets back the field list to update its content.
    op.SetParameter(c4d.FIELDS, fl, c4d.DESCFLAGS_SET_NONE)
    c4d.EventAdd()
    


if __name__=='__main__':
   main()

The linked object is still selected, but that reproduce what the "select none" popup menu does.

Cheers,
Manuel

Hi,

you could try your luck with BaseList2D.DelBit(), but I wouldn't hold my breath, since FieldLists are presented in a very specialized GUI gadget. Something like this (I did not try this):

for layer in get_field_layers(my_fieldlist):
    layer.DelBit(c4d.BIT_ACTIVE)
    layer.Message(c4d.MSG_UPDATE)
my_fieldlist.Message(c4d.MSG_UPDATE)
c4d.EventAdd()

Cheers
zipit

hello,

I've forked the other thread as this is a new question.

I'm not sure what you are talking about "half selected" element. Are you talking about the field object in the object manager ?

A screenshot showing what you mean by that would be apreciate.

Cheers,
Manuel

@m_magalhaes I am talking about the bold orange Highlight on selected field object when it is not actually selected in the OM but trough the field list

selected_01.JPG

I would like to remove this, deselect everything inside Field list, if possible.

Thanks.

@zipit Thanks for this, I tried, doesn't seem to work with DelBit(), it does change the state, so if I read it back with GetBit() it says false, but it doesn't reflect in OM or AM.

But thanks anyway, this is more a visual thing anyway, would be cool to fix but it works without it too, just more confusing 🙂

hello,

you have to set back the field list like so:

Warning : I discovered that GetSelected is actually bugged and if you set the includeChildren to False, it will crash.
I've opened a bug report for that.
you can use this with children or retrieves the layer using your own function as you can do with an object hierarchy (fieldlayer are BaseList2D)

import c4d


def main():
    if op is None:
        raise TypeError("no object selected")
    

    data = op.GetDataInstance()
    # Retrieves the fieldlist
    fl = data.GetCustomDataType(c4d.FIELDS)
    if fl is None:
        raise ValueError("no field list found")
    
    
    root = fl.GetLayersRoot()
    
    sel = list()
    # Retrieves the selected layers.
    fl.GetSelected(sel, True)
    
    for layer in sel:
        layer.SetStrength(0.5)
        layer.DelBit(c4d.BIT_ACTIVE)
        
    # Sets back the field list to update its content.
    op.SetParameter(c4d.FIELDS, fl, c4d.DESCFLAGS_SET_NONE)
    c4d.EventAdd()
    


if __name__=='__main__':
   main()

The linked object is still selected, but that reproduce what the "select none" popup menu does.

Cheers,
Manuel

@m_magalhaes Hey!

Added the code you provided and it works nicely, thanks so much!

Cheers,

Sandi