Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    How to make menus pop up in a certain distance of the mouse?

    Cinema 4D SDK
    python r20 windows
    2
    3
    1.1k
    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.
    • M
      milkliu
      last edited by milkliu

      I know how to use the method below to create a popup menu:

      c4d.gui.ShowPopupDialog(cd, bc, x, y, flags=POPUP_RIGHT|POPUP_EXECUTECOMMANDS)
      (x (int) – Popup X position in screen pixels, or c4d.MOUSEPOS to popup where the cursor is.
      y (int) – Popup Y position in screen pixels, or c4d.MOUSEPOS to popup where the cursor is.)

      I want the menu to popup at a position like this:x=c4d.mousepos+200,y=c4d.mousepos+200

      but it do not work. is there a way?

      thank you very much!

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by m_adam

        Hi @milkliu first of all welcome in the plugincafe.

        I would like to point you to Q&A New Functionality.

        While your idea is correct to add 200, c4d.mousepos is actually a constant and not a real value. So if you want to offset the position you have to first, retrieve the position with GetInputState.

        import c4d
        
        def main():
            IDM_MENU1 = c4d.FIRST_POPUP_ID
            IDM_MENU2 = c4d.FIRST_POPUP_ID+1
                
            menu = c4d.BaseContainer()
            menu.InsData(IDM_MENU1, 'Item 1')
            menu.InsData(IDM_MENU2, 'Item 2')
        
            state = c4d.BaseContainer()
            c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, state)
            x = state.GetInt32(c4d.BFM_INPUT_X) + 200
            y = state.GetInt32(c4d.BFM_INPUT_Y) + 200
        
            result = c4d.gui.ShowPopupDialog(cd=None, bc=menu, x=x, y=y)
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        If you have any question, please let me know.
        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        M 1 Reply Last reply Reply Quote 1
        • M
          milkliu @m_adam
          last edited by

          @m_adam wow!
          I did what you say,it works!!
          you are so cool!!
          thank you very much!!!
          yeah!!

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