Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Get SoftSelection Data in Python?

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 444 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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()
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post