ViewportSelect Invalid object length



  • 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



  • 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.



  • 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



  • 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.



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

    YES!!!! Now WORK!!!! :D Thanks!!!


Log in to reply