# Простой аддон для изменения строки меню
#Cкачать можно здесь:https://yadi.sk/d/udj-6ftsL3kfjQ
bl_info = {
"name": "Set string",
"author": "Orlov Alexander",
"version": (1, 0),
"blender": (2, 93, 0),
"location": "3D View > Set string",
"description": "Changing the menu string",
"warning": "",
"doc_url": "",
"category": "Test",
}
import bpy
from bpy.types import Operator, Panel, PropertyGroup
from bpy.utils import register_class, unregister_class
from bpy.props import BoolProperty, IntProperty, FloatProperty, EnumProperty, StringProperty, PointerProperty
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
class VarPanel123(PropertyGroup):
str1 : StringProperty (
name = 's1',
default = 'Some text'
)
# ---------------------------- Main function Основная функция вызываемая из оператора ---------
def main123(self,context):
#self.report({'ERROR'},"Проверка связи") #<---Работающий вариант
path1=context.scene.prop123
path1.str1="Hallo World !"
#self.report({'ERROR'},self.str1) #<---Работающий вариант
#Shows a message box with a specific message
ShowMessageBox("Поздравляю у нас всё получилось !") #<---Работающий вариант
#Shows a message box with a message and custom title
#ShowMessageBox("This is a message", "This is a custom title") #<---Работающий вариант
#Shows a message box with a message, custom title, and a specific icon
#ShowMessageBox("This is a message", "This is a custom title", 'ERROR') #<---Работающий вариант
# ---------------------------- Основной оператор вызываемый по нажатию кнопки ------------
class SuperLineOperator(Operator):
"""Tooltip"""
bl_idname = "scene.string_operator"
bl_label = "Set String Button"
str1 = None
def structure123(self,context):
connect333 = context.scene.prop123
self.str1 = connect333.str1
def execute(self,context):
self.structure123(context)
main123(self,context)
#self.report({'ERROR'},"Проверка связи")
return {'FINISHED'}
# ---------------------------- Panels Наше меню-------------------------------
class SuperLineMenuPanel(Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Set String 1.0"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Set String"
def draw(self, context):
layout = self.layout
connect123 = context.scene.prop123 # Connect Var and Panel
col = layout.column()
# Cycles
col.label(text="Create:")
spl = col.split(align = True)
col.prop(connect123, 'str1')
# Big super line button
layout.label(text="Сreate:")
row = layout.row()
row.scale_y = 2.0
row.operator("scene.string_operator") # Вызов оператора по нажатию кнопки
# ---------------------------- Регистрация функций и меню -------------------------------
classes123 = [
VarPanel123,
SuperLineOperator,
SuperLineMenuPanel
]
# Регистрация меню - Включить
def register():
for c123 in classes123:
register_class(c123)
bpy.types.Scene.prop123 = PointerProperty(type = VarPanel123)
# Регистрация меню - Выключить
def unregister():
for c123 in classes123:
unregister_class(c123)
#bpy.utils.register_class(SuperLineOperator)
if __name__ == "__main__":
register()
# test call
# bpy.ops.object.superline_operator()
|