def calculateNewVector(self): try: self.faceDir = faced.getDirectionAxis() # face direction faces = faced.findFaceSHavingTheSameEdge() # TODO: SHOULD WE DO ANY CALCULATION TO FIND BETTER FACE? if type(faces) == list: face = faces[0] elif faces is not None: face = faces else: raise ValueError("Face returned was none") yL = face.CenterOfMass uv = face.Surface.parameter(yL) nv = face.normalAt(uv[0], uv[1]) self.normalVector = nv # Setup calculation. if (face.Surface.Rotation is None): plr = plDirection = App.Placement() # section direction. When the face doesn't have a Rotation yL = face.CenterOfMass uv = face.Surface.parameter(yL) nv = face.normalAt(uv[0], uv[1]) direction = yL.sub(nv + yL) r = App.Rotation(App.Vector(0, 0, 1), direction) plDirection.Base = yL plDirection.Rotation.Q = r.Q plr = plDirection rotation = (plr.Rotation.Axis.x, plr.Rotation.Axis.y, plr.Rotation.Axis.z, math.degrees(plr.Rotation.Angle)) else: ang = face.Surface.Axis.getAngle(App.Vector(0, 0, 1)) rotation = [0, 0, 1, ang] d = self.tweakLength self.FirstLocation = yL + d * nv # the 3 arrows-disc if self.oldFaceVertexes[ 0].Point.z > self.selectedObj.Shape.BoundBox.ZMin: self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMax else: self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMin return rotation except Exception as err: App.Console.PrintError("'Calculate new Vector. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def selectFaces_Horizontal_faceloop(self): firstFace=self.selectedObj[0].SubObjects[0] #Selected face in the Loop side if( hasattr(firstFace, 'curvature')): print("Curvature face has only one face") return # cylinder has only one face firstFaceName= self.selectedObj[0].SubElementNames[0] #Selected facename shape=self.selectedObj[0].Object.Shape Gui.Selection.clearSelection() self.selectFaces_Horizontal() HorizontalFaces=Gui.Selection.getSelectionEx()[0].SubObjects #all horizontal Gui.Selection.clearSelection() self.selectEdges_Horizontal() HorizontalEdges=Gui.Selection.getSelectionEx()[0].SubObjects firstFaceEdges=[] for e in HorizontalEdges: if self.faceHasEdge(firstFace,e): print("found") firstFaceEdges.append(e) #We have the horizontal edges of first edge TotalFaces=[] newEdge=firstFaceEdges[1] currentFace=firstFace currentEdges=[] while (not(newEdge.isSame(firstFaceEdges[0]))): f=faced.findFaceSHavingTheSameEdge(newEdge,shape) if f[0].isSame(currentFace): TotalFaces.append(f[1]) currentFace=f[1] else: TotalFaces.append(f[0]) currentFace=f[0] #we have new face, find edges for e in HorizontalEdges: if self.faceHasEdge(currentFace, e): currentEdges.append(e) if not(currentEdges[0].isSame(newEdge)): newEdge=currentEdges[0] else: newEdge=currentEdges[1] currentEdges.clear() Gui.Selection.clearSelection() for i in range(0, len(self.faces)): for j in range(0,len(TotalFaces)): f1=self.faces[i] f2=TotalFaces[j] if(f2.isSame(f1)): Gui.Selection.addSelection(self.doc.Name,self.Targetobj.Name,"Face"+str(i+1)) Gui.Selection.addSelection(self.doc.Name,self.Targetobj.Name,firstFaceName)
def calculateNewVector(self): try: self.faceDir = faced.getDirectionAxis() # face direction faces = faced.findFaceSHavingTheSameEdge() # TODO: SHOULD WE DO ANY CALCULATION TO FIND BETTER FACE? if type(faces) == list: face = faces[0] elif faces is not None: face = faces else: raise ValueError("Face returned was none") yL = face.CenterOfMass uv = face.Surface.parameter(yL) nv = face.normalAt(uv[0], uv[1]) self.normalVector = nv # Setup calculation. if (face.Surface.Rotation is None): calAn = math.degrees(nv.getAngle(App.Vector(1, 1, 0))) rotation = [0, 1, 0, calAn] else: rotation = [ face.Surface.Rotation.Axis.x, face.Surface.Rotation.Axis.y, face.Surface.Rotation.Axis.z, math.degrees(face.Surface.Rotation.Angle) ] d = self.tweakLength self.FirstLocation = yL + d * nv # the 3 arrows-discs if self.oldEdgeVertexes[ 0].Point.z > self.selectedObj.Shape.BoundBox.ZMin: self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMax + self.awayFromObj else: self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMin - self.awayFromObj return rotation except Exception as err: App.Console.PrintError("'Calculate new Vector. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)