Python Part.Line() Examples

The following are 16 code examples of Part.Line(). 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: comp_spring.py    From CurvesWB with GNU Lesser General Public License v2.1 6 votes vote down vote up
def compute_path_cp(self):
        free_turns = self.turns-2
        skew = Part.LineSegment(Vector(2*pi,self.wire_diam,0),Vector((self.turns-1)*2*pi,self.length-self.wire_diam,0))
        tan = skew.tangent(skew.FirstParameter)[0]
        tan.normalize()
        tan.multiply(self.wire_diam/2.)
        p1 = Vector(-tan.y,tan.x,0)
        ls = Part.Line(skew.StartPoint+p1,skew.EndPoint-p1)
        h1 = Part.Line(Vector(0,self.wire_diam/2.,0),Vector(1,self.wire_diam/2.,0))
        h2 = Part.Line(Vector(0,self.length-self.wire_diam/2.,0),Vector(1,self.length-self.wire_diam/2.,0))
        pts = [Vector2d(0,self.wire_diam/2.)]
        i1 = h1.intersect(ls)[0]
        i2 = h2.intersect(ls)[0]
        pts.append(Vector2d(i1.X,i1.Y))
        pts.append(Vector2d(i2.X,i2.Y))
        pts.append(Vector2d(self.turns*2*pi,self.length-self.wire_diam/2.))
        return pts 
Example #2
Source File: frameForms.py    From flamingo with GNU Lesser General Public License v3.0 6 votes vote down vote up
def selectAction(self):
    edged = [objex for objex in FreeCADGui.Selection.getSelectionEx() if frameCmd.edges([objex])]
    if edged:
      self.Axis=frameCmd.edges([edged[0]])[0]
      self.deleteArrow()
      from polarUtilsCmd import arrow
      where=FreeCAD.Placement()
      where.Base=self.Axis.valueAt(self.Axis.LastParameter)
      where.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),self.Axis.tangentAt(self.Axis.LastParameter))
      size=[self.Axis.Length/20.0,self.Axis.Length/10.0,self.Axis.Length/20.0]
      self.arrow=arrow(pl=where,scale=size,offset=self.Axis.Length/10.0)
      if self.Axis.curvatureAt(0):
        O=self.Axis.centerOfCurvatureAt(0)
        n=self.Axis.tangentAt(0).cross(self.Axis.normalAt(0))
        from Part import Edge, Line
        self.Axis=(Edge(Line(FreeCAD.Vector(O),FreeCAD.Vector(O+n))))
      self.form.lab1.setText(edged[0].Object.Label+": edge") 
Example #3
Source File: NiCrPath.py    From NiCr with GNU General Public License v2.0 6 votes vote down vote up
def PathToShape(point_list):
    # creates a compound of faces from a NiCr point list to representate the wire
    # trajectory
    comp = []
    for i in range(len(point_list[0])-1):
        pa_0 = FreeCAD.Vector(tuple(point_list[0][i]))
        pa_1 = FreeCAD.Vector(tuple(point_list[0][i+1]))
        pb_0 = FreeCAD.Vector(tuple(point_list[1][i]))
        pb_1 = FreeCAD.Vector(tuple(point_list[1][i+1]))
        l0 = Part.Line(pa_0, pa_1).toShape()
        l1 = Part.Line(pb_0, pb_1).toShape()
        f = Part.makeLoft([l0, l1])
        comp.append(f)

    return Part.makeCompound(comp)




# routing between WirePaths (wirepath path link) 
Example #4
Source File: shapes.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
def __init__(self, obj):
        """
            An Edge
        """
        self.wrapped = obj
        # self.startPoint = None
        # self.endPoint = None

        self.edgetypes = {
            FreeCADPart.ArcOfCircle: 'ARC',
            FreeCADPart.Circle: 'CIRCLE'
        }

        if hasattr(FreeCADPart,"Line"):
            self.edgetypes[FreeCADPart.Line] = 'LINE'

        if hasattr(FreeCADPart,"LineSegment"):
            self.edgetypes[FreeCADPart.LineSegment] = 'LINE'

         # Helps identify this solid through the use of an ID
        self.label = "" 
Example #5
Source File: utils.py    From FreeCAD_assembly3 with GNU General Public License v3.0 5 votes vote down vote up
def isLine(param):
    return isinstance(param,(Part.Line,Part.LineSegment)) 
