Python Part.makePolygon() Examples

The following are 26 code examples of Part.makePolygon(). 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: pipeshellFP.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def getRails(self, shapes):
        nbvert = len(shapes[0].Vertexes)
        edges = []
        for i in range(nbvert):
            pts = []
            for s in shapes:
                pts.append(s.Vertexes[i].Point)
            try:
                bs = Part.BSplineCurve()
                bs.interpolate(pts)
                edges.append(bs.toShape())
                debug("Rail %d : BSpline curve"%i)
            except Part.OCCError:
                po = Part.makePolygon(pts)
                edges.append(po)
                debug("Rail %d : Polygon"%i)
        return(edges) 
Example #2
Source File: makebox.py    From LCInterlocking with GNU Lesser General Public License v2.1 6 votes vote down vote up
def make_side_panels(width, height, thickness, spacing):
    half_width = width / 2.0
    down_height = -height / 2.0
    up_height = height / 2.0
    x = spacing / 2.0
    p1 = FreeCAD.Vector(x, -half_width, down_height)
    p2 = FreeCAD.Vector(x, -half_width, up_height)
    p3 = FreeCAD.Vector(x, half_width, up_height)
    p4 = FreeCAD.Vector(x, half_width, down_height)

    wire = Part.makePolygon([p1,p2,p3,p4,p1])
    face = Part.Face(wire)
    left_part = face.extrude(FreeCAD.Vector(thickness, 0, 0))
    right_part = left_part.copy()
    right_part.translate(FreeCAD.Vector(-spacing - thickness, 0, 0))

    return left_part, right_part 
Example #3
Source File: makebox.py    From LCInterlocking with GNU Lesser General Public License v2.1 6 votes vote down vote up
def make_twice_half_front_panel(length, height, thickness, spacing):
    quarter_length = length / 4.0
    down_height = -height / 2.0
    up_height = height / 2.0
    y = spacing / 2.0
    p1 = FreeCAD.Vector(-quarter_length, y, down_height)
    p2 = FreeCAD.Vector(-quarter_length, y, up_height)
    p3 = FreeCAD.Vector(quarter_length, y, up_height)
    p4 = FreeCAD.Vector(quarter_length, y, down_height)

    wire = Part.makePolygon([p1,p2,p3,p4,p1])
    face = Part.Face(wire)
    front_part_1 = face.extrude(FreeCAD.Vector(0, thickness, 0))
    front_part_2 = front_part_1.copy()
    front_part_1.translate(FreeCAD.Vector(-quarter_length, 0, 0))
    front_part_2.translate(FreeCAD.Vector(quarter_length, 0, 0))

    return front_part_1, front_part_2

# YZ plan 
Example #4
Source File: makebox.py    From LCInterlocking with GNU Lesser General Public License v2.1 6 votes vote down vote up
def make_front_panels(length, height, thickness, spacing):
    half_length = length / 2.0
    down_height = -height / 2.0
    up_height = height / 2.0
    y = spacing / 2.0
    p1 = FreeCAD.Vector(-half_length, y, down_height)
    p2 = FreeCAD.Vector(-half_length, y, up_height)
    p3 = FreeCAD.Vector(half_length, y, up_height)
    p4 = FreeCAD.Vector(half_length, y, down_height)

    wire=Part.makePolygon([p1,p2,p3,p4,p1])
    face = Part.Face(wire)
    front_part = face.extrude(FreeCAD.Vector(0, thickness, 0))
    behind_part = front_part.copy()
    behind_part.translate(FreeCAD.Vector(0, -spacing - thickness, 0))

    return front_part, behind_part 
Example #5
Source File: SheetMetalCmd.py    From FreeCAD_SheetMetal with GNU General Public License v3.0 6 votes vote down vote up
def smMakeFace(edge, dir, extLen, gap1 = 0.0,
               gap2 = 0.0, angle1 = 0.0, angle2 = 0.0, op = ''):
    len1 = extLen * math.tan(math.radians(angle1))
    len2 = extLen * math.tan(math.radians(angle2))

    p1 = edge.valueAt(edge.LastParameter - gap2)
    p2 = edge.valueAt(edge.FirstParameter + gap1)
    p3 = edge.valueAt(edge.FirstParameter + gap1 + len1) + dir.normalize() * extLen
    p4 = edge.valueAt(edge.LastParameter - gap2 - len2) + dir.normalize() * extLen

    e2 = Part.makeLine(p2, p3)
    e4 = Part.makeLine(p4, p1)
    section = e4.section(e2)

    if section.Vertexes :
      p5 = section.Vertexes[0].Point
      w = Part.makePolygon([p1,p2,p5,p1])
    else :
      w = Part.makePolygon([p1,p2,p3,p4,p1])
    face = Part.Face(w)
    if hasattr(face, 'mapShapes'):
        face.mapShapes([(edge,face)],None,op)
    return face 
