Thanks to all, I'v something that works. At least one problem left: the spline. In my solution, the spline reveals "x=subelem[ix]
IndexError: tuple index out of range". I cannot find a mechanism to distinguish the spline from a edge. I now, that a spline can be distinguished by the nodes in FreeCAD. But how can I find/get these nodes. Someone can help me a little further, thanks a lot. Below my code (a part of). John.
Code: Select all
from PySide import QtGui
# designation of element: still to implement.
dsgn=QtGui.QInputDialog.getText(None, "Designation", "Designation of elements by yourself y/n?")[0]
if "y" or "Y" in dsng:
dsng="yes"
print("--->your choice: designation by your own")
else:
dsng="no"
print("--->your choice: designation automatically")
# discretization input by user
npoints=QtGui.QInputDialog.getText(None, "Segmented", "number of vertices (default 2):")[0]
try:
npoints=int(max(2,float(npoints)))
except:
npoints=2
print("--->your choice for pieces per element: ", npoints)
npoints=int(max(2,npoints))
ix=0
elem=0
print()
def parameters(elem):
if elem=="ARC":
print("**this is an**",elem)
else:
print("**this is a**",elem)
#add: export vertices, length, radius, center etc to a .csv file
# if line then..
# if circle then...
# etc.
def handleMouseEvent(eventInfo):
global ix
global elem
if (eventInfo["Button"] == "BUTTON1" and eventInfo["State"])=="UP" :
sel=Gui.Selection.getSelectionEx()
edge=sel[0]
subelem=edge.SubElementNames
x=subelem[ix]
print("selected item:",ix,"-",x)
if ('Vertex' in x):
node=edge.PickedPoints
for x in node:
print("selected item (x,y,z)",ix,":", x[0],x[1],x[2])
elem="Point"
#print("**this is a NODE**")
elif ('Edge' in x):
points=edge.SubObjects[ix].discretize(npoints)
for p in points:
print("selected item (x,y,z)",ix,":", p.x,p.y,p.z)
try:
subobj=edge.SubObjects[ix]
if hasattr(subobj.Curve, "Center"):
if subobj.Closed:
elem="Circle"
#print("**this is a CIRCLE**")
# remark: for a circle: first and end last vertex are exactly the same!
else:
elem="Arc"
#print("**this is an ARC**")
else:
elem="Line"
#print("**this is a LINE**")
except: pass
else:
print( "UNKNOWN ITEM SELECTED" )
print("subelem[i]: ",ix,":",x)
parameters(elem) #module for exporting element variables etc.
ix+=1
print()
elif (eventInfo["Button"] == "BUTTON2" and eventInfo["State"])=="DOWN":
FreeCADGui.ActiveDocument.ActiveView.removeEventCallback("SoMouseButtonEvent", handleMouseEvent)
print()
print("Right mouse button pressed: selection stopped")
print(">>>>>FINISHED<<<<<")
App.Gui.ActiveDocument.ActiveView.addEventCallback("SoMouseButtonEvent", handleMouseEvent)