Get SoftSelection Data in Python?

On 12/03/2017 at 01:17, xxxxxxxx wrote:

I searched a bit and found some interesting info, but it seemed not possible, but I wanted to just check.

If I enable softSelect, is it possible to get the weight value of each vertex? Not only to find out which points will be effected by the softSelect, but also their percentage or influence? I'd like to get all that data to use elsewhere, but I fear it is not possible in Python. Am I wrong?

On 13/03/2017 at 03:41, xxxxxxxx wrote:

Hi,

It's possible to get soft selection values in Python.
The hidden soft selection data has to be retrieved and converted from byte string to float values.
Note VariableTag.GetAllHighlevelData()/SetAllHighlevelData() doesn't support soft selection tag data so we have to use VariableTag.GetLowlevelDataAddressR()/GetLowlevelDataAddressW()(see c4d.VariableTag for more information).

Here's some code:

import c4d
import array
  
  
def main() :
    # Get soft selection tag
    tag = op.GetTag(c4d.Tsoftselection)
    if tag is None: return
    
    # Get soft selection data
    data = tag.GetLowlevelDataAddressR()
    if data is None: return
    
    # Convert soft selection byte data to a float array
    floatArray = array.array('f')
    floatArray.fromstring(data)
    softValues = floatArray.tolist()
    
    # Print weights
    for value in softValues:
        weight = 1.0 - value
        print weight
  
  
if __name__=='__main__':
    main()

On 14/03/2017 at 00:12, xxxxxxxx wrote:

Thanks Yannick! That works well. But why did you do weight = 1.0 - value? That seems to put unaffected weights to 1.0 instead of 0.0. Otherwise it all worked and my script works like a charm.

On 14/03/2017 at 04:04, xxxxxxxx wrote:

Glad it works fine.

Originally posted by xxxxxxxx

But why did you do weight = 1.0 - value? That seems to put unaffected weights to 1.0 instead of 0.0.

Sorry for inverting the weight values. I was confused by some internal code.