Example #6
Source File: FSNuts.py    From FreeCAD_FastenersWB with GNU General Public License v2.0 6 votes vote down vote up
def makeSquareTool(s, m):
  # makes a cylinder with an inner square hole, used as cutting tool
  # create square face
  msq = Base.Matrix()
  msq.rotateZ(math.radians(90.0))
  polygon = []
  vsq = Base.Vector(s / 2.0, s / 2.0, -m * 0.1)
  for i in range(4):
     polygon.append(vsq)
     vsq = msq.multiply(vsq)
  polygon.append(vsq)
  square = Part.makePolygon(polygon)
  square = Part.Face(square)

  # create circle face
  circ = Part.makeCircle(s * 3.0, Base.Vector(0.0, 0.0, -m * 0.1))
  circ = Part.Face(Part.Wire(circ))

  # Create the face with the circle as outline and the square as hole
  face=circ.cut(square)
 
  # Extrude in z to create the final cutting tool
  exSquare = face.extrude(Base.Vector(0.0, 0.0, m * 1.2))
  # Part.show(exHex)
  return exSquare 
Example #7
Source File: dev.py    From NodeEditor with MIT License 6 votes vote down vote up
def cylindricprojection(self,*args, **kwargs):

    s=App.activeDocument().ReflectLines001.Shape

    eds=[]
    for e in s.Edges:
        pts2=[]
        pts=e.discretize(100)
        for p in pts:
            h=p.y
            arc=np.arctan2(p.x,p.z)
            r=FreeCAD.Vector(p.x,p.z).Length
            R=150
            p2=FreeCAD.Vector(np.sin(arc)*R,h,np.cos(arc)*R)
            pts2 += [p2]

        Part.show(Part.makePolygon(pts2))

 


#-------------------------- 
Example #8
Source File: dev.py    From NodeEditor with MIT License 6 votes vote down vote up
def mapEdgesLines( uvedges,face):

    if face == None:
        sayW("no face")
        return Part.Shape()
    col=[]
    say("face",face)
    umin,umax,vmin,vmax=face.ParameterRange
    sf=face.Surface
    for edge in uvedges:
        ua,va,ub,vb=edge
        ua=umin+ua*(umax-umin)
        va=vmin+va*(vmax-vmin)

        ub=umin+ub*(umax-umin)
        vb=vmin+vb*(vmax-vmin)
        
        pa=sf.value(ua,va)
        pb=sf.value(ub,vb)
        say(pa)
        col += [Part.makePolygon([pa,pb])]

    shape=Part.Compound(col)
    return shape 
Example #9
Source File: SheetMetalUnfolder.py    From FreeCAD_SheetMetal with GNU General Public License v3.0 5 votes vote down vote up
def SMmakeSketchfromEdges (edges, name):
    precision = 0.1 # precision in Bspline to BiArcs
    quasidef = 0.01 #quasi deflection for Ellipses and Parabola
    usk = FreeCAD.activeDocument().addObject('Sketcher::SketchObject',name)
    geo=[]
    for e in edges:
        if isinstance(e.Curve,Part.BSplineCurve):
            arcs = e.Curve.toBiArcs(precision)
            for i in arcs:
                eb = Part.Edge(i)
                seg = SMGetGeoSegment(eb)
                if seg is not None:
                    geo.append(seg)
        elif isinstance(e.Curve,Part.Ellipse) or isinstance(e.Curve,Part.Parabola):
            l=e.copy().discretize(QuasiDeflection=quasidef)
            plines=Part.makePolygon(l)
            for edg in plines.Edges:
                seg = SMGetGeoSegment(edg)
                if seg is not None:
                    geo.append(seg)
        else:
            seg = SMGetGeoSegment(e)
            if seg is not None:
                geo.append(seg)
    usk.addGeometry(geo)
    return usk



#############################################################################
# Gui Part. Widget generated from UnfoldOptions.ui using pyuic
############################################################################# 
Example #10
Source File: libS2R.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def shapeGrid(self):
        poly = []
        #polyV = []
        for row in self.result:
            poly.append(Part.makePolygon(row))
        for i in range(len(self.result[0])):
            row = []
            for j in range(len(self.result)):
                row.append(self.result[j][i])
            poly.append(Part.makePolygon(row))
        c = Part.Compound(poly)
        return(c) 
