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

    Soft Selection to BaseSelect?

    SDK Help
    0
    15
    1.2k
    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
      Helper
      last edited by

      On 12/02/2013 at 16:40, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R10-R14 
      Platform:   Windows  ;   Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      My latest plugin allows restriction of operation on points/edges/polygons based on the active selection.  If the user is using Soft Selection, is there any way to get all of the affected points/edges/polygons?

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

        On 12/02/2013 at 17:15, xxxxxxxx wrote:

        soft selections are a hidden variabletag on the object. the ID is Tsoftselection. the tag only
        exists while the object is selected and a tool which uses softselections is active.

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

          On 12/02/2013 at 17:27, xxxxxxxx wrote:

          Aha!  I actually looked in the OM to find such a tag on the object but couldn't see it - well, because it's hidden.  Because it's a variable tag, I take it that any of the elements that aren't 0.0 could be considered as 'hard' selected (for my purposes, anyway).

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

            On 12/02/2013 at 18:22, xxxxxxxx wrote:

            Well, my code is finding the Tsoftselection tag but it is getting dataCount = 0 every time.  Any ideas anyone?

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

              On 12/02/2013 at 19:18, xxxxxxxx wrote:

              hm,

              in python i can read the datacount, but i cannot read the highleveldata, only the bytesequence.

                  taglist = doc.GetActiveObject().GetTags()
                  
                  for tag in taglist:
                      if tag.GetType() == c4d.Tsoftselection:
                          print tag.GetDataCount()
                          data = tag.GetLowlevelDataAddressR()
              	    print data
              
              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 12/02/2013 at 19:27, xxxxxxxx wrote:

                In C++, I'm doing this:

                Whatever ActiveSelectionCheckMethod()  
                {  
                  ...  
                  BaseSelect*    bs =        NULL;  
                  BaseTag*    vtag =        obj->GetTag(Tsoftselection);  
                  if (vtag)                bs =    SoftToHardSelection(static_cast<VariableTag*>(vtag));  
                  else                    bs =    obj->GetEdgeS();  
                  if (!bs)  
                  {  
                      if (notify)            return MessageSystem::Throw(GeLoadString(KDZERR_GENERAL), "No Edges Selected!");  
                      return FALSE;  
                  }  
                  ...  
                }  
                // SymMorphyTag.SoftToHardSelection  
                // -    Convert a Soft Selection (Tsoftselection) into a hard selection (BaseSelect)  
                //*---------------------------------------------------------------------------*  
                BaseSelect*    SymMorphyTag::SoftToHardSelection(VariableTag* vtag)  
                //*---------------------------------------------------------------------------*  
                {  
                  LONG    dataCount =            vtag->GetDataCount();  
                  if (!dataCount)                return (BaseSelect* )ErrPrtV("SymMorphyTag.SoftToHardSelection.dataCount");  
                  const    SReal*    data =        static_cast<const SReal*>(vtag->GetLowlevelDataAddressR());  
                  if (!data)                    return (BaseSelect* )ErrPrtV("SymMorphyTag.SoftToHardSelection.data");  
                  BaseSelect*        bs =        BaseSelect::Alloc();  
                  if (!bs)                    return (BaseSelect* )ErrPrtV("SymMorphyTag.SoftToHardSelection.bs");  
                  
                  for (LONG i = 0L; i != dataCount; ++i)  
                  {  
                      if (data[i])    bs->Select(i);  
                  }  
                  
                  return bs;  
                }
                

                Not even getting to the data.  The first check is for the data count and it is balking.

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

                  On 12/02/2013 at 19:43, xxxxxxxx wrote:

                  well,
                  are you sure, that you meet the conditions for correct soft selection data ? as i said before,
                  you have to select the the object, activate a soft selection tool and have a selection of
                  course.

                  python is just a wrapper for cpp, so it has to work.

                  and i managed to unpack the data into something meaningful, the bytesequence seems to be
                  single.

                  import c4d, struct
                  from c4d import gui
                    
                  def main() :
                      taglist = doc.GetActiveObject().GetTags()
                      
                      for tag in taglist:
                          if tag.GetType() == c4d.Tsoftselection:
                              data = tag.GetLowlevelDataAddressR()
                              
                              count = 0
                              for i in xrange(0, len(data)-4,4) :
                                  fdata = struct.unpack('f', data[i:i+4])
                                  count += 1
                                  print fdata
                              
                              print count
                              print data.GetDataCount()
                    
                  if __name__=='__main__':
                      main()
                  

                  edit: after posting this, i realized, that you already knew this (unpacking/casting the byte
                  sequence). my cpp is really bad, so please excuse me 🙂 but i'll leave the code fragment
                  if you do not mind, so that people who might search for a python example could use it.

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

                    On 12/02/2013 at 19:48, xxxxxxxx wrote:

                    As far as I know, the polygon object is selected, the tool is the tool with soft selection and there should be a selection (or the changes are in my head).  I do need to switch to my plugin tag which might upset something but that is about it.

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

                      On 12/02/2013 at 20:08, xxxxxxxx wrote:

                      it could be a 'benefit' of the python wrapper that it provides GetDataCount(). maybe the
                      element count is in cpp not exposed when you only have access to the lowleveldata.
                      there are some rare examples where the python sdk provides more features than the cpp.

                      i am not so sure about cpp, but shouldn't be the datacount in cpp also length(bytestring)/4
                      like i did it in my script ?

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

                        On 13/02/2013 at 05:58, xxxxxxxx wrote:

                        Unfortunately, pointer array sizes can't be known in C++.  You have to store the size separately from the array.  The return from GetLowLevelData() is a void* - so you can't even get the type - you have to know what it should be.  So, without dataCount, it can't be done.  Hopefully Yannick will be able to clarify.

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

                          On 13/02/2013 at 08:17, xxxxxxxx wrote:

                          Hi Robert,

                          From the C++ TTagType section:

                          Tsoftselection
                          Soft selection SReal.

                          You probably can cast the void* value to SReal* and assume the pointed data has as many
                          elements as points are in the object. This is just a guess, no garuantee. 🙂

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

                            On 13/02/2013 at 09:03, xxxxxxxx wrote:

                            If you looked at the code I posted, I'm way beyond that.  What I don't have is a valid datacount.  It is always 0 (though I'm still in the same edit mode and using the same tool).

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

                              On 13/02/2013 at 09:16, xxxxxxxx wrote:

                              i think what nikklas meant is : you can assume datacount == host_object.pointcount, due to 
                              the nature of variable tags (to bypass the missing datacount in cpp).

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

                                On 13/02/2013 at 09:28, xxxxxxxx wrote:

                                Oh, I see.  Maybe.  Let me see if I get a valid data* and the assumption may work.  I don't know.  There is only one other thread on this entire forum about soft selection and it basically shows the same idea as my code.

                                User error.  Having not used soft selection before, I see that once I select my plugin tag to do the operation, the soft selection is not shown anymore.  The soft selection tag is still there but it has no data.  I have to select the polygon object in the edtior to show the soft selection, maintain the tag display in the AM, and then it actually works.  Something to mention in my documentation.  This behavior is not happening in R10 but in R13.  R10 maintains the soft selection display while I select my tag and do the operation.

                                Thanks!

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

                                  On 13/02/2013 at 12:43, xxxxxxxx wrote:

                                  Originally posted by xxxxxxxx

                                  i think what nikklas meant is : you can assume datacount == host_object.pointcount, due to 
                                  the nature of variable tags (to bypass the missing datacount in cpp).

                                  Yes, I wanted to say this. But Robert is also right, I didn't read the code he posted, sorry for that. 🙂

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