Example #6
Source File: utils.py    From FreeCAD_assembly3 with GNU General Public License v3.0 5 votes vote down vote up
def getVertexes(shape):
    v = shape.Vertexes
    if v or shape.countElement('Edge')!=1:
        return v
    curve = shape.Edge1.Curve
    if isinstance(curve,Part.Line):
        return [Part.Vertex(curve.Location),
                Part.Vertex(curve.Location+curve.Direction)]
    return [] 
Example #7
Source File: curveOnSurface.py    From CurvesWB with GNU Lesser General Public License v2.1 5 votes vote down vote up
def tangentTo(self, t, pt):
        v = self.valueAt(t)
        n = self.normalAt(t)
        tanPlane = Part.Plane(v,n)
        line = Part.Line(pt, pt.add(n))
        ptOnPlane = tanPlane.intersect(line)
        res = []
        if isinstance(ptOnPlane,tuple):
            for el in ptOnPlane:
                if isinstance(el,(tuple,list)):
                    for e in el:
                        if isinstance(e,Part.Point):
                            res.append(FreeCAD.Vector(e.X,e.Y,e.Z).sub(v))
        return(res) 
Example #8
Source File: polarUtilsCmd.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def disegna(sk, pos):
  'arg1=sketch, arg2=pos (list of 3-uple): draws the segments of "pos" in "sketch" and close the polygon'
  import FreeCAD, Part, Sketcher
  lines=[]
  while len(pos)>1:
    lines.append(sk.addGeometry(Part.Line(FreeCAD.Vector(pos[0]),FreeCAD.Vector(pos[1]))))
    pos.pop(0)
  for i in range(len(lines)-1):
    sk.addConstraint(Sketcher.Constraint('Coincident',lines[i],2,lines[i+1],1))
  sk.addConstraint(Sketcher.Constraint('Coincident',lines[len(lines)-1],2,lines[0],1))
  FreeCAD.activeDocument().recompute()
  return lines 
Example #9
Source File: polarUtilsCmd.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, wireFlag=True):
    DraftTools.Line.__init__(self,wireFlag)
    self.Activated()
    dialogPath=join(dirname(abspath(__file__)),"dialogs","hackedline.ui")
    self.hackedUI=FreeCADGui.PySideUic.loadUi(dialogPath)
    self.hackedUI.btnRot.clicked.connect(self.rotateWP)
    self.hackedUI.btnOff.clicked.connect(self.offsetWP)
    self.hackedUI.btnXY.clicked.connect(lambda: self.alignWP(FreeCAD.Vector(0,0,1)))
    self.hackedUI.btnXZ.clicked.connect(lambda: self.alignWP(FreeCAD.Vector(0,1,0)))
    self.hackedUI.btnYZ.clicked.connect(lambda: self.alignWP(FreeCAD.Vector(1,0,0)))
    self.ui.layout.addWidget(self.hackedUI) 
Example #10
Source File: frameForms.py    From flamingo with GNU Lesser General Public License v3.0 5 votes vote down vote up
def getPrincipalAx(self, ax='Z'):
    self.deleteArrow()
    from Part import Edge,Line
    O=FreeCAD.Vector()
    l=Line(O,FreeCAD.Vector(0,0,1000))
    if ax=='X':
      l=Line(O,FreeCAD.Vector(1000,0,0))
    elif ax=='Y':
      l=Line(O,FreeCAD.Vector(0,1000,0))
    self.Axis=Edge(l)
    self.form.lab1.setText("Principal: "+ax) 
Example #11
Source File: a2plib.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def isLine(param):
    if hasattr(Part,"LineSegment"):
        return isinstance(param,(Part.Line,Part.LineSegment))
    else:
        return isinstance(param,Part.Line)