Example #11
Source File: nurbs_tools.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def param_samples(edge, samples=10):
    fp = edge.FirstParameter
    lp = edge.LastParameter
    ra = lp-fp
    return [fp+float(i)*ra/(samples-1) for i in range(samples)]

# doesn't work
#def eval_smoothness(edge, samples=10):
    #params = param_samples(edge, samples)
    ## compute length score
    #chord = edge.valueAt(edge.LastParameter) - edge.valueAt(edge.FirstParameter)
    #if chord.Length > 1e-7: 
        #length_score = (edge.Length / chord.Length) - 1.0
    #else:
        #length_score = None
    ## compute tangent and curvature scores
    #tans = list()
    #curv = list()
    #for p in params:
        #tans.append(edge.tangentAt(p))
        #curv.append(edge.curvatureAt(p))
    #poly = Part.makePolygon(tans)
    #tangent_score = poly.Length
    #m = max(curv)
    #if m > 1e-7:
        #curvature_score = (m-min(curv))/m
    #else:
        #curvature_score = 0.0
    #return length_score,tangent_score,curvature_score 
Example #12
Source File: grid2.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def draw_box():
    #pts = [getPoint(-0.5,-0.5), getPoint(0.5,-0.5), getPoint(0.5,0.5), getPoint(-0.5,0.5), getPoint(-0.5,-0.5)]
    pts = [getPoint(0,0), getPoint(1,0), getPoint(1,1), getPoint(0,1), getPoint(0,0)]
    poly = Part.makePolygon(pts)
    Part.show(poly) 
Example #13
Source File: makebox.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def make_z_panel(length, width, thickness, z_pos):
    half_length = length / 2.0
    half_width = width / 2.0
    p1 = FreeCAD.Vector(-half_length, -half_width, z_pos)
    p2 = FreeCAD.Vector(-half_length, half_width, z_pos)
    p3 = FreeCAD.Vector(half_length, half_width, z_pos)
    p4 = FreeCAD.Vector(half_length, -half_width, z_pos)

    wire = Part.makePolygon([p1,p2,p3,p4,p1])
    face = Part.Face(wire)
    part = face.extrude(FreeCAD.Vector(0, 0, thickness))
    return part


# XZ plan 
Example #14
Source File: Tracker.py    From Animation with GNU General Public License v2.0 5 votes vote down vote up
def showpath(self):
		''' path as Part.polygon '''
		FreeCAD.s=self
		points=self.Object.Proxy.path
		for p in self.Object.Proxy.path:
			say(str(p))
		pp=Part.makePolygon(points)
		Part.show(pp)
		FreeCAD.ActiveDocument.recompute()
		return FreeCAD.activeDocument().ActiveObject 
Example #15
Source File: VertexTracker.py    From Animation with GNU General Public License v2.0 5 votes vote down vote up
def showpath(self):
		''' path as Part.polygon '''
		FreeCAD.s=self
		points=self.Object.Proxy.path
		for p in self.Object.Proxy.path:
			say(str(p))
		pp=Part.makePolygon(points)
		Part.show(pp)
		FreeCAD.ActiveDocument.recompute()
		return FreeCAD.activeDocument().ActiveObject 
Example #16
Source File: Animation.py    From Animation with GNU General Public License v2.0 5 votes vote down vote up
def step(self,now):
		App=FreeCAD
		say("step " +str(now))
		s=self.obj2.ext.Spine
		ss=s[0]
		kk=s[1]
		if now==self.obj2.start:
			kk=[]
			steps=20
			steps=self.obj2.duration
			l=ss.Shape.copy().discretize(steps)
			f=Part.makePolygon(l)
			f1=Part.show(f)
			ss=FreeCAD.ActiveDocument.Objects[-1]
		kk.append("Edge"+str(now+1-self.obj2.start))
		if now<self.obj2.start:
			kk=["Edge1"]
			self.obj2.ext.ViewObject.Visibility=False
		else: 
			self.obj2.ext.ViewObject.Visibility=True
		self.obj2.ext.Spine=(ss,kk)
		FreeCAD.ActiveDocument.recompute()
		FreeCADGui.updateGui() 

