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

    Transform mouse coordinates to c4d coordinates

    Cinema 4D SDK
    r20 python
    2
    5
    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.
    • P
      pim
      last edited by pim

      I have a command plugin with a (floating) dialog.
      After the user gives a command, he must click on the screen to indicate the location where the command plugin should place the object.
      I can get the mouse coordinates, but I do not know how to convert them to coordinates to place the object.
      For example, if the user clicks on the Top View in the center, the object must be placed at (0,0,0).

      msg = c4d.BaseContainer()
      while self.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, msg):    #While the left mouse button is held down
        if msg.GetLong(c4d.BFM_INPUT_VALUE)==0: break
      
      while self.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, msg):    #Wait for next mouse click
        if msg.GetLong(c4d.BFM_INPUT_VALUE)==1: break
      
      while self.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_MOUSELEFT, msg):    #While the left mouse button is held down
        if msg.GetLong(c4d.BFM_INPUT_VALUE)==0: break
      
      
      mouseX = int(msg[c4d.BFM_INPUT_X])
      mouseY = int(msg[c4d.BFM_INPUT_Y])
      print mouseX, mouseY
      
      
      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @pim, I'm not sure a CommandData is the best place for doing this stuff, a ToolData offers the InputEvent which is far more suited for this.

        With that's said in a CommandData you actually get now way to be sure in which space you are currently retrieving the coordinate from.

        Finally, you can retrieve the active BaseDraw, then call BaseView.SW.

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

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        P 1 Reply Last reply Reply Quote 1
        • P
          pim @m_adam
          last edited by

          Hi @m_adam,

          Thanks for the quick reply.

          I agree with you with you that I can better use a toolplugin.
          But that means calling the toolplugin from the command plugin and I thought it should also be possible from a command plugin.

          Unfortunately bd.SW(p) does not return what I expect.
          When I click in the origin of the front view, I get strange results.

          b06da0a0-e041-4b2c-8ed0-5fa1cd584662-image.png

          Here is what I do:

          mouseX = int(msg[c4d.BFM_INPUT_X])
          mouseY = int(msg[c4d.BFM_INPUT_Y])
          print "Mouse coord: ", mouseX, mouseY
          
          bd = doc.GetActiveBaseDraw()         
          print "Converted coord: ", bd.SW(c4d.Vector(mouseX, mouseY, 0))
          

          It seems, I read it somewhere, that the mouse coordinates I get, are relative to the command plugin dialog.
          Could that be the issue and if so, how to solve it?

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

            Yes you are right this is relative to the current frame being drawn (understand it as the current GeDialog, SubDialog, GeUserArea) and there is no way to retrieve the frame position in the screen. As I said cinema 4D does not work this way.

            May I ask you why SubDialog of a ToolData is not enough for your needs?

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • P
              pim
              last edited by

              Thanks for the answer.

              I just started with a command plugin.
              New requirements emerged and yes, perhaps I now change over to a tool plugin.

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