Advertisement
DarkfallBlender

TextTool

Mar 9th, 2020
2,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.85 KB | None | 0 0
  1. bl_info = {
  2.     "name": "Text Tool",
  3.     "author": "Darkfall",
  4.     "version": (1, 0),
  5.     "blender": (2, 80, 0),
  6.     "location": "View3D > UI > Text Tool Tab",
  7.     "description": "Adds a new Text Object with user defined properties",
  8.     "warning": "",
  9.     "wiki_url": "",
  10.     "category": "Add Text",
  11. }
  12.  
  13. import bpy
  14.  
  15.  
  16. class OBJECT_PT_TextTool(bpy.types.Panel):
  17.     bl_label = "Text Tool"
  18.     bl_idname = "OBJECT_PT_texttool"
  19.     bl_space_type = 'VIEW_3D'
  20.     bl_region_type = 'UI'
  21.     bl_category = "Text Tool"
  22.    
  23.  
  24.     def draw(self, context):
  25.         layout = self.layout
  26.  
  27.         row = layout.row()
  28.         row = layout.row()
  29.         row.label(text= "Click the button to add text to")
  30.         row = layout.row()
  31.         row.label(text= "the 3D View.")
  32.         row = layout.row()
  33.         row = layout.row()
  34.        
  35.         row = layout.split(factor= 0.45)
  36.         row.label(text= "")
  37.         row.operator("wm.textopbasic", text= "Add Text", icon= 'OUTLINER_OB_FONT')
  38.        
  39.  
  40.  
  41.  
  42.  
  43.  
  44. class OBJECT_PT_Spacing(bpy.types.Panel):
  45.     bl_label = "Spacing"
  46.     bl_idname = "OBJECT_PT_spacing"
  47.     bl_space_type = 'VIEW_3D'
  48.     bl_region_type = 'UI'
  49.     bl_category = "Text Tool"
  50.     bl_parentid = "OBJECT_PT_texttool"
  51.     bl_options = {"DEFAULT_CLOSED"}
  52.    
  53.  
  54.     def draw(self, context):
  55.         layout = self.layout
  56.         text = context.object.data
  57.  
  58.         row = layout.row()
  59.         row.label(text= "Set the Spacing Options")
  60.        
  61.         row = layout.split(factor= 0.45)
  62.         row.label(text= "Character:")
  63.         row.prop(text, "space_character", text= "")
  64.  
  65.         row = layout.split(factor= 0.45)
  66.         row.label(text= "Word:")
  67.         row.prop(text, "space_word", text= "")
  68.        
  69.         row = layout.split(factor= 0.45)
  70.         row.label(text= "Line:")
  71.         row.prop(text, "space_line", text= "")
  72.        
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. class WM_OT_textOpBasic(bpy.types.Operator):
  89.     """Open the Text Tool Dialog Box"""
  90.     bl_idname = "wm.textopbasic"
  91.     bl_label = "                            Text Tool Operator"
  92.    
  93.  
  94.    
  95.     text : bpy.props.StringProperty(name="Enter Text", default="")
  96.     scale : bpy.props.FloatProperty(name= "Scale", default= 1)
  97.     rotation : bpy.props.BoolProperty(name= "Z up", default= False)
  98.     center : bpy.props.BoolProperty(name= "Center Origin", default= False)
  99.     extrude : bpy.props.BoolProperty(name= "Extrude", default= False)
  100.     extrude_amount : bpy.props.FloatProperty(name= "Extrude Amount", default= 0.06)
  101.    
  102.     def invoke(self, context, event):
  103.         wm = context.window_manager
  104.         return wm.invoke_props_dialog(self)
  105.    
  106.        
  107.    
  108.        
  109.  
  110.     def execute(self, context):
  111.        
  112.         t = self.text
  113.         s = self.scale
  114.         c = self.center
  115.         e = self.extrude
  116.         ea = self.extrude_amount
  117.         r = self.rotation
  118.        
  119.         bpy.ops.object.text_add(enter_editmode=True)
  120.         bpy.ops.font.delete(type='PREVIOUS_WORD')
  121.         bpy.ops.font.text_insert(text= t)
  122.         bpy.ops.object.editmode_toggle()
  123.         bpy.context.object.data.size = s
  124.        
  125.  
  126.  
  127.         if r == True:
  128.             bpy.context.object.rotation_euler[0] = 1.5708
  129.                    
  130.         if e == True:
  131.             bpy.context.object.data.extrude = ea
  132.        
  133.         if c == True:
  134.             bpy.context.object.data.align_x = 'CENTER'
  135.             bpy.context.object.data.align_y = 'CENTER'
  136.  
  137.  
  138.         return {'FINISHED'}
  139.  
  140.    
  141.  
  142.  
  143.  
  144.  
  145.  
  146. def register():
  147.     bpy.utils.register_class(OBJECT_PT_TextTool)
  148.     bpy.utils.register_class(OBJECT_PT_Spacing)
  149.     bpy.utils.register_class(WM_OT_textOpBasic)
  150.  
  151.  
  152. def unregister():
  153.     bpy.utils.unregister_class(OBJECT_PT_TextTool)
  154.     bpy.utils.unregister_class(OBJECT_PT_Spacing)
  155.     bpy.utils.unregister_class(WM_OT_textOpBasic)
  156.  
  157.  
  158. if __name__ == "__main__":
  159.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement