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

    Can get Point-Index under the mouse pointer? (Py)

    Cinema 4D SDK
    python sdk
    2
    3
    603
    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.
    • ymoonY
      ymoon
      last edited by

      Can get Point-Index under the mouse pointer? (Py)
      I found a useful post.
      But I'm a beginner so I'm asking for help. Thank you.

      1. Python SDK
      2. GetNearestPoint to work

      2023-04-25_085427.png

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @ymoon
        last edited by

        Hello @ymoon,

        Thank you for reaching out to us. I am a bit confused regarding what you are asking for here. The method ViewportSelect.GetNearestPoint you have linked to is indeed the recommended way to retrieve the closest vertex to a mouse cursor. Its return value also contains the index of the closest element under the key i.

        Alternatively, you could also convert the points of a point object first to world and then to screen space using BaseView.WS. You could then manually poll the mouse using c4d.gui.GetInputEvent or use mouse coordinates provided by another method to determine which is the closest point. But since this is extra labor and the kind of computation one wants to avoid doing in Python for performance reasons, you should only do that if you must customize the closest point computation for some reason.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • ymoonY
          ymoon
          last edited by

          The mouse position is obtained as follows.
          msg[c4d.BFM_INPUT_X] --> GetEditorWindow() --> editor_x = win.Global2Local() --> mouse_x-abs(Editor_x)
          The problem of overlapping selection in GetNearestPoint() was solved by making a list of selected object.
          Thank you.

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