Python Part.LineSegment() Examples
The following are 17
code examples of Part.LineSegment().
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: HelicalSweepFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 7 votes |
def make_profile_sketch(self): import Sketcher sk = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Profile') sk.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(0,0,0,1)) sk.MapMode = "Deactivated" sk.addGeometry(Part.LineSegment(FreeCAD.Vector(100.0,0.0,0),FreeCAD.Vector(127.0,12.0,0)),False) sk.addConstraint(Sketcher.Constraint('PointOnObject',0,1,-1)) sk.addGeometry(Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(125.0,17.0,0),FreeCAD.Vector(0,0,1),5.8),-1.156090,1.050925),False) sk.addConstraint(Sketcher.Constraint('Tangent',0,2,1,1)) sk.addGeometry(Part.LineSegment(FreeCAD.Vector(128.0,22.0,0),FreeCAD.Vector(100.0,37.0,0)),False) sk.addConstraint(Sketcher.Constraint('Tangent',1,2,2,1)) sk.addConstraint(Sketcher.Constraint('Vertical',0,1,2,2)) sk.addConstraint(Sketcher.Constraint('DistanceY',0,1,2,2,37.5)) sk.setDatum(4,FreeCAD.Units.Quantity('35.000000 mm')) sk.renameConstraint(4, u'Lead') sk.setDriving(4,False) sk.addConstraint(Sketcher.Constraint('Equal',2,0)) FreeCAD.ActiveDocument.recompute() return sk
Example #2
Source File: shapes.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
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 #3
Source File: comp_spring.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
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 #4
Source File: Sketch_On_Surface.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def addFaceBoundsToSketch(para_range, sk): geoList = list() conList = list() u0,u1,v0,v1 = para_range geoList.append(Part.LineSegment(vec(u0,v0,0),vec(u1,v0,0))) geoList.append(Part.LineSegment(vec(u1,v0,0),vec(u1,v1,0))) geoList.append(Part.LineSegment(vec(u1,v1,0),vec(u0,v1,0))) geoList.append(Part.LineSegment(vec(u0,v1,0),vec(u0,v0,0))) o = int(sk.GeometryCount) sk.addGeometry(geoList,False) conList.append(Sketcher.Constraint('Coincident',o+0,2,o+1,1)) conList.append(Sketcher.Constraint('Coincident',o+1,2,o+2,1)) conList.append(Sketcher.Constraint('Coincident',o+2,2,o+3,1)) conList.append(Sketcher.Constraint('Coincident',o+3,2,o+0,1)) conList.append(Sketcher.Constraint('Horizontal',o+0)) conList.append(Sketcher.Constraint('Horizontal',o+2)) conList.append(Sketcher.Constraint('Vertical',o+1)) conList.append(Sketcher.Constraint('Vertical',o+3)) conList.append(Sketcher.Constraint('DistanceX',o+2,2,o+2,1,u1-u0)) conList.append(Sketcher.Constraint('DistanceY',o+1,1,o+1,2,v1-v0)) conList.append(Sketcher.Constraint('DistanceX',o+0,1,-1,1,-u0)) conList.append(Sketcher.Constraint('DistanceY',o+0,1,-1,1,-v0)) sk.addConstraint(conList)
Example #5
Source File: SheetMetalUnfolder.py From FreeCAD_SheetMetal with GNU General Public License v3.0 | 5 votes |
def SMGetGeoSegment(e): if 'Line' in str(e.Curve): return Part.LineSegment(e.Vertexes[0].Point,e.Vertexes[1].Point) elif 'Circle' in str(e.Curve): if not e.Closed: return Part.ArcOfCircle(e.Curve, e.FirstParameter, e.LastParameter,e.Curve.Axis.z>0) else: return Part.Circle(e.Curve.Center,e.Curve.Axis,e.Curve.Radius) return None
Example #6
Source File: ParametricBlendCurve.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def line(self, ed, p): e = self.getEdge(ed) pt = e.valueAt(p) t = e.tangentAt(p).multiply(100000) l = Part.LineSegment(pt,pt.add(t)).toShape() return(l)
Example #7
Source File: sketchUtils.py From qmt with MIT License | 5 votes |
def addPolyLineSketch(name, doc, segmentOrder, lineSegments): """Add a sketch given segment order and line segments. Parameters ---------- name : doc : segmentOrder : lineSegments : Returns ------- """ if doc.getObject(name) is not None: raise ValueError(f"Sketch with name '{name}' already exists.") obj = doc.addObject("Sketcher::SketchObject", name) for segIndex, segment in enumerate(lineSegments): startPoint = segment[0, :] endPoint = segment[1, :] obj.addGeometry(Part.LineSegment(vec(tuple(startPoint)), vec(tuple(endPoint)))) for i in range(len(lineSegments)): connectIndex = segmentOrder[i] if connectIndex < len(lineSegments): obj.addConstraint(Sketcher.Constraint("Coincident", i, 2, connectIndex, 1)) doc.recompute() return obj
Example #8
Source File: sketchUtils.py From qmt with MIT License | 5 votes |
def addCycleSketch(name, wire): """Add a sketch of a cycle (closed wire) to a FC document. Parameters ---------- name : wire : Returns ------- """ assert wire.isClosed() doc = FreeCAD.ActiveDocument if doc.getObject(name) is not None: raise ValueError(f"Sketch with name '{name}' already exists.") # makeSketch() could handle constraints itself and does recompute() well, # but sometimes we may have invalid wires, which it handles badly (fixsometime) # ~ return Draft.makeSketch([wire], name=name, autoconstraints=True) sketch = doc.addObject("Sketcher::SketchObject", name) for i, edge in enumerate(wire.Edges): v0 = vec(tuple(edge.Vertexes[0].Point)) v1 = vec(tuple(edge.Vertexes[1].Point)) if i > 0: if (v0 - old_v1).Length > 1e-5: # fix invalid wire segments v1 = vec(tuple(edge.Vertexes[0].Point)) v0 = vec(tuple(edge.Vertexes[1].Point)) old_v1 = v1 sketch.addGeometry(Part.LineSegment(v0, v1)) if i > 0: sketch.addConstraint(Sketcher.Constraint("Coincident", i - 1, 2, i, 1)) sketch.addConstraint(Sketcher.Constraint("Coincident", i, 2, 0, 1)) doc.recompute() return sketch
Example #9
Source File: conftest.py From qmt with MIT License | 5 votes |
def fix_rectangle_sketch(): """Return unit square sketch function object.""" def aux_rectangle_sketch(x_length=1, y_length=1, x_start=0, y_start=0): """Helper function to drop a simple unit square sketch. The segments are carefully ordered. """ import FreeCAD import Part vec = FreeCAD.Vector lseg = Part.LineSegment a = (x_start, y_start, 0) b = (x_length, y_start, 0) c = (x_length, y_length, 0) d = (x_start, y_length, 0) doc = FreeCAD.ActiveDocument sketch = doc.addObject("Sketcher::SketchObject", "Sketch") sketch.addGeometry(lseg(vec(*a), vec(*b)), False) sketch.addGeometry(lseg(vec(*b), vec(*c)), False) sketch.addGeometry(lseg(vec(*c), vec(*d)), False) sketch.addGeometry(lseg(vec(*d), vec(*a)), False) doc.recompute() return sketch return aux_rectangle_sketch
Example #10
Source File: conftest.py From qmt with MIT License | 5 votes |
def fix_two_cycle_sketch(): """Return two-cycle sketch function object.""" def aux_two_cycle_sketch( a=(20, 20, 0), b=(-30, 20, 0), c=(-30, -10, 0), d=(20, -10, 0), e=(50, 50, 0), f=(60, 50, 0), g=(55, 60, 0), ): """Helper function to drop a simple multi-cycle sketch. The segments are ordered into one rectangle and one triangle. """ # Note: the z-component is zero, as sketches are plane objects. # Adjust orientation with Sketch.Placement(Normal, Rotation) import Part import FreeCAD vec = FreeCAD.Vector lseg = Part.LineSegment doc = FreeCAD.ActiveDocument sketch = doc.addObject("Sketcher::SketchObject", "Sketch") sketch.addGeometry(lseg(vec(*a), vec(*b)), False) sketch.addGeometry(lseg(vec(*b), vec(*c)), False) sketch.addGeometry(lseg(vec(*c), vec(*d)), False) sketch.addGeometry(lseg(vec(*d), vec(*a)), False) sketch.addGeometry(lseg(vec(*e), vec(*f)), False) sketch.addGeometry(lseg(vec(*f), vec(*g)), False) sketch.addGeometry(lseg(vec(*g), vec(*e)), False) doc.recompute() return sketch return aux_two_cycle_sketch
Example #11
Source File: kicad.py From fcad_pcb with MIT License | 5 votes |
def getFaceCompound(shape,wire=False): objs = [] for f in shape.Faces: selected = True for v in f.Vertexes: if not isZero(v.Z): selected = False break if not selected: continue ################################################################ ## TODO: FreeCAD curve.normalAt is not implemented ################################################################ # for e in f.Edges: # if isinstance(e.Curve,(Part.LineSegment,Part.Line)): continue # if not isZero(e.normalAt(Vector()).dot(Vector(0,0,1))): # selected = False # break # if not selected: continue if not wire: objs.append(f) continue for w in f.Wires: objs.append(w) if not objs: raise ValueError('null shape') return Part.makeCompound(objs)
Example #12
Source File: a2plib.py From A2plus with GNU Lesser General Public License v2.1 | 5 votes |
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: a2plib.py From A2plus with GNU Lesser General Public License v2.1 | 5 votes |
def isLine(param): if hasattr(Part,"LineSegment"): return isinstance(param,(Part.Line,Part.LineSegment)) else: return isinstance(param,Part.Line) #------------------------------------------------------------------------------
Example #14
Source File: lineFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def execute(self, obj): v1 = _utils.getShape(obj, "Vertex1", "Vertex") v2 = _utils.getShape(obj, "Vertex2", "Vertex") if v1 and v2: l = Part.LineSegment(v1.Point, v2.Point) obj.Shape = l.toShape() else: FreeCAD.Console.PrintError("%s broken !\n"%obj.Label)
Example #15
Source File: ProfileSketch.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def execute(self, obj): e1,e2 = self.getEdges(obj) if (not e1) or (not e2): return() if hasattr(obj, "Parameter1") and hasattr(obj, "Parameter2") and hasattr(obj, "MainAxis"): l1 = Part.LineSegment(e1.valueAt(obj.Parameter1), e2.valueAt(obj.Parameter2)) v = FreeCAD.Vector(obj.MainAxis) if v.Length < 1e-6: v = FreeCAD.Vector(0,0,1) direction = v.normalize().multiply(l1.length()) obj.Shape = l1.toShape().extrude(direction) return()
Example #16
Source File: ribbon.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def getNotches(self, num=20, l=1.0): notches = list() for i in range(num): par = 1.0*i / (num-1) p1, p2 = self.valueAt(par) ls = Part.LineSegment(p1, p2) p3 = ls.value(ls.FirstParameter - l) p4 = ls.value(ls.LastParameter + l) nls = Part.makeLine(p3, p4) sh1 = self.rail1.face.project([nls]) sh2 = self.rail2.face.project([nls]) if (len(sh1.Edges) > 0) and (len(sh2.Edges) > 0): notches.append((sh1.Edges[0], sh2.Edges[0])) return(notches)
Example #17
Source File: blendsurf_editor.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def param(self, par): if (par >= self.edge.FirstParameter) and (par <= self.edge.LastParameter): self._par = par self.p1 = MarkerOnShape([self.edge.valueAt(self._par)],edge) tangent = self.edge.tangentAt(self._par) # TODO change tangent to cross-tangent tangent.normalize() tangent.multiply(1e12) l = Part.LineSegment(self.edge.valueAt(self._par).sub(tangent),self.edge.valueAt(self._par).add(tangent)) self.tangent = l.toShape() self.p2 = MarkerOnShape([self.tangent.valueAt(self._scale)],self.tangent) else: FreeCAD.Console.PrintError("Bad parameter value, setting to middle of edge") self._par = self.edge.FirstParameter + 0.5 * (self.edge.LastParameter - self.edge.FirstParameter)