Code: Select all
>>> help(DraftGeomUtils.findIntersection)
Help on function findIntersection in module draftgeoutils.intersections:
findIntersection(edge1, edge2, infinite1=False, infinite2=False, ex1=False, ex2=False, dts=True, findAll=False)
Return a list containing the intersection points of 2 edges.
You can also feed 4 points instead of `edge1` and `edge2`.
If `dts` is used, `Shape.distToShape()` is used, which can be buggy.
If you use
you get a list of selection objects. If you pick two lines, you get two objects, each an edge. If you select two edges of a single object, you only get one selection object. The two edges are sub-objects of that object and are not accessible.
To access sub-object selections you need
Gui.Selection.getSelectionEx(), and to deal with a selection being either the entire object or a subobject, you can do the following:
Code: Select all
subObjs = []# create list of selected (sub) objects
for sel in Gui.Selection.getSelectionEx():
for path in sel.SubElementNames if sel.SubElementNames else ['']:#the else clause handles the case the entire object is selected
subObj = sel.Object.getSubObject(path)
subObjs.append(subObj)
print(f'{sel.Object.Name} {path} ')
# do stuff with your selections, like
if subObj.ShapeType == 'Vertex':
print(f'Vertex Loc = {sub.Point}')
#do stuff with your list, like
import DraftGeomUtils
edges = [sub for sub in subObjs if sub.ShapeType == 'Edge']
if len(edges) == 2:
xns = DraftGeomUtils.findIntersection(edges[0],edges[1], findAll = True)
if xns:
for xn in xns:
print(f'Edge intersection at ({xn.x}, {xn.y}, {xn.z})')
else:
print(f'Edges do not intersect')
else:
print(f'Select two edges')
if you replace
Gui.Selection.getSelectionEx() with
Gui.Selection.getSelectionEx('',0), data is returned in the global coordinate system instead of the local one (or more precisely, the local coordinate system of the linked object, if it is a link).