@jfc4120
I think you are missing the point of Carlo's post. Suppose you make a number of selections - say a vertex and a face from Object1 and an edge from Object2
Code: Select all
sels = Gui.Selection.getSelection()
returns a list of "Selection Objects" in this case two of them, one for Object1 and one for Object2. Assuming they are objects that have a
Shape
(ie made by Part, Part Design, Draft etc. not Meshes), then
sel[0].Shape and
sel[1].Shape contain the topological and geometrical information about the entire objects - BUT - DO NOT contain information about which vertices/edges/faces that were selected - only the objects that contained them.
If for instance, you wanted the location of
all the vertices in Object1:
Code: Select all
for vertex in sels[0].Shape.Vertexes:
print(vertex.Point)
Suppose you wanted the vertices on a face by face basis:
Code: Select all
for i, face in enumerate(sels[0].Shape.Faces):
print(f'Face{i+1}')
for v in face.Vertexes:
print(v.Point)
Objects have faces, edges and vertexes
Faces have edges and vertexes
Edges have Vertexes
Vertexes have locations (point)
This is what is refered to as
Topology
However, suppose you want information about the particular vertex/edge/face/objects(s) you selected - not just the object in which they were contained.
Now we need
Gui.Selection.getSelectionEx(), in fact to be compatible with links, you should use
Gui.Selection.getSelectionEx('', 0)
In the example above
Code: Select all
for sel in Gui.Selection.getSelectionEx('',0):
print(f'\n{sel.Object.Name}')
for path in sel.SubElementNames if sel.SubElementNames else ['']:
subobj = sel.Object.getSubObject(path)
print(f' {subobj.ShapeType}')
sel.Object contains the selected object, subobj contains the selected subobject (face/edge/vertex)
replacing
subobj = sel.Object.getSubObject(path) with
subobj = sel.Object.getSubObject(path, retType = number) returns additional optional information about the subobj like its global Placement. Here's the help:
Code: Select all
>>> help(sel.Object.getSubObject)
Help on built-in function getSubObject:
getSubObject(...) method of Part.Feature instance
getSubObject(subname, retType=0, matrix=None, transform=True, depth=0)
* subname(string|list|tuple): dot separated string or sequence of strings
referencing subobject.
* retType: return type, 0=PyObject, 1=DocObject, 2=DocAndPyObject, 3=Placement
PyObject: return a python binding object for the (sub)object referenced in
each 'subname' The actual type of 'PyObject' is implementation dependent.
For Part::Feature compatible objects, this will be of type TopoShapePy and
pre-transformed by accumulated transformation matrix along the object path.
DocObject: return the document object referenced in subname, if 'matrix' is
None. Or, return a tuple (object, matrix) for each 'subname' and 'matrix' is
the accumulated transformation matrix for the sub object.
DocAndPyObject: return a tuple (object, matrix, pyobj) for each subname
Placement: return a transformed placement of the sub-object
* matrix: the initial transformation to be applied to the sub object.
* transform: whether to transform the sub object using this object's placement
* depth: current recursive depth