#------------------------------------------------------------------------------ 
Example #12
Source File: a2plib.py    From A2plus with GNU Lesser General Public License v2.1 5 votes vote down vote up
def drawVector(fromPoint,toPoint, color):
    if fromPoint == toPoint: return
    doc = FreeCAD.ActiveDocument

    l = Part.LineSegment()
    l.StartPoint = fromPoint
    l.EndPoint = toPoint
    line = doc.addObject("Part::Feature","Line")
    line.Shape = l.toShape()
    line.ViewObject.LineColor = color
    line.ViewObject.LineWidth = 1

    
    c = Part.makeCone(0,1,4)
    cone = doc.addObject("Part::Feature","ArrowHead")
    cone.Shape = c
    cone.ViewObject.ShapeColor = color
    #
    mov = Base.Vector(0,0,0)
    zAxis = Base.Vector(0,0,-1)
    rot = FreeCAD.Rotation(zAxis,toPoint.sub(fromPoint))
    cent = Base.Vector(0,0,0)
    conePlacement = FreeCAD.Placement(mov,rot,cent)
    cone.Placement = conePlacement.multiply(cone.Placement)
    cone.Placement.move(toPoint)
    doc.recompute()
#------------------------------------------------------------------------------ 
Example #13
Source File: flextab.py    From LCInterlocking with GNU Lesser General Public License v2.1 5 votes vote down vote up
def make_rounded_shape(material_face, material_plane, width, pos_y, use_laser_kerf = True):
    part_thickness = material_face.thickness
    other_part_thickness_with_tolerance = material_plane.thickness + material_plane.thickness_tolerance

    corrected_width = width
    if use_laser_kerf:
        corrected_width = corrected_width + material_face.laser_beam_diameter

    half_width = corrected_width / 2.0
    z = part_thickness/2.0
    th = other_part_thickness_with_tolerance

    p1 = FreeCAD.Vector(0., -half_width, z)
    p2 = FreeCAD.Vector(0.3 * th, -half_width, z)
    cp2_1 = FreeCAD.Vector(0.9 * th, -half_width, z)
    p3 = FreeCAD.Vector(0.9 * th, 0, z)
    cp3_1 = FreeCAD.Vector(0.9 * th, half_width / 4.0, z)
    cp3_2 = FreeCAD.Vector(1.6 * th, half_width / 4.0, z)
    p4 = FreeCAD.Vector(1.6 * th, half_width / 2.0, z)
    p5 = FreeCAD.Vector(1.6 * th, half_width, z)
    cp5_1 = FreeCAD.Vector(1.6 * th, 1.2 * half_width, z)
    p6 = FreeCAD.Vector(1.04 * th, 1.2 * half_width, z)
    p7 = FreeCAD.Vector(th, half_width, z)
    p8 = FreeCAD.Vector(0, half_width, z)

    l1 = Part.Line(p1, p2)
    c2 = make_bezier_curve([p2, cp2_1, p3])
    c3 = make_bezier_curve([p3, cp3_1, cp3_2, p4])
    l4 = Part.Line(p4, p5)
    c5 = make_bezier_curve([p5, cp5_1, p6])
    l6 = Part.Line(p6, p7)
    l7 = Part.Line(p7, p8)
    l8 = Part.Line(p8, p1)

    shape = Part.Shape([l1, c2, c3, l4, c5, l6, l7, l8])
    wire = Part.Wire(shape.Edges)
    face = Part.Face(wire)
    part = face.extrude(FreeCAD.Vector(0, 0, -part_thickness))
    part.translate(FreeCAD.Vector(0, pos_y, 0))
    #Part.show(part)
    return part 
Example #14
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 #15
Source File: flextab.py    From LCInterlocking with GNU Lesser General Public License v2.1 4 votes vote down vote up
def make_rounded_shape_for_groove(material_face, material_plane, width, pos_y, use_laser_kerf = True):
    part_thickness = material_face.thickness
    other_part_thickness_with_tolerance = material_plane.thickness + material_plane.thickness_tolerance

    corrected_width = width
    if use_laser_kerf:
        corrected_width = corrected_width + material_face.laser_beam_diameter

    half_width = corrected_width / 2.0
    z = part_thickness/2.0
    th = other_part_thickness_with_tolerance

    p1 = FreeCAD.Vector(0., -half_width, z)
    p2 = FreeCAD.Vector(th, -half_width, z)
    p3 = FreeCAD.Vector(1.04 * th, -1.15 * half_width, z)
    p4 = FreeCAD.Vector(1.4 * th, -1.15 * half_width, z)
    cp4_1 = FreeCAD.Vector(1.6 * th, -half_width / 4.0, z)
    p5 = FreeCAD.Vector(th, half_width / 4.0, z)
    p6 = FreeCAD.Vector(th, 0.7 * half_width, z)
    cp6_1 = FreeCAD.Vector(th, half_width, z)
    p7 = FreeCAD.Vector(0.7 * th, half_width, z)
    p8 = FreeCAD.Vector(0, half_width, z)

    l1 = Part.Line(p1, p2)
    l2 = Part.Line(p2, p3)
    l3 = Part.Line(p3, p4)
    c4 = make_bezier_curve([p4, cp4_1, p5])
    l5 = Part.Line(p5, p6)
    c6 = make_bezier_curve([p6, cp6_1, p7])
    p7 = Part.Line(p7, p8)
    p8 = Part.Line(p8, p1)

    shape = Part.Shape([l1, l2, l3, c4, l5, c6, p7, p8])
    wire = Part.Wire(shape.Edges)
    face = Part.Face(wire)
    part = face.extrude(FreeCAD.Vector(0, 0, -part_thickness))
    part.translate(FreeCAD.Vector(0, pos_y, 0))
    #Part.show(part)

    part = helper.make_dog_bone_on_limits_on_xz(part, part_thickness)

    return part 
