本文整理汇总了Python中Part.Vertex方法的典型用法代码示例。如果您正苦于以下问题:Python Part.Vertex方法的具体用法?Python Part.Vertex怎么用?Python Part.Vertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part.Vertex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drag
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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()
示例2: update_shape
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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
示例3: get_shapes
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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)
示例4: run
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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_()
示例5: drag
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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()
示例6: execute
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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)
示例7: Activated
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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)
示例8: is_subsegment
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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
示例9: ancestors
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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
示例10: get_guide_params
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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)
示例11: Activated
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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)
示例12: getSnap
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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
示例13: drawLine
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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)
示例14: updateElement
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
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()
示例15: execute
# 需要导入模块: import Part [as 别名]
# 或者: from Part import Vertex [as 别名]
def execute(self,obj):
length = obj.Length.Value
width = obj.Width.Value
if not length:
if not width:
obj.Shape = Part.Vertex(FreeCAD.Vector())
else:
obj.Shape = Part.makeLine(FreeCAD.Vector(0,-width/2,0),
FreeCAD.Vector(0,width/2,0))
elif not width:
obj.Shape = Part.makeLine(FreeCAD.Vector(-length/2,0,0),
FreeCAD.Vector(length/2,0,0))
else:
obj.Shape = Part.makePlane(length,width,
FreeCAD.Vector(-length/2,-width/2,0))