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()