from harmonic.mz.data import * from harmonic.cad.shapes import * from harmonic.cad.manager import * from harmonic.mz.manager import * from harmonic.meshGeom.math import * from MakeHelix import * class MakeSpring: # These units are MILLIMETERS (1A= 5mm at 50,000,000X) # so, 1.0 = 5mm; 0.2 = 1mm; 0.1 = 0.5mm; 0.04 = 0.2mm **layer thickness** housing_radius = 5.0 axle_radius = 1. # thickness of radial walls radial_thickness = 0.5 radial_tolerance = 0.15 # thickness of axial walls (axial means along Z-axis, probably). axial_thickness = 0.5 axial_tolerance = 0.2 # entire height of housing height = 5.75 # define spring spring_radius = 3.0 tube_radius = 0.5 # turns of spring in housing turns = 2.0 samplesPerTurn = 32 # scale factor scale_factor = 1.0 def make_spring(self): # call MakeHelix macro mh = MakeHelix() # tranxfer params mh.radius = self.spring_radius*self.scale_factor mh.height = self.height/self.turns**self.scale_factor mh.turns = self.turns mh.samplesPerTurn = self.samplesPerTurn # make the shape helix = mh.make_helix() # make the section section = CircleFromCenterRadiusShape() section.radius.setScalar(self.tube_radius*self.scale_factor) # move the section to the end of the path rot = TMat() rot.fromXRotation(90.*Geo.radPerDeg) # rotate trans = TMat() trans.translate(1., 0., 0.) # translate sweepPerSection = TMat() sweepPerSection.mul(trans, rot) section.setTransform(sweepPerSection) # do tfm # make the spring spring = GeneralPathSweepShape() spring.setName("Spring") spring.section.addNode(section) spring.path.addNode(helix) return spring def make_assembly(self): housing_radius_s = self.housing_radius * self.scale_factor axle_radius_s = self.axle_radius * self.scale_factor radial_thickness_s = self.radial_thickness * self.scale_factor axial_thickness_s = self.axial_thickness * self.scale_factor tube_radius_s = self.tube_radius * self.scale_factor height_s = self.height * self.scale_factor spring_radius_s = self.spring_radius * self.scale_factor spring = self.make_spring(); CAD.addShape(spring); pink = Clr3f(1.0, 0.5, 0.5) spring.fillColor.setAllColors(pink) # Make housing outer = CylinderFromCenterRadiusHeightShape() outer.radius.setScalar(housing_radius_s) outer.height.setScalar(height_s) outer_center = Pnt3f() outer.center.setPoint(outer_center) inner = CylinderFromCenterRadiusHeightShape() inner_radius = housing_radius_s - radial_thickness_s; inner.radius.setScalar(inner_radius) inner_center = Pnt3f(outer_center) inner_center.z += axial_thickness_s inner.center.setPoint(inner_center) inner_height = height_s - 2.0 * axial_thickness_s inner.height.setScalar(inner_height) ax_bore = CylinderFromCenterRadiusHeightShape() ax_bore_rad = axle_radius_s + self.radial_tolerance ax_bore.radius.setScalar(ax_bore_rad) bore_center = Pnt3f(outer_center) bore_center.z += -1. ax_bore.center.setPoint(bore_center) ax_bore_height = height_s + 2.0 ax_bore.height.setScalar(ax_bore_height) # add axle seat. # add spokes to distal end # now make it housing = SubtractionShape() housing.positive.addNode(outer) housing.negative.addNode(inner) housing.negative.addNode(ax_bore) # housing.negative.addNode(ax_seat) # housing.negative.addNode(spokes) CAD.addShape(housing) housing.setName("housing") outer.visibility.setBoolean(0) inner.visibility.setBoolean(0) ax_bore.visibility.setBoolean(0) # ax_seat.visibility.setBoolean(false) # spokes.visibility.setBoolean(false) MZ.modules().loadModule("harmonic.cad.manager.CAD") # how to have mz call function? # CAD.addShape(MakeSpring().make_spring()) MakeSpring().make_assembly()