Python Part.Vertex() Examples
The following are 30
code examples of Part.Vertex().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
Part
, or try the search function
.
Example #1
Source File: pipeshellProfileFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def Activated(self): edges = [] verts = [] source = None sel = FreeCADGui.Selection.getSelectionEx() if sel == []: FreeCAD.Console.PrintError("Select at least 1 edge !\n") for selobj in sel: if selobj.HasSubObjects: for i in range(len(selobj.SubObjects)): if isinstance(selobj.SubObjects[i], Part.Edge): edges.append((selobj.Object, selobj.SubElementNames[i])) selobj.Object.ViewObject.Visibility=False elif isinstance(selobj.SubObjects[i], Part.Vertex): verts=(selobj.Object, selobj.SubElementNames[i]) #selobj.Object.ViewObject.Visibility=False else: source = selobj.Object selobj.Object.ViewObject.Visibility=False if source: self.makeProfileFeature(source, verts) elif edges: self.makeProfileFeature(edges, verts)
Example #2
Source File: ProfileSketch.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def Activated(self): shapes = [] params = [] sel = FreeCADGui.Selection.getSelectionEx() if sel == []: FreeCAD.Console.PrintError("Select 2 edges or vertexes first !\n") for selobj in sel: if selobj.HasSubObjects: for i in range(len(selobj.SubObjects)): if isinstance(selobj.SubObjects[i], Part.Edge): shapes.append((selobj.Object, selobj.SubElementNames[i])) p = selobj.PickedPoints[i] poe = selobj.SubObjects[i].distToShape(Part.Vertex(p)) par = poe[2][0][2] params.append(par) elif isinstance(selobj.SubObjects[i], Part.Vertex): shapes.append((selobj.Object, selobj.SubElementNames[i])) #p = selobj.PickedPoints[i] #poe = so.distToShape(Part.Vertex(p)) #par = poe[2][0][2] params.append(0) else: FreeCAD.Console.PrintError("Select 2 edges or vertexes first !\n") if shapes: self.makeProfileFeature(shapes, params)
Example #3
Source File: FC_interaction_example.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def get_guide_params(): sel = Gui.Selection.getSelectionEx() pts = list() for so in sel: pts.extend(so.PickedPoints) edges = list() for so in sel: for sen in so.SubElementNames: n = eval(sen.lstrip("Edge")) e = so.Object.Shape.Edges[n-1] edges.append(e) inter = list() for pt in pts: sol = None min = 1e50 for e in edges: d,points,info = e.distToShape(Part.Vertex(pt)) if d < min: min = d sol = [e,e.Curve.parameter(points[0][0])] inter.append(sol) return(inter)
Example #4
Source File: gordon_profile_FP.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def get_shapes(self, fp): if hasattr(fp,'Support'): sl = list() for ob,names in fp.Support: for name in names: if ("Vertex" in name): n = eval(name.lstrip("Vertex")) if len(ob.Shape.Vertexes) >= n: sl.append(ob.Shape.Vertexes[n-1]) elif ("Edge" in name): n = eval(name.lstrip("Edge")) if len(ob.Shape.Edges) >= n: sl.append(ob.Shape.Edges[n-1]) elif ("Face" in name): n = eval(name.lstrip("Face")) if len(ob.Shape.Faces) >= n: sl.append(ob.Shape.Faces[n-1]) return(sl)
Example #5
Source File: _utils.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def ancestors(shape, sub): '''list_of_shapes = ancestors(shape, sub) Returns the closest ancestors of "sub" in "shape"''' def cleanup(shape): s = str(shape) ss = s.split()[0] return ss.split('<')[1] shd = (Part.Vertex, Part.Edge, Part.Wire, Part.Face, Part.Shell, Part.Solid, Part.CompSolid, Part.Compound) for i in range(len(shd)-1): if isinstance(sub, shd[i]): for j in range(i+1,len(shd)): manc = shape.ancestorsOfType(sub, shd[j]) if manc: print("{} belongs to {} {}.".format(cleanup(sub), len(manc), cleanup(manc[0]))) return manc
Example #6
Source File: profile_editor.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def drag(self, mouse_coords, fact=1.): if self.enabled: pts = self.points for i, p in enumerate(pts): p[0] = mouse_coords[0] * fact + self._tmp_points[i][0] p[1] = mouse_coords[1] * fact + self._tmp_points[i][1] p[2] = mouse_coords[2] * fact + self._tmp_points[i][2] if self._shape: v = Part.Vertex(p[0],p[1],p[2]) proj = v.distToShape(self._shape)[1][0][1] # FreeCAD.Console.PrintMessage("%s -> %s\n"%(p.getValue(),proj)) p[0] = proj.x p[1] = proj.y p[2] = proj.z self.points = pts for foo in self.on_drag: foo()
Example #7
Source File: manipulators.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def drag(self, mouse_coords, fact=1.): if self.enabled: pts = self.points for i, p in enumerate(pts): p[0] = mouse_coords[0] * fact + self._tmp_points[i][0] p[1] = mouse_coords[1] * fact + self._tmp_points[i][1] p[2] = mouse_coords[2] * fact + self._tmp_points[i][2] if self._shape: v = Part.Vertex(p[0],p[1],p[2]) proj = v.distToShape(self._shape)[1][0][1] # FreeCAD.Console.PrintMessage("%s -> %s\n"%(p.getValue(),proj)) p[0] = proj.x p[1] = proj.y p[2] = proj.z self.points = pts for foo in self.on_drag: foo()
Example #8
Source File: IsoCurve2.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def run(): sel = Gui.Selection.getSelectionEx() try: if len(sel) != 1: raise Exception("Select one face only.") try: App.ActiveDocument.openTransaction("Macro IsoCurve") selfobj = makeIsoCurveFeature() so = sel[0].SubObjects[0] p = sel[0].PickedPoints[0] poe = so.distToShape(Part.Vertex(p)) par = poe[2][0][2] selfobj.Face = [sel[0].Object,sel[0].SubElementNames] selfobj.Parameter = par[0] selfobj.Proxy.execute(selfobj) finally: App.ActiveDocument.commitTransaction() except Exception as err: from PySide import QtGui mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) mb.setText("{0}".format(err)) mb.setWindowTitle("Macro IsoCurve") mb.exec_()
Example #9
Source File: ParametricBlendCurve.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def update_shape(self): e1 = _utils.getShape(self.Object, "Edge1", "Edge") e2 = _utils.getShape(self.Object, "Edge2", "Edge") if e1 and e2: bc = nurbs_tools.blendCurve(e1,e2) v = Part.Vertex(self.m1.point) proj = v.distToShape(self.m1.snap_shape)[1][0][1] bc.param1 = e1.Curve.parameter(proj) #bc.param1 = (pa1 - self.m1.snap_shape.FirstParameter) / (self.m1.snap_shape.LastParameter - self.m1.snap_shape.FirstParameter) bc.scale1 = self.t1.parameter bc.cont1 = self.Object.Proxy.getContinuity(self.c1.text[0]) v = Part.Vertex(self.m2.point) proj = v.distToShape(self.m2.snap_shape)[1][0][1] bc.param2 = e2.Curve.parameter(proj) #bc.param2 = (pa2 - self.m2.snap_shape.FirstParameter) / (self.m2.snap_shape.LastParameter - self.m2.snap_shape.FirstParameter) bc.scale2 = self.t2.parameter bc.cont2 = self.Object.Proxy.getContinuity(self.c2.text[0]) bc.maxDegree = self.Object.DegreeMax bc.compute() self.Object.Shape = bc.Curve.toShape() return bc
Example #10
Source File: splitCurves_2.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def drag(self, mouse_coords, fact=1.): if self.enabled: pts = self.points for i, p in enumerate(pts): p[0] = mouse_coords[0] * fact + self._tmp_points[i][0] p[1] = mouse_coords[1] * fact + self._tmp_points[i][1] p[2] = mouse_coords[2] * fact + self._tmp_points[i][2] if self._shape: v = Part.Vertex(p[0],p[1],p[2]) proj = v.distToShape(self._shape)[1][0][1] # FreeCAD.Console.PrintMessage("%s -> %s\n"%(p.getValue(),proj)) p[0] = proj.x p[1] = proj.y p[2] = proj.z self.points = pts for foo in self.on_drag: foo()
Example #11
Source File: blendsurf_editor.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def drag(self, mouse_coords, fact=1.): if self.enabled: pts = self.points for i, p in enumerate(pts): p[0] = mouse_coords[0] * fact + self._tmp_points[i][0] p[1] = mouse_coords[1] * fact + self._tmp_points[i][1] p[2] = mouse_coords[2] * fact + self._tmp_points[i][2] if self.shape: v = Part.Vertex(p[0],p[1],p[2]) proj = v.distToShape(self.shape)[1][0][1] # FreeCAD.Console.PrintMessage("%s -> %s\n"%(p.getValue(),proj)) p[0] = proj.x p[1] = proj.y p[2] = proj.z self.points = pts for foo in self.on_drag: foo()
Example #12
Source File: Asm4_Measure.py From FreeCAD_Assembly4 with GNU Lesser General Public License v2.1 | 6 votes |
def getSnap( self, shape ): point = None if shape.isValid(): if 'Vertex' in str(shape): point = shape.Vertexes[0].Point # for a circle, snap to the center elif 'Edge' in str(shape) and hasattr(shape,'Curve') \ and hasattr(shape.Curve,'Radius'): point = shape.Curve.Center # as fall-back, snap to center of bounding box elif hasattr(shape,'BoundBox'): point = shape.BoundBox.Center else: self.printResult('Invalid shape\n'+str(shape)) return point # measure the coordinates of a single point
Example #13
Source File: nurbs_tools.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def is_subsegment(edge_1, edge_2, num=20, tol=1e-7): # check if edge_1 is a trim of edge_2. """check if edge_1 is a trim of edge_2. Usage : is_subsegment(edge_1, edge_2, num=20, tol=1e-7) ---> bool 'num' points are sampled on edge_1 return False if a point is farther than tol. """ try: e1 = edge_1.toShape() e2 = edge_2.toShape() except AttributeError: e1 = edge_1 e2 = edge_2 dist = 0 for p in e1.discretize(num): d, pts, info = Part.Vertex(p).distToShape(e2) if d > tol: return False return True
Example #14
Source File: SheetMetalRelief.py From FreeCAD_SheetMetal with GNU General Public License v3.0 | 6 votes |
def updateElement(self): if self.obj: sel = FreeCADGui.Selection.getSelectionEx()[0] if sel.HasSubObjects: obj = sel.Object for elt in sel.SubElementNames: if "Vertex" in elt: vertex = self.obj.baseObject found = False if (vertex[0] == obj.Name): if isinstance(vertex[1],tuple): for subf in vertex[1]: if subf == elt: found = True else: if (vertex[1][0] == elt): found = True if not found: self.obj.baseObject = (sel.Object, sel.SubElementNames) self.update()
Example #15
Source File: hooks.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def execute(self, obj): debug("* Hook : execute *\n") e = self.getEdge(obj) if e == None: return #center = FreeCAD.Vector(0,0,0) if obj.Method == "Fixed": p = FreeCAD.Vector(obj.X, obj.Y, obj.Z) v = Part.Vertex(p) obj.Center = v.distToShape(e)[1][0][1] elif obj.Method == "Parameter": obj.Center = e.valueAt(obj.Parameter) elif obj.Method == "Distance-From-Start": par = e.getParameterByLength(obj.StartDistance) obj.Center = e.valueAt(par) elif obj.Method == "Distance-From-End": par = e.getParameterByLength(e.Length - obj.EndDistance) obj.Center = e.valueAt(par) #radius = 1.0 * e.Length / 100.0 #sphere = Part.Sphere() #sphere.Radius = radius #sphere.Center = obj.Center obj.Shape = Part.Vertex(obj.Center)
Example #16
Source File: Asm4_Measure.py From FreeCAD_Assembly4 with GNU Lesser General Public License v2.1 | 6 votes |
def drawLine( self, pt1, pt2, name='aLine', width=3 ): global taskUI if pt1!=pt2: line = Part.makeLine( pt1, pt2 ) wire = App.ActiveDocument.addObject('Part::FeaturePython', name) wire.ViewObject.Proxy = setCustomIcon(wire, taskUI.lineIcon ) wire.Shape = Part.Wire(line) wire.ViewObject.LineWidth = width wire.ViewObject.LineColor = ( 1.0, 1.0, 1.0 ) wire.ViewObject.PointSize = 10 wire.ViewObject.PointColor= ( 0.0, 0.0, 1.0 ) self.addToDims(wire) else: point = App.ActiveDocument.addObject('Part::FeaturePython', 'aPoint') point.ViewObject.Proxy = setCustomIcon(point, taskUI.pointIcon ) point.Shape = Part.Vertex(Part.Point( pt1 )) point.ViewObject.PointSize = 10 point.ViewObject.PointColor= ( 0.0, 0.0, 1.0 ) self.addToDims(point)
Example #17
Source File: _utils.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def getSubShape(shape, shape_type, n): if shape_type == "Vertex" and len(shape.Vertexes) >= n: return shape.Vertexes[n-1] elif shape_type == "Edge" and len(shape.Edges) >= n: return shape.Edges[n-1] elif shape_type == "Face" and len(shape.Faces) >= n: return shape.Faces[n-1] else: return None
Example #18
Source File: bezierCurve-2.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def finish(self): self.curve.setPoles(self.stack[0:-1]) self.obj.Shape = self.curve.toShape() #self.obj.ViewObject.Selectable = True #FreeCADGui.Selection.removeObserver(self) self.viewer.setPickRadius(self.oldRadius) self.sg.removeChild(self.polygon) self.sg.removeChild(self.markers) self.sg.removeChild(self.coord) self.view.removeEventCallbackPivy( coin.SoLocation2Event.getClassTypeId(), self.cursorCB) self.view.removeEventCallbackPivy( coin.SoKeyboardEvent.getClassTypeId(), self.keyboardCB) self.view.removeEventCallbackPivy( coin.SoMouseButtonEvent.getClassTypeId(), self.clicCB) #def getSnapPoint(self): #v = Part.Vertex(self.point) #dist, pts, sols = v.distToShape(self.snapShape) #self.point = pts[0][1] #def getSnapShape(self,**info): #if not info == None: #try: #doc, obj, sub = info['Document'], info['Object'], info['Component'] #except KeyError, TypeError: #self.snapShape = None #return(False) #snapobj = FreeCAD.getDocument(doc).getObject(obj) #if 'Edge' in sub: #n = eval(sub.lstrip('Edge')) #self.snapShape = snapobj.Shape.Edges[n-1] #return(True) #elif 'Face' in sub: #n = eval(sub.lstrip('Face')) #self.snapShape = snapobj.Shape.Faces[n-1] #return(True)
Example #19
Source File: bezierCurve-selection.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def setPreselection(self,doc,obj,sub): snapObj = FreeCAD.getDocument(doc).getObject(obj) if 'Vertex' in sub: n = eval(sub.lstrip('Vertex')) self.snapShape = snapObj.Shape.Vertexes[n-1] elif 'Edge' in sub: n = eval(sub.lstrip('Edge')) self.snapShape = snapObj.Shape.Edges[n-1] elif 'Face' in sub: n = eval(sub.lstrip('Face')) self.snapShape = snapObj.Shape.Faces[n-1]
Example #20
Source File: nurbs_tools.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def nearest_parameter(bs,pt): try: par = bs.parameter(pt) except Part.OCCError: # failed. We try with distToShape error("parameter error at %f"%par) v = Part.Vertex(pt) e = bs.toShape() d,p,i = v.distToShape(e) pt1 = p[0][1] par = bs.parameter(pt1) return par
Example #21
Source File: IsoCurve.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def run(): f = Gui.Selection.Filter("SELECT Part::Feature SUBELEMENT Face COUNT 1..1000") try: if not f.match(): raise Exception("Select at least one face.") try: App.ActiveDocument.openTransaction("Macro IsoCurve") r = f.result() for e in r: for s in e: for f in s.SubElementNames: #App.ActiveDocument.openTransaction("Macro IsoCurve") selfobj = makeIsoCurveFeature() #so = sel[0].SubObjects[0] #p = sel[0].PickedPoints[0] #poe = so.distToShape(Part.Vertex(p)) #par = poe[2][0][2] #selfobj.Face = [sel[0].Object,sel[0].SubElementNames] selfobj.Face = [s.Object,f] #selfobj.Parameter = par[0] selfobj.Proxy.execute(selfobj) finally: App.ActiveDocument.commitTransaction() except Exception as err: from PySide import QtGui mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) mb.setText("{0}".format(err)) mb.setWindowTitle("Macro IsoCurve") mb.exec_()
Example #22
Source File: lineFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def IsActive(self): if FreeCAD.ActiveDocument: f = FreeCADGui.Selection.Filter("SELECT Part::Feature SUBELEMENT Vertex COUNT 2") return f.match() else: return(False)
Example #23
Source File: TestCadObjects.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def testBasicBoundingBox(self): v = Vertex(Part.Vertex(1, 1, 1)) v2 = Vertex(Part.Vertex(2, 2, 2)) self.assertEqual(BoundBox, type(v.BoundingBox())) self.assertEqual(BoundBox, type(v2.BoundingBox())) bb1 = v.BoundingBox().add(v2.BoundingBox()) self.assertEqual(bb1.xlen, 1.0)
Example #24
Source File: frameCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def extendTheBeam(beam,target): '''arg1=beam, arg2=target: extend the beam to a plane, normal to its axis, defined by target. If target is a Vertex or a Vector, the plane is the one that includes the point defined by target. If target is a Face, the plane is the one that includes the intersection between the axis of beam and the plane of the face. Else, the plane is the one normal to the axis of beam that includes the CenterOfMass of target''' distBase=distTop=0 vBase=beam.Placement.Base vBeam=beamAx(beam) h=beam.Height vTop=vBase+vBeam.multiply(h) if type(target)==FreeCAD.Vector: distBase=vBase.distanceToPlane(target,vBeam) distTop=vTop.distanceToPlane(target,vBeam) elif target.ShapeType=="Vertex": distBase=vBase.distanceToPlane(target.Point,vBeam) distTop=vTop.distanceToPlane(target.Point,vBeam) elif target.ShapeType=="Face": if not isOrtho(target,vBeam): from Part import Point Pint=Point(intersectionPlane(beam.Placement.Base,beamAx(beam),target)).toShape() distBase=vBase.distanceToPlane(Pint.Point,vBeam) distTop=vTop.distanceToPlane(Pint.Point,vBeam) elif hasattr(target,"CenterOfMass"): distBase=vBase.distanceToPlane(target.CenterOfMass,vBeam) distTop=vTop.distanceToPlane(target.CenterOfMass,vBeam) if distBase*distTop>0: if abs(distBase)>abs(distTop): beam.Height+=FreeCAD.Units.Quantity(str(abs(distTop))+"mm") else: beam.Height+=FreeCAD.Units.Quantity(str(abs(distBase))+"mm") vMove=vBeam.normalize().multiply(-distBase) beam.Placement.move(vMove) else: if abs(distBase)>abs(distTop): beam.Height-=FreeCAD.Units.Quantity(str(abs(distTop))+"mm") else: beam.Height-=FreeCAD.Units.Quantity(str(abs(distBase))+"mm") vMove=vBeam.normalize().multiply(-distBase) beam.Placement.move(vMove) #FreeCAD.activeDocument().recompute()
Example #25
Source File: Asm4_Measure.py From FreeCAD_Assembly4 with GNU Lesser General Public License v2.1 | 5 votes |
def drawPoint( self, pt ): global taskUI point = App.ActiveDocument.addObject('Part::FeaturePython', 'PtS') point.ViewObject.Proxy = setCustomIcon(point, taskUI.pointIcon ) point.Shape = Part.Vertex(Part.Point( pt )) point.ViewObject.PointSize = 10 point.ViewObject.PointColor= ( 1.000, 0.667, 0.000 ) self.addToDims(point) return point
Example #26
Source File: TestCadObjects.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def testVertex(self): """ Tests basic vertex functions """ # Tests casting a vertex vc = Vertex.cast(Part.Vertex(1, 1, 1)) self.assertEqual(1, vc.X) self.assertEqual(Vector, type(vc.Center())) # Tests vertex instantiation v = Vertex(Part.Vertex(1, 1, 1)) self.assertEqual(1, v.X) self.assertEqual(Vector, type(v.Center()))
Example #27
Source File: SheetMetalCmd.py From FreeCAD_SheetMetal with GNU General Public License v3.0 | 5 votes |
def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len(Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False selobj = Gui.Selection.getSelection()[0] if selobj.isDerivedFrom("Sketcher::SketchObject"): return False for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selFace) == Part.Vertex : return False return True
Example #28
Source File: SheetMetalCmd.py From FreeCAD_SheetMetal with GNU General Public License v3.0 | 5 votes |
def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len(Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False selobj = Gui.Selection.getSelection()[0] if selobj.isDerivedFrom("Sketcher::SketchObject"): return False for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selFace) == Part.Vertex : return False return True
Example #29
Source File: frameCmd.py From flamingo with GNU Lesser General Public License v3.0 | 5 votes |
def rotateTheBeamAround(b,e,ang=90): # for rotation around an axis ''' rotateTheBeamAround(b,e,ang=90): rotates any Body around an edge b: any object with a Placement property e: the edge being axis of rotation ang: degrees of rotation ''' rot=FreeCAD.Rotation(e.tangentAt(0),ang) from Part import Vertex P0=Vertex(b.Placement.Base) O=P0.distToShape(e)[1][0][1] P1=O+rot.multVec(P0.Point-O) b.Placement.Rotation=rot.multiply(b.Placement.Rotation) b.Placement.Base=P1 #rot.multVec(b.Placement.Base)
Example #30
Source File: SheetMetalRelief.py From FreeCAD_SheetMetal with GNU General Public License v3.0 | 5 votes |
def IsActive(self): if len(Gui.Selection.getSelection()) < 1 or len(Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: return False selobj = Gui.Selection.getSelection()[0] for selVertex in Gui.Selection.getSelectionEx()[0].SubObjects: if type(selVertex) != Part.Vertex : return False return True