I am running version 17 on a Mac running MacOs v. 10.12.6
I am trying to select particular elements to a part (faces and edges), with a mouse click. I seem to be getting the previous element I selected. I want the one that shows up in the selection panel when I click on it.
the first item I select after starting the macro I get this error.
after making the next selection I get the first one I selected, and only the previous one with every other selection<type 'exceptions.IndexError'>
Traceback (most recent call last):
File "/Users/fasa02/Documents/freecad/FreeCad_macros/test_macro.FCMacro", line 18, in subselect
element_ = SubElement[0].SubElementNames[0] # name of 1 element selected
IndexError: list index out of range
Code: Select all
import Part, FreeCAD, PartGui, FreeCADGui
from FreeCAD import Base, Console
#App.newDocument()
#This class logs any mouse button events. As the registered callback function fires twice for 'down' and
#'up' events we need a boolean flag to handle this.
class ViewObserver:
def subselect(self, info):
DOWN = (info["State"] == "DOWN")
if (DOWN):
# try:
SubElement = FreeCADGui.Selection.getSelectionEx() # sub element name with getSelectionEx()
element_ = SubElement[0].SubElementNames[0] # name of 1 element selected
App.Console.PrintMessage("elementSelec : "+str(element_)+"\n\n")
# actview.removeEventCallback("SoMouseButtonEvent",c)
# except:
# App.Console.PrintMessage("Oups"+"\n\n")
actview=Gui.activeDocument().activeView()
o = ViewObserver()
c = actview.addEventCallback("SoMouseButtonEvent",o.subselect)
# actview.removeEventCallback("SoMouseButtonEvent",c)
Thanks,