Python Part.Compound() Examples
The following are 30
code examples of Part.Compound().
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: multiLoftFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def execute(self, obj): if not hasattr(obj, "Sources"): return src_shapes = [] for o in obj.Sources: sh = o.Shape.copy() #pl = sh.Placement sh.Placement = o.getGlobalPlacement() #.multiply(pl) src_shapes.append(sh) solids = [] num_faces = len(src_shapes[0].Faces) for i in range(num_faces): faces = [src_shapes[0].Faces[i], src_shapes[-1].Faces[i]] loft = [] num_wires = len(faces[0].Wires) for j in range(num_wires): wires = [] for o in src_shapes: wires.append(o.Faces[i].Wires[j]) loft = Part.makeLoft(wires, False, obj.Ruled, obj.Closed, obj.MaxDegree) faces.extend(loft.Faces) shell = Part.Shell(faces) solids.append(Part.Solid(shell)) obj.Shape = Part.Compound(solids)
Example #2
Source File: shapes.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 6 votes |
def geomType(self): """ Gets the underlying geometry type :return: a string according to the geometry type. Implementations can return any values desired, but the values the user uses in type filters should correspond to these. As an example, if a user does:: CQ(object).faces("%mytype") The expectation is that the geomType attribute will return 'mytype' The return values depend on the type of the shape: Vertex: always 'Vertex' Edge: LINE, ARC, CIRCLE, SPLINE Face: PLANE, SPHERE, CONE Solid: 'Solid' Shell: 'Shell' Compound: 'Compound' Wire: 'Wire' """ return self.wrapped.ShapeType
Example #3
Source File: ReflectLinesFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def execute(self, obj): sh = None rl = False if len(obj.IndivFaces) > 0: faces = _utils.getShape(obj, "IndivFaces", "Face") sh = Part.Compound(faces) elif hasattr(obj.Source,"Shape"): sh = obj.Source.Shape try: rl = sh.reflectLines(obj.ViewDir, obj.ViewPos, obj.UpDir) except AttributeError: pass if rl and obj.ShapeCleaning: edges = rl.Edges rl = Part.Compound(nurbs_tools.remove_subsegments(edges, num=obj.Samples, tol=obj.Tolerance)) if rl: obj.Shape = rl
Example #4
Source File: dev.py From NodeEditor with MIT License | 6 votes |
def mapEdgesCurves( edges,face): '''geschmiegte V<ariante''' col=[] umin,umax,vmin,vmax=face.ParameterRange sf=face.Surface for edge in edges: 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) a=FreeCAD.Base.Vector2d(ua,va) b=FreeCAD.Base.Vector2d(ub,vb) bs2d = Part.Geom2d.BSplineCurve2d() bs2d.buildFromPolesMultsKnots([a,b],[2,2],[0,1],False,1) ee = bs2d.toShape(sf) col += [ee] shape=Part.Compound(col) return shape
Example #5
Source File: combined_curve.py From CurvesWB with GNU Lesser General Public License v2.1 | 6 votes |
def shape(self): proj1 = self.shape1.toNurbs().extrude(self.dir1) proj2 = self.shape2.toNurbs().extrude(self.dir2) curves = list() for f1 in proj1.Faces: for f2 in proj2.Faces: curves += f1.Surface.intersectSS(f2.Surface) intersect = [c.toShape() for c in curves] edges = [] for sh in intersect: if isinstance(sh, Part.Edge) and sh.Length > 1e-7: edges.append(sh) se = Part.sortEdges(edges) wires = [] for el in se: wires.append(Part.Wire(el)) return Part.Compound(wires)
Example #6
Source File: dev.py From NodeEditor with MIT License | 6 votes |
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 #7
Source File: reparametrize.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def show_lines(e1, e2, params, title=""): lines = list() for q1,q2 in params: lines.append(Part.makeLine(e1.valueAt(q1), e2.valueAt(q2))) com = Part.Compound(lines) Part.show(com, title)
Example #8
Source File: shapes.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def makeCompound(cls, listOfShapes): """ Create a compound out of a list of shapes """ solids = [s.wrapped for s in listOfShapes] c = FreeCADPart.Compound(solids) return Shape.cast(c)
Example #9
Source File: reparametrize.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def main(): s = FreeCADGui.Selection.getSelectionEx() edges = [] for so in s: for su in so.SubObjects: #subshapes(su) if isinstance(su, Part.Edge): edges.append(su) if not so.HasSubObjects: edges.append(so.Object.Shape.Wires[0]) nc1, nc2 = reparametrize(edges[0], edges[1], 40) com2 = Part.Compound([nc1.toShape(), nc2.toShape()]) Part.show(com2)
Example #10
Source File: blendSurface.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def get_gordon_shapes(self, curvetype=0): com1 = Part.Compound([self.cos1.edge, self.cos2.edge]) com2 = Part.Compound(self.blend_curves()) if curvetype == 1: com2 = Part.Compound(self.cross_curves2()) return(Part.Compound([com1, com2]))
Example #11
Source File: features.py From freecad.gears with GNU General Public License v3.0 | 5 votes |
def execute(self, fp): inner_diameter = fp.module.Value * fp.teeth outer_diameter = inner_diameter + fp.height.Value * 2 inner_circle = Part.Wire(Part.makeCircle(inner_diameter / 2.)) outer_circle = Part.Wire(Part.makeCircle(outer_diameter / 2.)) inner_circle.reverse() face = Part.Face([outer_circle, inner_circle]) solid = face.extrude(App.Vector([0., 0., -fp.thickness.Value])) # cutting obj alpha_w = np.deg2rad(fp.pressure_angle.Value) m = fp.module.Value t = fp.teeth t_c = t t_i = fp.other_teeth rm = inner_diameter / 2 y0 = m * 0.5 y1 = m + y0 y2 = m r0 = inner_diameter / 2 - fp.height.Value * 0.1 r1 = outer_diameter / 2 + fp.height.Value * 0.3 polies = [] for r_i in np.linspace(r0, r1, fp.num_profiles): pts = self.profile(m, r_i, rm, t_c, t_i, alpha_w, y0, y1, y2) poly = Wire(makePolygon(list(map(fcvec, pts)))) polies.append(poly) loft = makeLoft(polies, True) rot = App.Matrix() rot.rotateZ(2 * np.pi / t) if fp.construct: cut_shapes = [solid] for _ in range(t): loft = loft.transformGeometry(rot) cut_shapes.append(loft) fp.Shape = Part.Compound(cut_shapes) else: for i in range(t): loft = loft.transformGeometry(rot) solid = solid.cut(loft) fp.Shape = solid
Example #12
Source File: dev_Development.py From NodeEditor with MIT License | 5 votes |
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 #13
Source File: FastenerBase.py From FreeCAD_FastenersWB with GNU General Public License v2.0 | 5 votes |
def Activated(self): for selObj in Gui.Selection.getSelectionEx(): obj = selObj.Object FreeCAD.Console.PrintLog("sel shape: " + str(obj.Shape) + "\n") if isinstance(obj.Shape, (Part.Solid, Part.Compound)): FreeCAD.Console.PrintLog("simplify shape: " + obj.Name + "\n") cobj = FreeCAD.ActiveDocument.addObject("Part::Feature", obj.Label + "_Copy") cobj.Shape = obj.Shape; Gui.ActiveDocument.getObject(obj.Name).Visibility = False FreeCAD.ActiveDocument.recompute() return
Example #14
Source File: geomUtils.py From qmt with MIT License | 5 votes |
def crossSection(obj, axis=(1.0, 0.0, 0.0), d=1.0, name=None): """Return cross section of object along axis. Parameters ---------- obj : FreeCAD.App.Document A FreeCAD object. axis : (Default value = (1.0, 0.0, 0.0) d : float (Default value = 1.0) name : str (Default value = None) Returns ------- returnObj """ doc = FreeCAD.ActiveDocument if name is None: name = obj.Name + "_section" wires = list() shape = obj.Shape for i in shape.slice(vec(axis[0], axis[1], axis[2]), d): wires.append(i) returnObj = doc.addObject("Part::Feature", name) returnObj.Shape = Part.Compound(wires) return returnObj
Example #15
Source File: shapes.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def cast(cls, obj, forConstruction=False): "Returns the right type of wrapper, given a FreeCAD object" s = obj.ShapeType if type(obj) == FreeCAD.Base.Vector: return Vector(obj) tr = None # TODO: there is a clever way to do this i'm sure with a lookup # but it is not a perfect mapping, because we are trying to hide # a bit of the complexity of Compounds in FreeCAD. if s == 'Vertex': tr = Vertex(obj) elif s == 'Edge': tr = Edge(obj) elif s == 'Wire': tr = Wire(obj) elif s == 'Face': tr = Face(obj) elif s == 'Shell': tr = Shell(obj) elif s == 'Solid': tr = Solid(obj) elif s == 'Compound': #compound of solids, lets return a solid instead if len(obj.Solids) > 1: tr = Solid(obj) elif len(obj.Solids) == 1: tr = Solid(obj.Solids[0]) elif len(obj.Wires) > 0: tr = Wire(obj) else: tr = Compound(obj) else: raise ValueError("cast:unknown shape type %s" % s) tr.forConstruction = forConstruction return tr # TODO: all these should move into the exporters folder. # we don't need a bunch of exporting code stored in here! #
Example #16
Source File: shapes.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def Compounds(self): return [Compound(i) for i in self.wrapped.Compounds]
Example #17
Source File: shapes.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def isSolid(cls, obj): """ Returns true if the object is a FreeCAD solid, false otherwise """ if hasattr(obj, 'ShapeType'): if obj.ShapeType == 'Solid' or \ (obj.ShapeType == 'Compound' and len(obj.Solids) > 0): return True return False
Example #18
Source File: Discretize.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def execute(self, obj): debug("* Discretization : execute *") if self.buildPoints( obj): obj.Shape = Part.Compound([Part.Vertex(i) for i in obj.Points])
Example #19
Source File: isocurves.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def toShape(self): c = [] for u in self.uiso: c.append(u.toShape()) for v in self.viso: c.append(v.toShape()) return(Part.Compound(c))
Example #20
Source File: OrientedSketchFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def execute(self, obj): edges = [] for g in obj.Geometry: if hasattr(g, 'Construction') and not g.Construction: #try: edges.append(g.toShape()) #except AttributeError: #debug("Failed to convert %s to BSpline"%str(g)) if edges: c = Part.Compound([]) se = Part.sortEdges(edges) for l in se: c.add(Part.Wire(l)) obj.Shape = c
Example #21
Source File: gordon.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def check_curve_network_compatibility(self): # self.profiles, self.guides, self.intersectionParamsU, self.intersectionParamsV, tol): # find out the 'average' scale of the B-splines in order to being able to handle a more approximate dataset and find its intersections bsa = BSplineAlgorithms(self.par_tol) splines_scale = 0.5 * (bsa.scale(self.profiles) + bsa.scale(self.guides)) if abs(self.intersectionParamsU[0]) > (splines_scale * self.tolerance) or abs(self.intersectionParamsU[-1] - 1.) > (splines_scale * self.tolerance): self.error("WARNING: B-splines in u-direction must not stick out, spline network must be 'closed'!") if abs(self.intersectionParamsV[0]) > (splines_scale * self.tolerance) or abs(self.intersectionParamsV[-1] - 1.) > (splines_scale * self.tolerance): self.error("WARNING: B-splines in v-direction mustn't stick out, spline network must be 'closed'!") # check compatibility of network #ucurves = list() #vcurves = list() debug("check_curve_network_compatibility") for u_param_idx in range(len(self.intersectionParamsU)): #(size_t u_param_idx = 0; u_param_idx < self.intersectionParamsU.size(); ++u_param_idx) { spline_u_param = self.intersectionParamsU[u_param_idx] spline_v = self.guides[u_param_idx] #vcurves.append(spline_v.toShape()) for v_param_idx in range(len(self.intersectionParamsV)): #(size_t v_param_idx = 0; v_param_idx < self.intersectionParamsV.size(); ++v_param_idx) { spline_u = self.profiles[v_param_idx] #ucurves.append(spline_u.toShape()) spline_v_param = self.intersectionParamsV[v_param_idx] #debug("spline_u_param, spline_v_param = %0.5f,%0.5f"%(spline_u_param, spline_v_param)) p_prof = spline_u.value(spline_u_param) p_guid = spline_v.value(spline_v_param) #debug("p_prof, p_guid = %s,%s"%(p_prof, p_guid)) distance = p_prof.distanceToPoint(p_guid) #debug("distance = %f"%(distance)) if (distance > splines_scale * self.tolerance): self.error("\nB-spline network is incompatible (e.g. wrong parametrization) or intersection parameters are in a wrong order!") self.error("\nprofile {} - guide {}".format(u_param_idx, v_param_idx)) #Part.show(Part.Compound(ucurves)) #Part.show(Part.Compound(vcurves))
Example #22
Source File: gordon.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def curve_network(self): self.perform() profiles = Part.Compound([c.toShape() for c in self.profiles]) guides = Part.Compound([c.toShape() for c in self.guides]) return(Part.Compound([profiles,guides]))
Example #23
Source File: blendSurfaceFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def shapeCloud(arr): v = [] for row in arr: for pt in row: v.append(Part.Vertex(pt)) c = Part.Compound(v) return c
Example #24
Source File: approximate_extension.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def approximate(self, obj, input_shape): pts = False input_edges = None if isinstance(input_shape,(list, tuple)): #debug(isinstance(input_shape[0],Base.Vector)) if isinstance(input_shape[0],Base.Vector): pts = input_shape elif isinstance(input_shape[0],Part.Edge): input_edges = input_shape else: input_edges = input_shape.Edges if not obj.Active: return Part.Compound(input_shape) edges = list() if input_edges: for e in input_edges: pts = e.discretize(obj.Samples) bs = Part.BSplineCurve() bs.approximate(Points = pts, DegMin = obj.DegreeMin, DegMax = obj.DegreeMax, Tolerance = obj.ApproxTolerance, Continuity = obj.Continuity, ParamType = obj.Parametrization) edges.append(bs.toShape()) se = Part.sortEdges(edges) wires = [] for el in se: if len(el) > 1: wires.append(Part.Wire(el)) else: wires.append(el[0]) if len(wires) > 1: return Part.Compound(wires) else: return wires[0] elif pts: bs = Part.BSplineCurve() bs.approximate(Points = pts, DegMin = obj.DegreeMin, DegMax = obj.DegreeMax, Tolerance = obj.ApproxTolerance, Continuity = obj.Continuity, ParamType = obj.Parametrization) return bs.toShape()
Example #25
Source File: HelicalSweepFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def sweep_wire(self, w, solid=False): faces = [] for e in w.Edges: faces.append(self.sweep_edge(e,solid)) shell = Part.Shell(faces) shell.sewShape() if solid: cyl = Part.makeCylinder(self.max_radius*2, self.nb_of_turns*self.lead) cyl.Placement = self._placement.multiply(FreeCAD.Placement(FreeCAD.Vector(),FreeCAD.Vector(1,0,0),-90)) common = cyl.common(shell) cut_faces = common.Faces new_edges = [] for e1 in common.Edges: found = False for e2 in shell.Edges: if nurbs_tools.is_same(e1.Curve, e2.Curve, tol=1e-7, full=False): found = True #print("found similar edges") continue if not found: new_edges.append(e1) #print(len(Part.sortEdges(new_edges))) el1, el2 = Part.sortEdges(new_edges)[0:2] f1 = Part.makeFace(Part.Wire(el1),'Part::FaceMakerSimple') f2 = Part.makeFace(Part.Wire(el2),'Part::FaceMakerSimple') cut_faces.extend([f1,f2]) try: shell = Part.Shell(cut_faces) shell.sewShape() return Part.Solid(shell) except Part.OCCError: print("Failed to create solid") return Part.Compound(cut_faces) return shell
Example #26
Source File: parametricSolid.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def execute(self, obj): faces = _utils.getShape(obj,"Faces","Face") shell = Part.Shell(faces) solid = Part.Solid(shell) if solid.isValid(): obj.Shape = solid elif shell.isValid(): obj.Shape = shell else: obj.Shape = Part.Compound(faces)
Example #27
Source File: libS2R.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
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 #28
Source File: libS2R.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def InterpoCurves(self): el = [] for ic in self.interpoCurves: for c in ic: el.append(Part.Edge(c)) return(Part.Compound(el))
Example #29
Source File: libS2R.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def LocalProfiles(self): el = [] for pro in self.profiles: el.append(pro.localCurve1) return(Part.Compound(el))
Example #30
Source File: HQRuledSurfaceFP.py From CurvesWB with GNU Lesser General Public License v2.1 | 5 votes |
def execute(self, obj): c1, c2 = self.get_curves(obj) nc1, nc2 = rp.reparametrize(c1, c2, num=obj.Samples, smooth_start=obj.SmoothingFactorStart, smooth_end=obj.SmoothingFactorEnd, method=obj.Method ) #com = Part.Compound([nc1.toShape(), nc2.toShape()]) rs = Part.makeRuledSurface(nc1.toShape(), nc2.toShape()) if isinstance(rs, Part.Face) and rs.isValid(): obj.Shape = rs