Advertisement
Guest User

Untitled

a guest
Mar 27th, 2021
1,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 16.49 KB | None | 0 0
  1. # ##### BEGIN LICENSE BLOCK #####
  2. #
  3. #  Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
  4. #
  5. #  This work is licensed under the Creative Commons
  6. #  Attribution-NonCommercial-NoDerivatives 4.0 International License.
  7. #
  8. #  To view a copy of this license,
  9. #  visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
  10. #
  11. # ##### END LICENSE BLOCK #####
  12.  
  13. bl_info = {
  14.     "name": "Text Tool",
  15.     "author": "Darkfall",
  16.     "version": (1, 3),
  17.     "blender": (2, 80, 0),
  18.     "location": "View3D > UI > Text Tool Tab",
  19.     "description": "Adds a new Text Object with user defined properties, Typewriter / Scrolling Text Animation, Radial Curve tool",
  20.     "warning": "",
  21.     "wiki_url": "",
  22.     "category": "Add Text",
  23. }
  24.  
  25. import bpy
  26. from bpy.types import (Panel, Operator)
  27.  
  28.  
  29. class OBJECT_PT_TextTool(Panel):
  30.     bl_label = " "
  31.     bl_idname = "OBJECT_PT_texttool"
  32.     bl_space_type = 'VIEW_3D'
  33.     bl_region_type = 'UI'
  34.     bl_category = "Text Tool"
  35.    
  36.     def draw_header(self, context):
  37.         layout = self.layout
  38.         row = layout.row()
  39.         row.label(text="Text Tool", icon= 'EVENT_T')
  40.    
  41.  
  42.     def draw(self, context):
  43.         layout = self.layout
  44.  
  45.        
  46.         layout.label(text= "Click the button to add text to")
  47.         layout.label(text= "the 3D View.")
  48.        
  49.        
  50.         row = layout.split(factor= 0.45)
  51.         row.label(text= "")
  52.         row.operator("wm.textopbasic", text= "Text Tool", icon= 'OUTLINER_OB_FONT')
  53.        
  54.         row = layout.split(factor= 0.45)
  55.         row.label(text= "")
  56.         row.operator("wm.textopcurveradial", text= "Radial Curve", icon= 'CURVE_BEZCIRCLE')
  57.        
  58.         row = layout.row()
  59.         row.operator("wm.textopcurveradialborder", text= "Radial Border Tool", icon= 'CURVE_NCIRCLE')
  60.        
  61.        
  62.        
  63.  
  64.  
  65.  
  66.  
  67.  
  68. class OBJECT_PT_Spacing(Panel):
  69.     bl_label = "Spacing"
  70.     bl_idname = "OBJECT_PT_spacing"
  71.     bl_space_type = 'VIEW_3D'
  72.     bl_region_type = 'UI'
  73.     bl_category = "Text Tool"
  74.     bl_parentid = "OBJECT_PT_texttool"
  75.     bl_options = {"DEFAULT_CLOSED"}
  76.    
  77.    
  78.     @classmethod
  79.     def poll(cls, context):
  80.         return (context.object != None)
  81.    
  82.     def draw(self, context):
  83.         layout = self.layout
  84.         text = context.object.data
  85.        
  86.        
  87.        
  88.         row = layout.row()
  89.         row.label(text= "Set the Spacing Options")
  90.        
  91.        
  92.         row = layout.row()
  93.         row = layout.split(factor= 0.45)
  94.         row.label(text= "Offset X")
  95.         row.prop(text, "offset_x", text= "")
  96.        
  97.         row = layout.split(factor= 0.45)
  98.         row.label(text= "           Y")
  99.         row.prop(text, "offset_y", text= "")
  100.        
  101.         row = layout.row()
  102.        
  103.         row = layout.split(factor= 0.45)
  104.         row.label(text= "Character:")
  105.         row.prop(text, "space_character", text= "")
  106.  
  107.         row = layout.split(factor= 0.45)
  108.         row.label(text= "Word:")
  109.         row.prop(text, "space_word", text= "")
  110.        
  111.         row = layout.split(factor= 0.45)
  112.         row.label(text= "Line:")
  113.         row.prop(text, "space_line", text= "")
  114.        
  115.  
  116.  
  117. class OBJECT_PT_Animations(Panel):
  118.     bl_label = "Animations"
  119.     bl_idname = "OBJECT_PT_Animation"
  120.     bl_space_type = 'VIEW_3D'
  121.     bl_region_type = 'UI'
  122.     bl_category = "Text Tool"
  123.     bl_parentid = "OBJECT_PT_texttool"
  124.     bl_options = {"DEFAULT_CLOSED"}
  125.  
  126.    
  127.     def draw(self, context):
  128.         layout = self.layout
  129.        
  130.         layout.separator(factor=1)
  131.         layout.label(text= "Select your Text then add an")
  132.         layout.label(text= "Animated Effect.")
  133.         layout.separator(factor=1)
  134.         layout.operator("wm.textoptypewriter", text= "Typewriter / Scrolling Text", icon= 'TRACKING_FORWARDS_SINGLE')
  135.        
  136.        
  137.            
  138.  
  139.  
  140.  
  141. class WM_OT_textOpBasic(Operator):
  142.     """Open the Text Tool Dialog Box"""
  143.     bl_idname = "wm.textopbasic"
  144.     bl_label = "                            Text Tool Operator"
  145.    
  146.  
  147.    
  148.     text : bpy.props.StringProperty(name="", default="")
  149.     scale : bpy.props.FloatProperty(name= "", default= 1)
  150.     rotation : bpy.props.BoolProperty(name= "Orientation", default= False)
  151.     center : bpy.props.BoolProperty(name= "Alignment", default= False)
  152.     extrude : bpy.props.BoolProperty(name= "Extrude", default= False)
  153.     extrude_amount : bpy.props.FloatProperty(name= "Extrude Amount", default= 0.06)
  154.     italic : bpy.props.BoolProperty(name= "Auto Italic", default = False)
  155.     options : bpy.props.BoolProperty(name= "Options", default = False)
  156.    
  157.     def invoke(self, context, event):
  158.         wm = context.window_manager
  159.         return wm.invoke_props_dialog(self)
  160.    
  161.        
  162.     def draw(self, context):
  163.         layout = self.layout
  164.         layout.separator(factor= 1)
  165.        
  166.         row = layout.row()
  167.         row.label(text= "Enter Text:", icon = 'FILE_TEXT')
  168.         row.prop(self, "text")
  169.        
  170.         row = layout.row()
  171.         row.label(text= "Scale:", icon = 'EMPTY_ARROWS')
  172.         row.prop(self, "scale")
  173.        
  174.         layout.separator(factor= 1)
  175.        
  176.         box = layout.box()
  177.        
  178.         row = box.row()
  179.         row.prop(self, "options")
  180.         if self.options == True:
  181.        
  182.             row = box.row()
  183.             row = box.row()
  184.             row.prop(self, "italic")
  185.             if self.italic == True:
  186.                 row.label(text= "Italic: Enabled", icon = 'ITALIC')
  187.             else:
  188.                 row.label(text= "Italic: Not Enabled", icon = 'DRIVER_DISTANCE')
  189.                    
  190.             row = box.row()
  191.             row.prop(self, "rotation")
  192.             if self.rotation == True:
  193.                 row.label(text= "Orientation: Z UP", icon= 'EMPTY_SINGLE_ARROW')
  194.             else:
  195.                 row.label(text= "Orientation: Default", icon= 'ARROW_LEFTRIGHT')
  196.                    
  197.            
  198.            
  199.             row = box.row()
  200.             row.prop(self, "center")
  201.             if self.center == True:
  202.                 row.label(text= "Alignment: Center", icon= 'ALIGN_CENTER')
  203.             else:
  204.                 row.label(text= "Alignment: Default", icon= 'ALIGN_LEFT')
  205.            
  206.            
  207.            
  208.             row = box.row()
  209.             row.prop(self, "extrude")
  210.             if self.extrude == True:
  211.                 row.prop(self, "extrude_amount")
  212.            
  213.         layout.separator(factor= 1)    
  214.            
  215.        
  216.  
  217.     def execute(self, context):
  218.        
  219.         t = self.text
  220.         s = self.scale
  221.         c = self.center
  222.         e = self.extrude
  223.         ea = self.extrude_amount
  224.         r = self.rotation
  225.        
  226.         bpy.ops.object.text_add(enter_editmode=True)
  227.         bpy.ops.font.delete(type='PREVIOUS_WORD')
  228.         bpy.ops.font.text_insert(text= t)
  229.         bpy.ops.object.editmode_toggle()
  230.         bpy.context.object.data.size = s
  231.         if r == True:
  232.             bpy.context.object.rotation_euler[0] = 1.5708    
  233.         if e == True:
  234.             bpy.context.object.data.extrude = ea
  235.         if c == True:
  236.             bpy.context.object.data.align_x = 'CENTER'
  237.             bpy.context.object.data.align_y = 'CENTER'
  238.            
  239.         if self.italic == True:
  240.             bpy.context.object.data.shear = 0.38
  241.        
  242.         bpy.context.object.name = self.text + " : (font)"    
  243.    
  244.         return {'FINISHED'}
  245.  
  246.    
  247.  
  248.  
  249.  
  250. class WM_OT_textOpCurve_Radial(Operator):
  251.     """Open the Curve Text Tool Dialog Box"""
  252.     bl_idname = "wm.textopcurveradial"
  253.     bl_label = "                 Text Tool Operator (Radial Curve)"
  254.    
  255.  
  256.    
  257.     text : bpy.props.StringProperty(name="", default="")
  258.     scale : bpy.props.FloatProperty(name= "", default= 1)
  259.     rotation : bpy.props.BoolProperty(name= "Orientation", default= False)
  260.     extrude : bpy.props.BoolProperty(name= "Extrude", default= False)
  261.     extrude_amount : bpy.props.FloatProperty(name= "Extrude Amount", default= 0.06)
  262.     flip : bpy.props.BoolProperty(name= "Text Position", default= False)
  263.     options : bpy.props.BoolProperty(name= "Options", default = False)
  264.    
  265.     def invoke(self, context, event):
  266.         wm = context.window_manager
  267.         return wm.invoke_props_dialog(self)
  268.    
  269.        
  270.     def draw(self, context):
  271.         layout = self.layout
  272.         layout.separator(factor= 1)
  273.        
  274.         row = layout.row()
  275.         row.label(text= "Enter Text:", icon = 'FILE_TEXT')
  276.         row.prop(self, "text")
  277.        
  278.         row = layout.row()
  279.         row.label(text= "Scale:", icon = 'EMPTY_ARROWS')
  280.         row.prop(self, "scale")
  281.        
  282.         layout.separator(factor= 1)
  283.        
  284.         box = layout.box()
  285.         row = box.row()
  286.         row.prop(self, "options")
  287.         if self.options == True:
  288.             row = box.row()
  289.             row = box.row()
  290.             row.prop(self, "flip")
  291.             if self.flip == True:
  292.                 row.label(text= "Text on Bottom", icon= 'MOD_CURVE')
  293.             else:
  294.                 row.label(text= "Text on Top", icon= 'SPHERECURVE')
  295.                    
  296.            
  297.            
  298.            
  299.             row = box.row()
  300.             row.prop(self, "extrude")
  301.             if self.extrude == True:
  302.                 row.prop(self, "extrude_amount")
  303.            
  304.         layout.separator(factor= 1)    
  305.            
  306.        
  307.  
  308.     def execute(self, context):
  309.        
  310.         t = self.text
  311.         s = self.scale
  312.         e = self.extrude
  313.         ea = self.extrude_amount
  314.         f = self.flip
  315.        
  316.         bpy.ops.curve.primitive_bezier_circle_add()
  317.         obj1 = bpy.context.object
  318.         obj1.name= "Radial Rotation Curve"
  319.         obj1.scale[0] = 3.5
  320.         obj1.scale[1] = 3.5
  321.         obj1.scale[2] = 3.5
  322.        
  323.        
  324.  
  325.        
  326.         bpy.ops.object.text_add(enter_editmode=True)
  327.         font1 = bpy.context.object
  328.         bpy.ops.font.delete(type='PREVIOUS_WORD')
  329.         bpy.ops.font.text_insert(text= t)
  330.         bpy.ops.object.editmode_toggle()
  331.         bpy.context.object.data.size = s
  332.        
  333.  
  334.            
  335.            
  336.  
  337.  
  338.        
  339.            
  340.         if e == True:
  341.             bpy.context.object.data.extrude = ea
  342.            
  343.        
  344.         bpy.context.object.name = self.text + " : (font)"
  345.        
  346.         bpy.ops.object.modifier_add(type='CURVE')
  347.         bpy.context.object.modifiers["Curve"].object = obj1
  348.            
  349.        
  350.         if f == True:
  351.             bpy.context.object.data.offset_x = -1.48
  352.             bpy.context.object.data.offset_y = -0.98
  353.             bpy.context.object.rotation_euler[0] = 3.14159
  354.             bpy.context.object.rotation_euler[1] = 3.14159
  355.  
  356.  
  357.  
  358.         else:
  359.             bpy.context.object.data.offset_x = 9.48
  360.             bpy.context.object.data.offset_y = 0.37
  361.    
  362.        
  363.        
  364.  
  365.         return {'FINISHED'}
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372. class WM_OT_textOpCurve_Radial_Border(Operator):
  373.     """Open the Curve Text Tool Dialog Box"""
  374.     bl_idname = "wm.textopcurveradialborder"
  375.     bl_label = "                 Text Tool Operator (Radial Border)"
  376.    
  377.  
  378.     preset_enum : bpy.props.EnumProperty(
  379.         name="",
  380.         description="Select a Style to be used.",
  381.         items=[ ('OP1', "Solid Line ________", ""),
  382.                 ('OP2', "Dots .........", ""),
  383.                 ('OP3', "Arrows  ^^^^^^^", ""),
  384.                 ('OP4', "Circles  OoOoOoOoOoOo", ""),
  385.                ]
  386.         )
  387.        
  388.     text : bpy.props.StringProperty(name = "")
  389.     use_custom : bpy.props.BoolProperty(name = "Use Custom Character")
  390.        
  391.    
  392.    
  393.    
  394.     def invoke(self, context, event):
  395.         wm = context.window_manager
  396.         return wm.invoke_props_dialog(self)
  397.    
  398.        
  399.     def draw(self, context):
  400.         layout = self.layout
  401.         layout.separator(factor= 1)
  402.        
  403.         row = layout.row()
  404.         row.label(text= "Select Border Style:", icon = 'RESTRICT_SELECT_OFF')
  405.         row = layout.row()
  406.         if self.use_custom != True:
  407.             row.prop(self, "preset_enum")  
  408.        
  409.         layout.separator(factor= 1)
  410.        
  411.         box = layout.box()
  412.         row = box.row()
  413.         row.prop(self, "use_custom")
  414.         if self.use_custom == True:
  415.             row = box.row()
  416.             row.label(text= "Enter Character:")
  417.             row.prop(self, "text")
  418.             row = box.row()
  419.  
  420.        
  421.            
  422.            
  423.         layout.separator(factor= 1)    
  424.            
  425.        
  426.  
  427.     def execute(self, context):
  428.        
  429.        
  430.         bpy.ops.curve.primitive_bezier_circle_add()
  431.         obj = bpy.context.object
  432.         obj.name= "Radial Rotation Curve"
  433.         obj.scale[0] = 3.5
  434.         obj.scale[1] = 3.5
  435.         obj.scale[2] = 3.5
  436.        
  437.        
  438.  
  439.        
  440.         bpy.ops.object.text_add(enter_editmode=True)
  441.         font = bpy.context.object
  442.         bpy.ops.font.delete(type='PREVIOUS_WORD')
  443.        
  444.         if self.use_custom == True:
  445.             bpy.ops.font.text_insert(text= self.text)
  446.            
  447.         else:    
  448.             if self.preset_enum == 'OP1':
  449.                 bpy.ops.font.text_insert(text= "_")
  450.                 font.data.offset_y = -7.23
  451.  
  452.                
  453.                
  454.             if self.preset_enum == 'OP2':
  455.                 bpy.ops.font.text_insert(text= ".")
  456.                
  457.  
  458.                 bpy.context.object.data.offset_y = -7.23
  459.  
  460.      
  461.             if self.preset_enum == 'OP3':
  462.                 bpy.ops.font.text_insert(text= "^")
  463.                 bpy.context.object.data.space_character = 0.907
  464.                 bpy.context.object.data.offset_y = -0.2
  465.            
  466.             if self.preset_enum == 'OP4':
  467.                 bpy.ops.font.text_insert(text= "Oo")
  468.                 bpy.context.object.data.space_character = 0.907
  469.                 bpy.context.object.data.offset_y = -0.2
  470.                 bpy.context.object.data.size = 0.3985
  471.            
  472.            
  473.  
  474.        
  475.        
  476.         bpy.ops.object.editmode_toggle()
  477.        
  478.        
  479.  
  480.            
  481.        
  482.         bpy.ops.object.modifier_add(type='ARRAY')
  483.         bpy.context.object.modifiers["Array"].fit_type = 'FIT_CURVE'
  484.  
  485.         bpy.context.object.modifiers["Array"].curve = obj
  486.  
  487.  
  488.        
  489.         bpy.ops.object.modifier_add(type='CURVE')
  490.         bpy.context.object.modifiers["Curve"].object = obj
  491.        
  492.         if self.preset_enum == 'OP2':
  493.            
  494.             bpy.context.object.modifiers["Array"].relative_offset_displace[0] = 1.696
  495.            
  496.             bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
  497.  
  498.  
  499.         return {'FINISHED'}
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517. class WM_OT_textOpTypewriter(Operator):
  518.     """Open the Typewriter / Scrolling Text Dialog Box. Note: The Text will be Converted to a Mesh"""
  519.     bl_idname = "wm.textoptypewriter"
  520.     bl_label = "             Text Tool Operator (Typewriter Effect)"
  521.    
  522.  
  523.    
  524.    
  525.     start_frame : bpy.props.IntProperty(name= "", default= 1)
  526.     anim_duration : bpy.props.IntProperty(name= "", default= 25)
  527.    
  528.    
  529.    
  530.    
  531.    
  532.     def invoke(self, context, event):
  533.         wm = context.window_manager
  534.         return wm.invoke_props_dialog(self)
  535.    
  536.        
  537.     def draw(self, context):
  538.         layout = self.layout
  539.         layout.separator(factor= 1)
  540.        
  541.        
  542.         row = layout.row()
  543.         row.label(text= "Start Frame:", icon = 'FRAME_NEXT')
  544.         row.prop(self, "start_frame")
  545.        
  546.         row = layout.row()
  547.         row.label(text= "Duration (frames):", icon = 'TIME')
  548.         row.prop(self, "anim_duration")
  549.        
  550.         layout.separator(factor= 2)
  551.                    
  552.        
  553.  
  554.     def execute(self, context):  
  555.            
  556.         obj = bpy.context.object    
  557.        
  558.         bpy.ops.object.convert(target='MESH')
  559.         bpy.ops.object.modifier_add(type='BUILD')
  560.         obj.modifiers["Build"].frame_start = self.start_frame
  561.         obj.modifiers["Build"].frame_duration = self.anim_duration
  562.  
  563.         bpy.ops.object.editmode_toggle()
  564.         bpy.ops.mesh.select_all(action='SELECT')
  565.         bpy.ops.mesh.sort_elements(type='VIEW_XAXIS', elements={'FACE'})
  566.         bpy.ops.object.editmode_toggle()
  567.        
  568.         return {'FINISHED'}
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578. classes = [OBJECT_PT_TextTool, OBJECT_PT_Animations, OBJECT_PT_Spacing, WM_OT_textOpBasic, WM_OT_textOpCurve_Radial, WM_OT_textOpTypewriter, WM_OT_textOpCurve_Radial_Border]
  579.  
  580.  
  581.  
  582. def register():
  583.     for cls in classes:
  584.         bpy.utils.register_class(cls)
  585.  
  586. def unregister():
  587.     for cls in classes:
  588.         bpy.utils.unregister_class(cls)
  589.  
  590.  
  591.  
  592. if __name__ == "__main__":
  593.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement