Jump to content
Sign in to follow this  
Smolak

Transfer poly selection to points - key

Recommended Posts

Hi,

 

Is there way to make key shortcut or script to transfer polygons selection to points ? Just like we do by pressing control key and point mode.

Share this post


Link to post
import c4d
from c4d import gui, utils

def main():
    settings = c4d.BaseContainer()
    settings[c4d.MDATA_CONVERTSELECTION_LEFT] = 2 # poly
    settings[c4d.MDATA_CONVERTSELECTION_RIGHT] = 0 # point
    settings[c4d.MDATA_CONVERTSELECTION_TOLERANT] = False

    res = utils.SendModelingCommand(command = c4d.MCOMMAND_CONVERTSELECTION,
                                    list = [op],
                                    mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                    bc = settings,
                                    doc = doc)
    c4d.EventAdd()
    
    if res is False:
      print "Something went wrong."
    elif res is True:
      print "Command successful."
    else:
      print "Unsupported response."

if __name__=='__main__':
    main()

Can be more or less taken from the documentation of SendModelingCommand...

Change the values for MDATA_CONVERTSELECTION_LEFT and _RIGHT if you want another direction.

Note that this script does not switch the mode from poly to point, it just calls the internal selection transfer functionality. Mode change could be added if needed.

 

Get more C4D Python from my Patreon:

https://www.patreon.com/cairyn

Share this post


Link to post

Although you can assign a keyboard shortcut to the Polygons command too. The trick is that you need to use Ctrl in this shortcut.

 

I have assigned Q~P and Q~Ctrl-P to the Polygons command, so the Ctrl qualifier is passed to the command itself, and works as if you click the icon while holding Ctrl. This is a conceptual difficulty - if you use a qualifier key as part of a keyboard shortcut, and the called command also evaluates the qualifier, then these qualifiers must match to have the desired effect.

 

Share this post


Link to post
  • Topic Author
  • Author of the topic Posted

    I tried assigning shortcut with control qualifier but it doesn't work, anyway in R21

    Share this post


    Link to post
    6 hours ago, Smolak said:

    I tried assigning shortcut with control qualifier but it doesn't work, anyway in R21

    image.thumb.png.16f6b425a232c48ba8e25735886ea077.png

    Works fine for me; that's R21 as well. Of course here I have a multi-key shortcut; if you have issues with single-key shortcuts (which I didn't test for this command) you may need to ask MAXON. Note that the ctrl qualifier has to be set for the very last keystroke to register with the command too.


    Anyway, while I was at it, I inserted the mode change into the script too:

    import c4d
    from c4d import gui, utils
    
    def main():
        settings = c4d.BaseContainer()
        settings[c4d.MDATA_CONVERTSELECTION_LEFT] = 2 # poly
        settings[c4d.MDATA_CONVERTSELECTION_RIGHT] = 0 # point
        settings[c4d.MDATA_CONVERTSELECTION_TOLERANT] = False
    
        res = utils.SendModelingCommand(command = c4d.MCOMMAND_CONVERTSELECTION,
                                        list = [op],
                                        mode = c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                        bc = settings,
                                        doc = doc)
    
        if res is False:
          print "Something went wrong."
        elif res is True:
          print "Command successful."
          doc.SetMode(c4d.Mpoints)
          c4d.EventAdd()
        else:
          print "Unsupported response."
    
    if __name__=='__main__':
        main()

    When the command finishes successfully (transfer of selection went well), then the mode is set to Points.

    Any error output goes to the Python console, you can set a message dialog as alternative.

     

    Get more C4D Python from my Patreon:

    https://www.patreon.com/cairyn

    Share this post


    Link to post
  • Topic Author
  • Author of the topic Posted

    Thank you ! Script works great but key shortcut not - it only change mode without transfering selection.

    Share this post


    Link to post

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...

    FORUMS INFO:

    Dear members, we are aware of few more bugs that are still present withing the theme.We just wanted to let you know that we are working to fix them as soon as possible.
     

    NEW MEMBERS:

    Please be aware that we are manually approving all new registrations, due to spam prevention. Please be patient in case you cannot login right away, we will approve you within 12h or less if we decide you are not potential spammer. 

     

    Thanks for understanding! :cowboypistol: