Simple Constructs

Tube

Now test function to make a tube generated along the z-axis

def tube(r, w, h, a ):
   '''
   Generate a (partial) tube with
   r  outside radius
   w  wall thickness
   h  length (height)
   a  angle of sweep (360 is full circle)
   e.g.
   b = tube(6, 2, 10, 90)
   '''
   b = Part.makeCylinder(r, h, Vector(0,0,0), Vector(0,0,1), a)
   b = b.cut(Part.makeCylinder(r-w, h, Vector(0,0,0), Vector(0,0,1), a))

   return(b)

Outside 6, wall 2, length 10, angle of sweep 360 (round tube)

tb = tube( 6, 2, 10, 360)
tb2 = tb.copy()
tb2.rotate(o, z, 30)
testEqual(tb,  tb2)   # symmetric normal to z-axis
tb2.rotate(o, x, 30)
testNotEqual(tb,  tb2)  # not symmetric normal to x-axis
TEST generate a tube by revolving a rectangle (vs cutting two cylindars above)
# edge1 = Part.makeLine((0,0,0), (10,0,0))
rect = Part.makePolygon([
     Vector(4,0,0), Vector(6,0,0),Vector(6,0,10),Vector(4,0,10), Vector(4,0,0)])

rectFace = Part.makeFilledFace(rect.Edges)

tb3 = rectFace.revolve(o, z, 360)
# Part.show(tb3)
testEqual(tb,  tb3)
# outside 6,  wall 2, length 10, angle of sweep  90 (1/4 round)

tb = tube( 6, 2, 10, 90)
testEqual(tb,  tube(6, 2, 10, 90))
testNotEqual(tb, tube(6, 2, 10, 80))
line = Part.LineSegment(o, Vector(10,0,0))
edge = line.toShape()

if edge.Length != 10.0 : print('bad')

if edge.CenterOfMass != Vector (5, 0, 0) : print('bad')


edge1 = Part.makeLine((0,0,0), (10,0,0))
edge2 = Part.makeLine((10,0,0), (10,10,0))
wire1 = Part.Wire([edge1,edge2])
edge3 = Part.makeLine((10,10,0), (0,10,0))
edge4 = Part.makeLine((0,10,0), (0,0,0))
wire2 = Part.Wire([edge3,edge4])
wire3 = Part.Wire([wire1,wire2])
wire3.Edges

#Part.show(wire3)

Needle

# main shaft

a = Part.makeCylinder(1.0, 55, Vector(0, 0, 0), Vector(1, 0, 0), 360) a = a.fuse(Part.makeSphere(1.0)) # Part.show(a)

# bent end shaft and point

b = Part.makeCylinder(1.0, 5, Vector(0, 0, 0), Vector(0, 0, 1), 360) b1 = Part.makeCone(1.0, 0.3, 4) b1.translate(Vector(0, 0, 5)) b2 = Part.makeSphere(0.3) b2.translate(Vector(0, 0, 5+4)) b = b.fuse([b1, b2]) b.rotate(Vector(0, 0, 0), Vector(0.5, 1, 0), 90) b.translate(Vector(55, 0, 0)) # Part.show(b)

# fill between shafts

c = Part.makeSphere(1.0) c.translate(Vector(55, 0, 0)) # Part.show(c)

a = a.fuse([b, c])

# Part.show(a)

# hole for thread

# center origin, X , Y radii, default orientation normal to z-axis e = Part.Ellipse(o, 5, 0.4).toShape() e.translate(Vector(6, 0, -1)) d = Part.Face(Part.Wire(e)).extrude(Vector(0, 0, 5)) #Part.show(d)

h = a.cut(d) #Part.show(h)

# smooth thread hole edges

# cannot get fillet to work with these edges #edges = [] #for e in h.Edges : # if (len(e.Vertexes) is 1) and e.Vertexes[0].Point[2] in (1.0, -1.0) : # edges.append(e) # #h = h.makeFillet(0.3, edges)

# so cut out another ellipse across the top of the hole # This leaves somewhat sharp edges #This works in Freecad, but printing is a real problem because of the long # bridge, and the sides areery narrow. Might try with a smaller nozzle. # However, even without it the edges are too small to print with 0.4mm nozzle, # or I have to make other adjustments I have not yet figured out.

# e = Part.Ellipse(Vector(0, 0, 0), 6, 0.3).toShape() # e.rotate(o, x, 90) # ceter at origin, about x-axis # e.translate(Vector(6, -2, -1)) # d = Part.Face(Part.Wire(e)).extrude(Vector(0, 5, 0)) # #Part.show(d) # h = h.cut(d) # # d.translate(Vector(0, 0, 2)) # h = h.cut(d)

#Part.show(h)

m = MeshPart.meshFromShape(Shape= h,
LinearDeflection=0.1, AngularDeflection=0.523599, Relative=False)

# why both of these ? Mesh.export([m], “needle.stl”) m.write(Filename =”needle.stl”)