From 7a7b9b49e18249f512bd2e9398aa753832b2a83f Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Fri, 13 Jul 2018 11:16:05 +0800 Subject: [PATCH] utils: imporve element checking performance --- utils.py | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/utils.py b/utils.py index f9922ff..9095392 100644 --- a/utils.py +++ b/utils.py @@ -67,15 +67,15 @@ def deduceSelectedElement(obj,subname): shape = obj.getSubObject(subname) if not shape: return - count = len(shape.Faces) + count = shape.countElement('Face') if count==1: return 'Face1' elif not count: - count = len(shape.Edges) + count = shape.countElement('Edge') if count==1: return 'Edge1' elif not count: - count = len(shape.Vertexes) + count = shape.countElement('Vertex') if count==1: return 'Vertex1' @@ -122,21 +122,18 @@ def getElementShape(obj,tp=None,transform=False,noElementMap=True): logger.trace('wrong shape type {}'.format(obj)) return elif tp is Part.Vertex: - if len(shape.Edges): + if shape.countElement('Edge'): return - v = shape.Vertexes - if len(v)==1: - return v[0] + if shape.countElement('Vertex')==1: + return shape.Vertex1 elif tp is Part.Edge: - if len(shape.Faces): + if shape.countElement('Face'): return - e = shape.Edges - if len(e)==1: - return e[0] + if shape.countElement('Edge')==1: + return shape.Edge1 elif tp is Part.Face: - f = shape.Faces - if len(f)==1: - return f[0] + if shape.countElement('Face')==1: + return shape.Face1 else: logger.trace('wrong shape type {}'.format(obj)) @@ -172,9 +169,9 @@ def isElement(obj): if isinstance(obj,(Part.Vertex,Part.Face,Part.Edge)): return True if isinstance(shape,Part.Shape) and not shape.isNull(): - return len(shape.Vertexes)==1 or \ - len(shape.Edges)==1 or \ - len(shape.Faces)==1 + return shape.countElement('Vertex')==1 or \ + shape.countElement('Edge')==1 or \ + shape.countElement('Face')==1 def isPlanar(obj): if isCircularEdge(obj): @@ -290,7 +287,7 @@ def getElementPos(obj): elif all( hasattr(surface,a) for a in ['Axis','Center','Radius'] ): pos = surface.Center elif str(surface).startswith('