def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] point1 = inp point1[direction] = point0[direction] if (point1[direction-1] == point0[direction-1] or point1[direction-2] == point0[direction-2]): raise InvalidInputException points = [] # add two other corners: for i in range(3): if i != direction: point = point0[:] point[i] = point1[i] points.append(point) points.insert(1, point0) points.insert(3, point1) builder = BRepBuilderAPI.BRepBuilderAPI_MakePolygon() for pnt in points: builder.Add(gp.gp_Pnt(*pnt)) builder.Build() builder.Close() polygon = builder.Wire() face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(polygon).Face() self._final = [face] return self._final
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] point1 = inp # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == point1: raise InvalidInputException dirvec = vec(0, 0, 0) dirvec[direction] = 1 axis = gp.gp_Ax2(point0, dirvec.to_gp_Dir()) d = point0 - inp d[direction] = 0 dist = d.length() a = Geom.Geom_Circle(axis, dist).GetHandle() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() c = BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire() d = BRepBuilderAPI.BRepBuilderAPI_MakeFace(c).Face() self._final = [d] return self._final
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: center = self.previous_data[0] radius = (center - inp).length() if not radius: raise InvalidInputException self._final = [BRepPrimAPI_MakeSphere(center, radius).Solid()] return self._final
def make_wire(listOfPoints, close=False): vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p)) for p in listOfPoints] edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex()) for v1,v2 in pairs(vertices)] if close: edges.append(BRepBuilderAPI.BRepBuilderAPI_MakeEdge(vertices[-1].Vertex(), vertices[0].Vertex())) wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) return toshape(wire)
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == inp: raise InvalidInputException a = GC.GC_MakeSegment(inp, point0).Value() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() self._final = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()] return self._final
def preview(self, inp, direction): if self.step == 0: self.previous_data = [inp] return [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(inp).Vertex()] elif self.step == 1: point0 = self.previous_data[0] # checking if the previous points are identical: This is necessary # before continuing in order to avoid a crash on Windows if point0 == inp: raise InvalidInputException point1 = inp dir_ = point1 - point0 len = dir_.length() p0 = point0 + 1000/len * dir_ p1 = point0 - 1000/len * dir_ a = GC.GC_MakeSegment(p0.to_gp_Pnt(), p1.to_gp_Pnt()).Value() b = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(a).Edge() self._final = [BRepBuilderAPI.BRepBuilderAPI_MakeWire(b).Wire()] return self._final
from OCC import BRepBuilderAPI, gp, STEPControl from itertools import izip, tee def pairs(itr): a,b = tee(itr) b.next() return izip(a,b) points = [(0,0,0), (1,1,1), (0,0,-2), (0,2,0)] vertices = [BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p)) for p in points] #print "verts", vertices #edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex()) # for v1,v2 in pairs(vertices)] v=vertices edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v[i].Vertex(),v[j].Vertex()) for i,j, in [(0,1),(0,2),(0,3)] ] #print "edges", edges wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge()) print wire step_export = STEPControl.STEPControl_Writer()
def MakeVertex(pt): vt = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*pt)) #print "make vertex", pt, vt return vt
def make_vertex(pnt): "make a vertex from a single point" s = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(pnt) s.Build() return s.Shape()
def MakeVertex(pt): bd = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*pt)) return bd
from itertools import izip, tee from OCC import BRepBuilderAPI, gp, STEPControl def pairs(itr): a, b = tee(itr) b.next() return izip(a, b) points = [(0, 0, 0), (1, 1, 1), (0, 0, -2), (0, 2, 0)] vertices = [ BRepBuilderAPI.BRepBuilderAPI_MakeVertex(gp.gp_Pnt(*p)) for p in points ] # print "verts", vertices # edges = [BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v1.Vertex(),v2.Vertex()) # for v1,v2 in pairs(vertices)] v = vertices edges = [ BRepBuilderAPI.BRepBuilderAPI_MakeEdge(v[i].Vertex(), v[j].Vertex()) for i, j, in [(0, 1), (0, 2), (0, 3)] ] # print "edges", edges wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire() for e in edges: wire.Add(e.Edge())
def preview(self, input_pnt, direction): assert self.step == 0 preview = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(input_pnt).Vertex() self._final = [preview] return self._final