Solved utils.ViewportSelect() Problem

Hi! guys! Here's the problem with utils.ViewportSelect()

This is my code:

ViewportSelect = 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_obj = ViewportSelect.PickObject(bd, doc, mx, my, 0, c4d.VIEWPORT_PICK_FLAGS_0)
print pick_obj

ViewportSelect.Init(width, height, bd, pick_obj, c4d.Mpolyedgepoint, True, c4d.VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL)
for obj in pick_obj:
        print obj
        nearest_poly = ViewportSelect.GetNearestPolygon(obj, mx, my, 0, False)

Cinema 4D giving feedback: RuntimeError: Object is not initialized yet.
How can i fix it?

Hi,

you cannot use the ViewportSelect before you have initialised it. So you can only invoke PickObject() after you have invoked Init().

Cheers
zipit

MAXON SDK Specialist
developers.maxon.net

ViewportSelect.Init(width, height, bd, pick_obj, c4d.Mpolyedgepoint, True, c4d.VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL)

pick_obj = ViewportSelect.PickObject(bd, doc, mx, my, 0, c4d.VIEWPORT_PICK_FLAGS_0)

Like this? But C4D giving feedback: UnboundLocalError: local variable 'pick_obj' referenced before assignment.

Hi,

unless you have defined pick_obj somewhere else you cannot pass it to your Init() before you actually define it in the next line.

Cheers
zipit

MAXON SDK Specialist
developers.maxon.net

@zipit
Thank you man ! I see how to fix it now!~~

Cheers
harry