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
    • Recent
    • Tags
    • Users
    • Login

    Mouseposition [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    4 Posts 0 Posters 385 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 14/06/2015 at 13:56, xxxxxxxx wrote:

      Hello again,
      I am trying to get the Mouseposition in the Viewport when I run a Script. Is this possible without making a Tool-Plugin? I tried this code and it does not return anything.

      import c4d
      from c4d import gui
        
        
      def main() :
        
          bc = c4d.BaseContainer()
          
          c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE,c4d.BFM_INPUT_X,bc)    
          mouse_x = bc[c4d.BFM_INPUT_X]
          
          print mouse_x
          
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 14/06/2015 at 14:02, xxxxxxxx wrote:

        Sorry....I was sitting on this for hours now....and a minute after posting I found the solution:

        mouse_x=bc.GetInt32(c4d.BFM_INPUT_X)

        But I have another Issued with mouse coordinates...now I get the Coordinates of the mouse in the complete C4D-Window. But I need the coordinates of the mouse inside the viewport. Do you have a solution? 
        What I need is the Pixel-Vallue of the left uper corner of the Viewport in my Layout.

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

          On 15/06/2015 at 03:31, xxxxxxxx wrote:

          Hello,

          a script might not be the right place to do such user interaction. A script is meant to include some commands that are executed and then the script is finished.

          If you want user interaction with the viewport you might want to create a SceneHookData plugin (only in C++) or a ToolData plugin to create proper tools.

          Getting the correct coordinates you might need to use functions like Screen2Local(). Such functions are available in GUI related classes like GeDialog and GeUserArea but also EditorWindow. You can get the EditorWindow from the BaseDraw using GetEditorWindow() and the BaseDraw from the document using GetBaseDraw().

          Best wishes,
          Sebastian

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

            On 15/06/2015 at 04:03, xxxxxxxx wrote:

            Thanks Sebastian. That worked for me. But instead I used Global2Local() which gives the Coordinates relative to the C4D Window.

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