Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. import bpy # contains all the functionalities of Blender and it can only be
  2. # accessed from inside the Blender application
  3.  
  4.  
  5.  
  6. # This function will draw base plate
  7. def Draw_Base_Plate():
  8.  
  9.  
  10. #Added two cubes for cutting sides of base plate
  11.  
  12. bpy.ops.mesh.primitive_cube_add(radius=0.05, location=(0.175,0,0.09))
  13. bpy.ops.mesh.primitive_cube_add(radius=0.05, location=(-0.175,0,0.09))
  14.  
  15. #############################################################################################
  16.  
  17. #Adding base plate
  18. bpy.ops.mesh.primitive_cylinder_add(radius=0.15,depth=0.005, location=(0,0,0.09))
  19.  
  20. #Adding booleab difference modifier from first cube
  21.  
  22. bpy.ops.object.modifier_add(type='BOOLEAN')
  23. bpy.context.object.modifiers["Boolean"].operation = 'DIFFERENCE'
  24. bpy.context.object.modifiers["Boolean"].object = bpy.data.objects["Cube"]
  25. bpy.ops.object.modifier_apply(modifier="Boolean")
  26.  
  27.  
  28. #############################################################################################
  29.  
  30. #Adding booleab difference modifier from second cube
  31.  
  32. bpy.ops.object.modifier_add(type='BOOLEAN')
  33. bpy.context.object.modifiers["Boolean"].operation = 'DIFFERENCE'
  34. bpy.context.object.modifiers["Boolean"].object = bpy.data.objects["Cube.001"]
  35. bpy.ops.object.modifier_apply(modifier="Boolean")
  36.  
  37.  
  38. #############################################################################################
  39.  
  40. #Deselect cylinder and delete cubes
  41. bpy.ops.object.select_pattern(pattern="Cube")
  42. bpy.ops.object.select_pattern(pattern="Cube.001")
  43. bpy.data.objects['Cylinder'].select = False
  44. bpy.ops.object.delete(use_global=False)
  45.  
  46.  
  47.  
  48. #This function will draw motors and wheels
  49. def Draw_Motors_Wheels():
  50.  
  51.  
  52.  
  53. #Create first Wheel
  54.  
  55. bpy.ops.mesh.primitive_cylinder_add(radius=0.045,depth=0.01, location=(0,0,0.07))
  56. #Rotate
  57. bpy.context.object.rotation_euler[1] = 1.5708
  58. #Transalation
  59. bpy.context.object.location[0] = 0.135
  60.  
  61. #Create second wheel
  62. bpy.ops.mesh.primitive_cylinder_add(radius=0.045,depth=0.01, location=(0,0,0.07))
  63. #Rotate
  64. bpy.context.object.rotation_euler[1] = 1.5708
  65. #Transalation
  66. bpy.context.object.location[0] = -0.135
  67.  
  68. #Adding motors
  69.  
  70. bpy.ops.mesh.primitive_cylinder_add(radius=0.018,depth=0.06, location=(0.075,0,0.075))
  71. bpy.context.object.rotation_euler[1] = 1.5708
  72.  
  73. bpy.ops.mesh.primitive_cylinder_add(radius=0.018,depth=0.06, location=(-0.075,0,0.075))
  74. bpy.context.object.rotation_euler[1] = 1.5708
  75.  
  76.  
  77. #Adding motor shaft
  78. bpy.ops.mesh.primitive_cylinder_add(radius=0.006,depth=0.04, location=(0.12,0,0.075))
  79. bpy.context.object.rotation_euler[1] = 1.5708
  80.  
  81. bpy.ops.mesh.primitive_cylinder_add(radius=0.006,depth=0.04, location=(-0.12,0,0.075))
  82. bpy.context.object.rotation_euler[1] = 1.5708
  83.  
  84.  
  85. #############################################################################################
  86.  
  87. #Addubg Caster Wheel
  88.  
  89. bpy.ops.mesh.primitive_cylinder_add(radius=0.015,depth=0.05, location=(0,0.125,0.065))
  90. bpy.ops.mesh.primitive_cylinder_add(radius=0.015,depth=0.05, location=(0,-0.125,0.065))
  91.  
  92. #Adding Kinect
  93.  
  94. bpy.ops.mesh.primitive_cube_add(radius=0.04, location=(0,0,0.26))
  95.  
  96. #Draw middle plate
  97. def Draw_Middle_Plate():
  98. bpy.ops.mesh.primitive_cylinder_add(radius=0.15,depth=0.005, location=(0,0,0.22))
  99.  
  100. #Adding top plate
  101. def Draw_Top_Plate():
  102. bpy.ops.mesh.primitive_cylinder_add(radius=0.15,depth=0.005, location=(0,0,0.37))
  103.  
  104. #Adding support tubes
  105. def Draw_Support_Tubes():
  106. #Cylinders
  107. bpy.ops.mesh.primitive_cylinder_add(radius=0.007,depth=0.30, location=(0.09,0.09,0.23))
  108. bpy.ops.mesh.primitive_cylinder_add(radius=0.007,depth=0.30, location=(-0.09,0.09,0.23))
  109. bpy.ops.mesh.primitive_cylinder_add(radius=0.007,depth=0.30, location=(-0.09,-0.09,0.23))
  110. bpy.ops.mesh.primitive_cylinder_add(radius=0.007,depth=0.30, location=(0.09,-0.09,0.23))
  111.  
  112. #Exporting into STL
  113. def Save_to_STL():
  114. bpy.ops.object.select_all(action='SELECT')
  115. # bpy.ops.mesh.select_all(action='TOGGLE')
  116. bpy.ops.export_mesh.stl(check_existing=True,
  117. filepath="/home/sam/Desktop/exported.stl",
  118. filter_glob="*.stl", ascii=False, use_mesh_modifiers=True,
  119. axis_forward='Y', axis_up='Z', global_scale=1.0)
  120.  
  121.  
  122. #Main code
  123.  
  124. if __name__ == "__main__":
  125. Draw_Base_Plate()
  126. Draw_Motors_Wheels()
  127. Draw_Middle_Plate()
  128. Draw_Top_Plate()
  129. Draw_Support_Tubes()
  130. Save_to_STL()
  131.  
  132. bpy.ops.mesh.primitive_cube_add(radius=0.05, location=(0.175,0,0.09))
  133. bpy.ops.mesh.primitive_cube_add(radius=0.05, location=(-0.175,0,0.09))
  134.  
  135. bpy.context.object.modifiers["Boolean"].object = bpy.data.objects["Cube"]
  136.  
  137. def Draw_Base_Plate(scene=bpy.context.scene):
  138. #Add cube for cutting sides of base plate
  139.  
  140. bpy.ops.mesh.primitive_cube_add(radius=0.05, location=(0.175,0,0.09))
  141. cube1 = scene.objects.active
  142. # copy cube1 and link to scene (not required as example howto)
  143. '''
  144. cube2 = cube1.copy()
  145. cube2.location.x = -0.175
  146. scene.objects.link(cube2)
  147. '''
  148.  
  149. #Adding base plate
  150. bpy.ops.mesh.primitive_cylinder_add(radius=0.15,depth=0.005, location=(0,0,0.09))
  151. cyl = scene.objects.active
  152.  
  153. #Adding booleab difference modifiers
  154. for ob in [cube1, cube1]:
  155. mod = cyl.modifiers.new("FacePlateBool", type='BOOLEAN')
  156. mod.operation = 'DIFFERENCE'
  157. mod.object = ob
  158. bpy.ops.object.modifier_apply(modifier=mod.name)
  159. ob.location.x = -ob.location.x
  160.  
  161. #Deselect cylinder and delete cube
  162. cyl.select = False
  163. scene.objects.unlink(cube1)
  164. bpy.data.objects.remove(cube1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement