Python GetNearestEdge returns hidden edges

On 24/06/2016 at 03:54, xxxxxxxx wrote:

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


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.

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


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,

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"]  
          print 'No edge under cursor'  
      return True  
# =============== Main =============  
def PluginMain() :  
      bmp = bitmaps.BaseBitmap()  
      dir, file = os.path.split(__file__)  
      fn = os.path.join(dir, "res", "GetNearestEdgeBug.tif")  
      plugins.RegisterToolPlugin(id=PLUGIN_ID, str="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__":  

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


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,

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.

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


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,

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

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

Thanks for the clarification.