#----------------------------------------------------------------------------------------------------------
#  Movie Screen
#---------------------------------------------------------------------------------------------------------- 
Example #17
Source File: interpolate.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def execute(self, obj):
        debug("* Interpolate : execute *")
        pts = self.getPoints(obj)
        self.setParameters(obj)
        if obj.Polygonal:
            if obj.Periodic:
                pts.append(pts[0])
            poly = Part.makePolygon(pts)
            if obj.WireOutput:
                obj.Shape = poly
                return
            else:
                bs = poly.approximate(1e-8,obj.Tolerance,999,1)
        else:
            bs = Part.BSplineCurve()
            bs.interpolate(Points=pts, PeriodicFlag=obj.Periodic, Tolerance=obj.Tolerance, Parameters=obj.Parameters)
            if not (len(obj.Tangents) == len(pts) and len(obj.TangentFlags) == len(pts)): # or obj.DetectAligned:
                if obj.Periodic:
                    obj.Tangents = [bs.tangent(p)[0] for p in obj.Parameters[0:-1]]
                else:
                    obj.Tangents = [bs.tangent(p)[0] for p in obj.Parameters]
                obj.TangentFlags = [True]*len(pts)
            if obj.CustomTangents: # or obj.DetectAligned:
                #if obj.DetectAligned:
                    #self.detect_aligned_pts(obj, pts)
                bs.interpolate(Points=pts, PeriodicFlag=obj.Periodic, Tolerance=obj.Tolerance, Parameters=obj.Parameters, Tangents=obj.Tangents, TangentFlags=obj.TangentFlags) #, Scale=False)
        obj.Shape = bs.toShape() 
Example #18
Source File: shapes.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def makePolygon(cls, listOfVertices, forConstruction=False):
        # convert list of tuples into Vectors.
        w = Wire(FreeCADPart.makePolygon([i.wrapped for i in listOfVertices]))
        w.forConstruction = forConstruction
        return w 
Example #19
Source File: __init__.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def makeUnitSquareWire():
    return Solid.cast(P.makePolygon([V(0, 0, 0), V(1, 0, 0), V(1, 1, 0), V(0, 1, 0), V(0, 0, 0)])) 
Example #20
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def make_gr_poly(params):
    points = SexpList(params.pts.xy)
    # close the polygon
    points._append(params.pts.xy._get(0))
    # KiCAD polygon runs in clockwise, but FreeCAD wants CCW, so must reverse.
    return Part.makePolygon([makeVect(p) for p in reversed(points)]) 
Example #21
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def make_trapezoid(size,params):
    pts = [product(size,Vector(*v)) \
            for v in ((-0.5,0.5),(-0.5,-0.5),(0.5,-0.5),(0.5,0.5))]
    try:
        delta = params.rect_delta[0]
        if delta:
            # horizontal
            idx = 1
            length = size[1]
        else:
            # vertical
            delta = params.rect_delta[1]
            idx = 0
            length = size[0]
        if delta <= -length:
            collapse = 1
            delta = -length;
        elif delta >= length:
            collapse = -1
            delta = length
        else:
            collapse = 0
        pts[0][idx] += delta*0.5
        pts[1][idx] -= delta*0.5
        pts[2][idx] += delta*0.5
        pts[3][idx] -= delta*0.5
        if collapse:
            del pts[collapse]
    except Exception:
        logger.warning('trapezoid pad has no rect_delta')

    pts.append(pts[0])
    return Part.makePolygon(pts) 
Example #22
Source File: kicad.py    From fcad_pcb with MIT License 5 votes vote down vote up
def make_rect(size,params=None):
    _ = params 
    return Part.makePolygon([product(size,Vector(*v))
        for v in ((-0.5,-0.5),(0.5,-0.5),(0.5,0.5),(-0.5,0.5),(-0.5,-0.5))]) 
Example #23
Source File: FreeCAD_Placement.py    From NodeEditor with MIT License 5 votes vote down vote up
def createShape(a):

    pa=FreeCAD.Vector(0,0,0)
    pb=FreeCAD.Vector(a*50,0,0)
    pc=FreeCAD.Vector(0,50,0)
    shape=Part.makePolygon([pa,pb,pc,pa])
    return shape 
Example #24
Source File: dev_Development.py    From NodeEditor with MIT License 5 votes vote down vote up
def run_FreeCAD_Toy3(self):
    # testdaten fuer toponaming

    pts=[
    [0,0,0],[10,0,0],[10,5,0],[0,5,0],
    [0,0,15],[10,0,15],[10,5,15],[0,5,10]
    ]

    if 1:
        [A,B,C,D,E,F,G,H]=[FreeCAD.Vector(p) for p in pts]
        col=[Part.makePolygon(l) for l in [[A,B],[B,C],[C,D],[D,A],
                [E,F],[F,G],[G,H],[H,E],
                [A,E],[B,F],[C,G],[D,H]]]
        
        Part.show(Part.Compound(col)) 
