def ApplySurfaceToText(self, surface, surfaces_written): if not surface in surfaces_written: surfaces_written[surface] = True tris = geom.Stl() for solid in surface.solids: o = cad.GetObjectFromId(cad.OBJECT_TYPE_STL_SOLID, solid) tris += o.GetTris(surface.tolerance) # name the stl file import tempfile temp_filename = tempfile.gettempdir( ) + '/surface%d.stl' % self.number_for_stl_file self.number_for_stl_file += 1 # write stl file tris.WriteStl(temp_filename) import attach import ocl_funcs attach.units = self.units attach.attach_begin() import nc.nc nc.nc.creator.stl = ocl_funcs.STLSurfFromFile(temp_filename) nc.nc.creator.minz = -10000.0 nc.nc.creator.material_allowance = surface.material_allowance wx.GetApp().attached_to_surface = surface
def MakeStlSolid(self): global drawing_mode global stl_to_add_to save_mode = drawing_mode save_render_pattern = self.render_pattern save_render_wing = self.render_wing stl_to_add_to = geom.Stl() drawing_mode = DRAWING_MODE_STL self.render_pattern = False self.render_wing = True self.OnRenderTriangles() drawing_mode = save_mode self.render_wing = save_render_wing self.save_render_pattern = save_render_pattern return stl_to_add_to
def SplitStlAtZ(self): p = self.PickPosition('Pick point at z height') if p == None: return temp_file = wx.StandardPaths.Get().GetTempDir() + '/split.stl' self.object.WriteSTL(0.001, temp_file) stl = geom.Stl(temp_file) new_stl = stl.SplitAtZ(p.z) if new_stl != None: stl.WriteStl(temp_file) cad.Import(temp_file) new_stl.WriteStl(temp_file) cad.Import(temp_file)
def MakeCuboidSection(self, index, num, box, margin): section_width = (box.MaxX() - box.MinX()) / num minx = box.MinX() + section_width * index miny = box.MinY() - margin minz = box.MinZ() - margin maxx = box.MinX() + section_width * (index + 1) maxy = box.MaxY() + margin maxz = box.MaxZ() + margin if index == 0: minx -= margin if index == num - 1: maxx += margin stl = geom.Stl() stl.Add(geom.Point3D(minx, miny, minz), geom.Point3D(maxx, miny, minz), geom.Point3D(maxx, miny, maxz)) stl.Add(geom.Point3D(minx, miny, minz), geom.Point3D(maxx, miny, maxz), geom.Point3D(minx, miny, maxz)) stl.Add(geom.Point3D(maxx, miny, minz), geom.Point3D(maxx, maxy, minz), geom.Point3D(maxx, maxy, maxz)) stl.Add(geom.Point3D(maxx, miny, minz), geom.Point3D(maxx, maxy, maxz), geom.Point3D(maxx, miny, maxz)) stl.Add(geom.Point3D(maxx, maxy, minz), geom.Point3D(minx, maxy, minz), geom.Point3D(minx, maxy, maxz)) stl.Add(geom.Point3D(maxx, maxy, minz), geom.Point3D(minx, maxy, maxz), geom.Point3D(maxx, maxy, maxz)) stl.Add(geom.Point3D(minx, maxy, minz), geom.Point3D(minx, miny, minz), geom.Point3D(minx, miny, maxz)) stl.Add(geom.Point3D(minx, maxy, minz), geom.Point3D(minx, miny, maxz), geom.Point3D(minx, maxy, maxz)) stl.Add(geom.Point3D(minx, miny, maxz), geom.Point3D(maxx, miny, maxz), geom.Point3D(maxx, maxy, maxz)) stl.Add(geom.Point3D(minx, miny, maxz), geom.Point3D(maxx, maxy, maxz), geom.Point3D(minx, maxy, maxz)) stl.Add(geom.Point3D(maxx, miny, minz), geom.Point3D(minx, miny, minz), geom.Point3D(maxx, maxy, minz)) stl.Add(geom.Point3D(maxx, maxy, minz), geom.Point3D(minx, miny, minz), geom.Point3D(minx, maxy, minz)) return stl
def DrawSection(self, span): if drawing_sketches: global stl_to_add_to stl_to_add_to = geom.Stl() xmax = self.curves[1].LastVertex().p.x if xmax < 0.001: return fraction0 = span.p.x / xmax fraction1 = span.v.p.x / xmax pts0 = self.GetOrderedSectionPoints(fraction0) if pts0 == None: return pts1 = self.GetOrderedSectionPoints(fraction1) if pts1 == None: return prev_p0 = None prev_p1 = None if drawing_sketches: mirror = False else: mirror = self.values['mirror'] for p0, p1 in zip(pts0, pts1): DrawTrianglesBetweenPoints(prev_p0, prev_p1, p0, p1, mirror) prev_p0 = p0 prev_p1 = p1 if drawing_sketches: if section_index != 7: return surface = stl_to_add_to.GetFlattenedSurface() outline = surface.Shadow(geom.Matrix(), True) outline.Offset(-2.0) curves = surface.GetTrianglesAsCurveList() area_fp = tempfile.gettempdir() + '/area.dxf' for curve in curves: outline.Append(curve) outline.WriteDxf(area_fp) cad.Import(area_fp)
def MakeExtrudedAreaSolid(self, pattern, minz, maxz): stl = geom.Stl() for curve in pattern.GetCurves(): if math.fabs(curve.GetArea()) > 1.0: spans = curve.GetSpans() pts = [] for span in spans: stl.Add(geom.Point3D(span.p.x, span.p.y, minz), geom.Point3D(span.v.p.x, span.v.p.y, minz), geom.Point3D(span.v.p.x, span.v.p.y, maxz)) stl.Add(geom.Point3D(span.p.x, span.p.y, minz), geom.Point3D(span.v.p.x, span.v.p.y, maxz), geom.Point3D(span.p.x, span.p.y, maxz)) pts.append(span.p) for i in range(2, len(pts)): stl.Add(geom.Point3D(pts[i].x, pts[i].y, maxz), geom.Point3D(pts[0].x, pts[0].y, maxz), geom.Point3D(pts[i - 1].x, pts[i - 1].y, maxz)) stl.Add(geom.Point3D(pts[0].x, pts[0].y, minz), geom.Point3D(pts[i].x, pts[i].y, minz), geom.Point3D(pts[i - 1].x, pts[i - 1].y, minz)) return stl
def DrawSection(self, span): if drawing_mode == DRAWING_MODE_SKETCHES: global stl_to_add_to stl_to_add_to = geom.Stl() perim = self.curves[1].Perim() if perim < 0.001: return fraction0 = self.curves[1].PointToPerim(span.p) / perim fraction1 = self.curves[1].PointToPerim(span.v.p) / perim pts0 = self.GetOrderedSectionPoints(fraction0) if pts0 == None: return pts1 = self.GetOrderedSectionPoints(fraction1) if pts1 == None: return prev_p0 = None prev_p1 = None if drawing_mode == DRAWING_MODE_SKETCHES: mirror = False else: mirror = self.mirror for p0, p1 in zip(pts0, pts1): self.DrawTrianglesBetweenPoints(prev_p0, prev_p1, p0, p1, mirror) prev_p0 = p0 prev_p1 = p1 if drawing_mode == DRAWING_MODE_SKETCHES: if section_index != 7: return surface = stl_to_add_to.GetFlattenedSurface() outline = surface.Shadow(geom.Matrix(), True) outline.Offset(-2.0) curves = surface.GetTrianglesAsCurveList() area_fp = tempfile.gettempdir() + '/area.dxf' for curve in curves: outline.Append(curve) outline.WriteDxf(area_fp) cad.Import(area_fp)