SI50

mesh.primitive_sedia_add

May 18th, 2021 (edited)
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. import bpy
  2. from math import pi
  3.  
  4.  
  5. class MESH_OT_sedia(bpy.types.Operator):
  6.     """Aggiunge una sedia alla scena"""
  7.     bl_idname = "mesh.primitive_sedia_add"
  8.     bl_label ="Sedia"
  9.     bl_options = {'REGISTER', 'UNDO'}
  10.    
  11.  
  12.     lun: bpy.props.FloatProperty(
  13.         name="Lato seduta",
  14.         default=.5,
  15.         unit='LENGTH',
  16.         min=.3,
  17.         soft_max=.6,
  18.     )
  19.     spe: bpy.props.FloatProperty(
  20.         name="Spessore",
  21.         default=.05,
  22.         unit='LENGTH',
  23.         min=.01,
  24.         max=.1,
  25.     )
  26.     alt: bpy.props.FloatProperty(
  27.         name="Altezza",
  28.         default=.5,
  29.         unit='LENGTH',
  30.         min=.4,
  31.         max=.6,
  32.     )
  33.     dia: bpy.props.FloatProperty(
  34.         name="Diametro",
  35.         default=.05,
  36.         unit='LENGTH',
  37.         min=.04,
  38.         max=.1,
  39.     )
  40.     gap: bpy.props.FloatProperty(
  41.         name="Gap Gamba-seduta",
  42.         default=.02,
  43.         unit='LENGTH',
  44.         min=0,
  45.         max=.1,
  46.     )
  47.     loc: bpy.props.FloatVectorProperty(
  48.         name="Posizione",
  49.         default=(0,0),
  50.         size=2,
  51.         unit='LENGTH',
  52.     )
  53.     rot: bpy.props.FloatProperty(
  54.         name="Rotazione",
  55.         default=0,
  56.         unit='ROTATION',
  57.     )
  58.    
  59.     def execute(self,context):
  60.         lun=self.lun
  61.         spe=self.spe
  62.         alt=self.alt
  63.         dia=self.dia
  64.         gap=self.gap
  65.         loc=self.loc
  66.         rot=self.rot
  67.  
  68.  
  69.         bpy.ops.mesh.primitive_cube_add(size=2,location=(loc[0],loc[1],alt+spe/2),scale=(lun,lun,spe),rotation=(0,0,rot))
  70.         seduta=bpy.context.object
  71.         bpy.ops.mesh.primitive_cube_add(size=2,location=(0+lun/2-spe/2,0,lun/2+spe/2),scale=(spe,lun,lun))
  72.         spalliera=bpy.context.object
  73.         spalliera.parent=seduta
  74.         loc_x=lun/2-dia/2-gap
  75.         loc_y=lun/2-dia/2-gap
  76.         bpy.ops.mesh.primitive_cylinder_add(vertices=64,radius=dia/2,depth=alt,location=(loc_x,loc_y,-alt/2-spe/2))
  77.         gambo1=bpy.context.object
  78.         gambo1.parent=seduta
  79.         bpy.ops.mesh.primitive_cylinder_add(vertices=64,radius=dia/2,depth=alt,location=(loc_x,-loc_y,-alt/2-spe/2))
  80.         gambo2=bpy.context.object
  81.         gambo2.parent=seduta
  82.         bpy.ops.mesh.primitive_cylinder_add(vertices=64,radius=dia/2,depth=alt,location=(-loc_x,loc_y,-alt/2-spe/2))
  83.         gambo3=bpy.context.object
  84.         gambo3.parent=seduta
  85.         bpy.ops.mesh.primitive_cylinder_add(vertices=64,radius=dia/2,depth=alt,location=(-loc_x,-loc_y,-alt/2-spe/2))
  86.         gambo4=bpy.context.object
  87.         gambo4.parent=seduta
  88.         return {'FINISHED'}
  89.        
  90.        
  91. def register():
  92.     bpy.utils.register_class(MESH_OT_sedia)
  93.  
  94. def unregister():
  95.     bpy.utils.unregister_class(MESH_OT_sedia)
  96.  
  97. if __name__ == '__main__':
  98.  register()
Add Comment
Please, Sign In to add comment