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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Python GetNearestEdge returns hidden edges

    Scheduled Pinned Locked Moved Bugs
    7 Posts 0 Posters 1.2k 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 24/06/2016 at 03:54, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R17 
      Platform:   Windows  ;   
      Language(s) :

      ---------
      Hi,

      I have a tooldata plugin which uses the viewport utility to check for edges under the mouse cursor.

      viewportSelect.Init(width, height, bd, objlist, c4d.Medges, True, c4d.VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL)
            edges = viewportSelect.GetNearestEdge(obj, x, y, radius)

      With hidden polygons, I still get edges belonging to these polygons, although the flag VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL is used during initialization. So maybe this does not work for hidden polygons.
      But even when I select some edges and hide these, the function GetNearestEdge still returns me these hidden edges.

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

        On 27/06/2016 at 01:34, xxxxxxxx wrote:

        Hello,

        could you please post some more complete code showing what you are doing? Providing a more complete example would help us the reproduce the issue more easily.

        Best wishes,
        Sebastian

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

          On 28/06/2016 at 13:21, xxxxxxxx wrote:

          Hi Sebastian,

          Below is the simplified implementation. I removed all non-necessary items to reproduce the problem (note that I also removed the 'out-of-range' checking).
          To reproduce the problem, create a cube, make it editable. Open the console, select the plugin (in edge mode) and hover over the edges. The number of the edge is displayed in the console. Now select some edges and hide them and use the plugin again. Hovering over the hidden edges will still print out the found edge number in the console. Which means edges were found, although the flag passed to GetNearestEdge indicates to ignore hidden edges.

          Maybe I am just doing something wrong?

            
            
          import c4d  
          import os  
            
          from c4d import gui, plugins, bitmaps, utils  
            
          PLUGIN_ID = 1031001 # dummy ID  
            
            
          class GetNearestEdgeBug(plugins.ToolData) :  
            
            def GetState(self, doc) :  
                docmode = doc.GetMode()  
                # only allow tool if in edge mode or uv polygon  
                if docmode!=c4d.Medges: return 0  
                # only allow tool if single polygon object selected  
                if len(doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0))!=1: return 0  
                return c4d.CMD_ENABLED  
              
            def GetCursorInfo(self, doc, data, bd, x, y, bc) :  
                # prepare for viewportselect  
                frame = bd.GetFrame()  
                left = frame["cl"]  
                right = frame["cr"]  
                top = frame["ct"]  
                bottom = frame["cb"]  
            
                width = right - left + 1  
                height = bottom - top +1  
            
                # get the edge under the mouse cursor  
                viewportSelect = utils.ViewportSelect()  
                obj = doc.GetActiveObject()  
                objlist = [obj]  
                viewportSelect.Init(width, height, bd, objlist, c4d.Medges, True, c4d.VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL)  
                edges = viewportSelect.GetNearestEdge(obj, x, y, 10)  
                if edges:  
                    print 'Edge number:', edges["i"]  
                else:  
                    print 'No edge under cursor'  
                  
                return True  
            
          # =============== Main =============  
                  
          def PluginMain() :  
            try:  
                bmp = bitmaps.BaseBitmap()  
                dir, file = os.path.split(__file__)  
                fn = os.path.join(dir, "res", "GetNearestEdgeBug.tif")  
                bmp.InitWith(fn)  
                plugins.RegisterToolPlugin(id=PLUGIN_ID, str="GetNearestEdgeBug",  
                                            info=0,  
                                            icon=bmp,   
                                            help="GetNearestEdgeBug",  
                                            dat=GetNearestEdgeBug())  
            except TypeError:  
                # when performing a 'reload plugin' without the plugin being registered to the system yet  
                # -> user should restart Cinema 4D  
                print "Unable to load plugin (GetNearestEdgeBug)"  
                  
          if __name__ == "__main__":  
            PluginMain()  
              
            
          
          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 29/06/2016 at 01:43, xxxxxxxx wrote:

            Hello,

            it looks like the ViewportSelect by default does ignores hidden polygons and edges of the given objects. So the flag VIEWPORTSELECTFLAGS_IGNORE_HIDDEN_SEL does not tell the ViewportSelect to ignore hidden elements but to do the opposite: to ignore the BaseSelect that stores the status if polygons or edges are hidden or not. So just write:

              
            viewportSelect.Init(width, height, bd, objlist, c4d.Medges, True, c4d.VIEWPORTSELECTFLAGS_0)  
            

            best wishes,
            Sebastian

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

              On 29/06/2016 at 12:33, xxxxxxxx wrote:

              Thanks for the reply Sebastian.
              I can confirm your suggestion does work.

              Will the current behaviour be changed in future, so that the flag is doing what it is supposed to? Or will it be left untouched?
              I'd like to know for current and future plugins, as to me, it makes not much sense to change my code to make it work now, and change it back after the behaviour is fixed.

              Thanks again.
              Daniel

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

                On 01/07/2016 at 01:16, xxxxxxxx wrote:

                Hello,

                sorry, maybe I wasn't clear enough. The flag behaves as it should, there is no bug and there will be no fix. See the description above.

                Best wishes,
                Sebastian

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

                  On 01/07/2016 at 04:31, xxxxxxxx wrote:

                  Oh, I see.
                  I never was very good in reverse logic.

                  Thanks for the clarification.

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