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

    ViewportSelect Invalid object length

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 424 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 25/08/2015 at 10:54, xxxxxxxx wrote:

      Hi! 🙂

      They do not work  GetNearestPoint and GetNearestPolygon
      always error: Invalid object length
      I tried to change the radius, but I do not get anything ...

      def MouseInput(self, doc, data, bd, win, msg) :
      mouse_x = int(msg[c4d.BFM_INPUT_X])
      mouse_y = int(msg[c4d.BFM_INPUT_Y])

      viewport_select = c4d.utils.ViewportSelect()
      frame = bd.GetFrame()
      left = frame["cl"]
      right = frame["cr"]
      top = frame["ct"]
      bottom = frame["cb"]
      width = right - left + 1
      height = bottom - top +1

      pick_objects = viewport_select.PickObject(bd, doc, mouse_x, mouse_y, rad=10, flags=c4d.VIEWPORT_PICK_FLAGS_0)
      viewport_select.Init(width, height, bd, pick_objects, c4d.Mpolyedgepoint, True, c4d.VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL)

      nearestPoint = viewport_select.GetNearestPoint(pick_objects[0], mouse_y, mouse_y, maxrad=10, onlyselected=False, ignorelist=None, ignorecnt=0)
      print nearestPoint

      nearestPoly = viewport_select.GetNearestPolygon(pick_objects[0], mouse_y, mouse_y, maxrad=10, onlyselected=False, ignorelist=None, ignorecnt=0)
      print nearestPoly

      return True

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

        On 26/08/2015 at 01:58, xxxxxxxx wrote:

        Hi,

        The error message isn't related to the radius but the 'ignorelist' argument.
        To fix this remove the parameters 'ignorelist' and 'ignorecnt' from your calls to GetNearestPoint() and GetNearestPolygon() as you're passing the default values.

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

          On 26/08/2015 at 10:51, xxxxxxxx wrote:

          Cinema 4D Crash 😢

          def MouseInput(self, doc, data, bd, win, msg) :
          mouse_x = int(msg[c4d.BFM_INPUT_X])
          mouse_y = int(msg[c4d.BFM_INPUT_Y])

          viewport_select = c4d.utils.ViewportSelect()
          frame = bd.GetFrame()
          left = frame["cl"]
          right = frame["cr"]
          top = frame["ct"]
          bottom = frame["cb"]
          width = right - left + 1
          height = bottom - top +1

          pick_objects = viewport_select.PickObject(bd, doc, mouse_x, mouse_y, rad=10, flags=c4d.VIEWPORT_PICK_FLAGS_0)
          viewport_select.Init(width, height, bd, pick_objects, c4d.Mpolyedgepoint, True, c4d.VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL)

          nearestPoint = viewport_select.GetNearestPoint(pick_objects[0], mouse_y, mouse_y, maxrad=10, onlyselected=False)
          print nearestPoint

          nearestPoly = viewport_select.GetNearestPolygon(pick_objects[0], mouse_y, mouse_y, maxrad=10, onlyselected=False)
          print nearestPoly

          return True

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

            On 26/08/2015 at 23:55, xxxxxxxx wrote:

            It crashes when you click outside of an object because you don't check if the list returned by viewport_select.PickObject() actually contains objects.
            If len(pick_objects) is not greater or equal to 1 then the method should return.

            Does it crashes in other case(s)?

            There's also a mistake in your code as you're calling GetNearestPoint() and GetNearestPolygon() with mouse_y twice when you should pass mouse_x first for the X coordinate.
            This is not giving the valid point or polygon for the mouse position.

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

              On 27/08/2015 at 02:05, xxxxxxxx wrote:

              YES!!!! Now WORK!!!! 😄 Thanks!!!

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