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

    utils.ViewportSelect() Problem

    Cinema 4D SDK
    r19 r20 r21 python
    2
    5
    866
    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.
    • gheyretG
      gheyret
      last edited by

      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?

      www.boghma.com

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

        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

        1 Reply Last reply Reply Quote 1
        • gheyretG
          gheyret
          last edited by

          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.

          www.boghma.com

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

            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

            gheyretG 1 Reply Last reply Reply Quote 0
            • gheyretG
              gheyret @ferdinand
              last edited by

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

              Cheers
              harry

              www.boghma.com

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