Example #16
Source File: flextab.py    From LCInterlocking with GNU Lesser General Public License v2.1 4 votes vote down vote up
def make_flex_slot(material_face, material_plane, width, pos_y, use_laser_kerf = True):
    part_thickness = material_face.thickness
    corrected_width = width
    if use_laser_kerf:
        corrected_width = corrected_width + material_face.laser_beam_diameter

    x_start = (material_plane.thickness + material_plane.thickness_tolerance) * 2.0 # 2.0 is arbitrary
    y_start = width / 5.0
    x_length = 1.8 * corrected_width
    y_length = 0.6 * corrected_width
    groove_thickness = 0.15 * corrected_width

    z = part_thickness / 2.0
    p1 = FreeCAD.Vector(x_start, y_start, z)
    p2 = FreeCAD.Vector(-x_length / 12.0, y_start, z)
    cp2_1 = FreeCAD.Vector(-x_length / 6.0, y_start, z)
    cp2_2 = FreeCAD.Vector(-x_length / 2.0, y_start - y_length, z)
    p3 = FreeCAD.Vector(FreeCAD.Vector(-x_length, y_start - (y_length / 2.0) , z))

    half_groove = groove_thickness / 2.0
    lp1 = p1 + FreeCAD.Vector(0., -half_groove, 0)
    rp1 = p1 + FreeCAD.Vector(0., half_groove, 0)
    lp2 = p2 + FreeCAD.Vector(0., -half_groove, 0)
    rp2 = p2 + FreeCAD.Vector(0., half_groove, 0)
    lcp2_1 = cp2_1 + FreeCAD.Vector(0., -half_groove, 0)
    rcp2_1 = cp2_1 + FreeCAD.Vector(0., half_groove, 0)
    lcp2_2 = cp2_2 + FreeCAD.Vector(0., -half_groove, 0)
    rcp2_2 = cp2_2 + FreeCAD.Vector(0., half_groove, 0)
    lp3 = p3 + FreeCAD.Vector(0., -half_groove, 0)
    rp3 = p3 + FreeCAD.Vector(0., half_groove, 0)

    local_axe_tmp = rp3.sub(lp3)
    local_axe_tmp.normalize()
    arc_dir_vector = FreeCAD.Vector(0,0,1).cross(local_axe_tmp)
    arc_dir_vector.normalize()
    arc_cp = (rp3 + lp3) * 0.5 + arc_dir_vector * local_axe_tmp.Length * 0.5

    l1 = Part.Line(lp1, lp2)
    c2 = make_bezier_curve([lp2, lcp2_1, lcp2_2, lp3])
    a3 = Part.Arc(lp3, arc_cp, rp3)
    c4 = make_bezier_curve([rp2, rcp2_1, rcp2_2, rp3])
    l5 = Part.Line(rp1, rp2)
    l6 = Part.Line(rp1, lp1)

    shape = Part.Shape([l1, c2, a3, c4, l5, l6])
    wire = Part.Wire(shape.Edges)
    face = Part.Face(wire)
    part = face.extrude(FreeCAD.Vector(0, 0, -part_thickness))
    #Part.show(part)
    part.translate(FreeCAD.Vector(0, pos_y, 0))

    return part