Example #25
Source File: SheetMetalRelief.py    From FreeCAD_SheetMetal with GNU General Public License v3.0 4 votes vote down vote up
def smMakeFace(vertex, face, edges, relief):

  if  edges[0].Vertexes[0].isSame(vertex) :
    Edgedir1 = edges[0].Vertexes[1].Point - edges[0].Vertexes[0].Point
  else :
    Edgedir1 = edges[0].Vertexes[0].Point - edges[0].Vertexes[1].Point
  Edgedir1.normalize()

  if  edges[1].Vertexes[0].isSame(vertex) :
    Edgedir2 = edges[1].Vertexes[1].Point - edges[1].Vertexes[0].Point
  else :
    Edgedir2 = edges[1].Vertexes[0].Point - edges[1].Vertexes[1].Point
  Edgedir2.normalize()
  normal = face.normalAt(0,0)
  Edgedir3 = normal.cross(Edgedir1)
  Edgedir4 = normal.cross(Edgedir2)

  p1 = vertex.Point
  p2 = p1 + relief * Edgedir1
  p3 = p2 + relief * Edgedir3
  if not(face.isInside(p3,0.0,True)) :
    p3 = p2 + relief * Edgedir3 * -1
  p6 = p1 + relief * Edgedir2
  p5 = p6 + relief * Edgedir4
  if not(face.isInside(p5, 0.0,True)) :
    p5 = p6 + relief * Edgedir4 * -1
  #print([p1,p2,p3,p5,p6,p1])

  e1 = Part.makeLine(p2, p3)
  #Part.show(e1,'e1')
  e2 = Part.makeLine(p5, p6)
  #Part.show(e2,'e2')
  section = e1.section(e2)
  #Part.show(section1,'section1')
  
  if section.Vertexes :
    wire = Part.makePolygon([p1,p2,p3,p6,p1])
  else :
    p41 = p3 + relief * Edgedir1 * -1
    p42 = p5 + relief * Edgedir2 * -1
    e1 = Part.Line(p3, p41).toShape()
    #Part.show(e1,'e1')
    e2 = Part.Line(p42, p5).toShape()
    #Part.show(e2,'e2')
    section = e1.section(e2)
    #Part.show(section1,'section1')
    p4 = section.Vertexes[0].Point
    wire = Part.makePolygon([p1,p2,p3,p4,p5,p6,p1])

  extface = Part.Face(wire)
  return extface 
Example #26
Source File: dev.py    From NodeEditor with MIT License 4 votes vote down vote up
def run_FreeCAD_Tread(self,produce=False, **kwargs):

    k=self.getData("noise")

    def rav(v):
        '''add a random vector to a vector'''
        return v+FreeCAD.Vector(0.5-random.random(),0.5-random.random(),(0.5-random.random())*1)*k


    pts=[self.getData("point_"+str(i)) for i in range(8)]
    pol=Part.makePolygon(pts+[pts[0]])
    f=Part.Face(pol)

    v=FreeCAD.Vector(0,0,120)
    pts2=[p+v for p in pts]
    pol2=Part.makePolygon(pts2+[pts2[0]])
    f2=Part.Face(pol2)
    colf=[f,f2]

    for i in range(8):
        pol=Part.makePolygon([pts[i-1],rav(pts[i]),rav(pts2[i]),rav(pts2[i-1]),pts[i-1]])
        f=Part.makeFilledFace(pol.Edges)
        colf += [f]

    comp=Part.Compound(colf)
    comp.Placement.Rotation=FreeCAD.Rotation(FreeCAD.Vector(1,0,0),90)
    self.setPinObject("Compound_out",comp)

    for tol in range(60,150):
        colf2=[c.copy() for c in colf]
        try:
            for f in colf2:
                f.Tolerance=tol
            sh=Part.Shell(colf2)
            sol=Part.Solid(sh)
            sol.Placement.Rotation=FreeCAD.Rotation(FreeCAD.Vector(1,0,0),90)
            if sol.isValid():
                say("solid created with tol",tol)
                if produce:
                    Part.show(sol)
                #cc=self.getObject();cc.Shape=sol
                self.setPinObject("Shape_out",sol)
                break
        except:
            pass