Skip to content

Instantly share code, notes, and snippets.

@p2or
Last active September 23, 2024 15:48
Show Gist options
  • Select an option

  • Save p2or/2947b1aa89141caae182526a8fc2bc5a to your computer and use it in GitHub Desktop.

Select an option

Save p2or/2947b1aa89141caae182526a8fc2bc5a to your computer and use it in GitHub Desktop.

Revisions

  1. p2or revised this gist Jan 24, 2024. No changes.
  2. p2or revised this gist Jan 24, 2024. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Blender_Basic-UI-Template.py
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,7 @@ class MY_PG_SceneProperties(PropertyGroup):

    my_bool: BoolProperty(
    name="Bool",
    description="A bool property",
    description="Bool property",
    default = False
    )

    @@ -164,7 +164,6 @@ class OBJECT_PT_CustomPanel(Panel):
    bl_category = "Tools"
    bl_context = "objectmode"


    @classmethod
    def poll(self,context):
    return context.object is not None
  3. p2or revised this gist Jan 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Blender_Basic-UI-Template.py
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@
    "name": "Add-on Template",
    "description": "A demo that adds a custom panel to the 'Tool Shelf' of the '3d View'",
    "author": "p2or",
    "version": (0, 0, 4),
    "version": (0, 4),
    "blender": (3, 0, 0),
    "location": "3D View > Tools",
    "warning": "", # used for warning icon and text in addons panel
  4. p2or revised this gist Jan 22, 2024. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions Blender_Basic-UI-Template.py
    Original file line number Diff line number Diff line change
    @@ -19,14 +19,15 @@

    bl_info = {
    "name": "Add-on Template",
    "description": "https://blender.stackexchange.com/a/57332",
    "description": "A demo that adds a custom panel to the 'Tool Shelf' of the '3d View'",
    "author": "p2or",
    "version": (0, 0, 4),
    "blender": (3, 0, 0),
    "location": "3D View > Tools",
    "warning": "", # used for warning icon and text in addons panel
    "wiki_url": "",
    "tracker_url": "",
    "doc_url": "https://blender.stackexchange.com/a/57332",
    "tracker_url": "https://gist.github.com/p2or/2947b1aa89141caae182526a8fc2bc5a",
    "support": "COMMUNITY",
    "category": "Development"
    }

  5. p2or revised this gist Jan 22, 2024. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions Blender_Basic-UI-Template.py
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@
    # Scene Properties
    # ------------------------------------------------------------------------

    class MyProperties(PropertyGroup):
    class MY_PG_SceneProperties(PropertyGroup):

    my_bool: BoolProperty(
    name="Bool",
    @@ -114,10 +114,10 @@ class MyProperties(PropertyGroup):
    # ------------------------------------------------------------------------

    class WM_OT_HelloWorld(Operator):
    bl_label = "Print Values Operator"
    bl_label = "Print Values to the Console"
    bl_idname = "wm.hello_world"
    # WindowManager namespace (wm.hello...) serves as example,
    # You could also use a custom one like: my_name.hello_world
    # You could also use a custom one like: my_category.hello_world

    def execute(self, context):
    scene = context.scene
    @@ -129,7 +129,7 @@ def execute(self, context):
    print("int value:", mytool.my_int)
    print("float value:", mytool.my_float)
    print("string value:", mytool.my_string)
    print("enum state:", mytool.my_enum)
    print("enum selection:", mytool.my_enum)

    return {'FINISHED'}

    @@ -195,8 +195,8 @@ def draw(self, context):
    # ------------------------------------------------------------------------

    classes = (
    MyProperties,
    WM_OT_HelloWorld,
    MY_PG_SceneProperties,
    OBJECT_MT_CustomMenu,
    OBJECT_PT_CustomPanel
    )
    @@ -206,7 +206,7 @@ def register():
    for cls in classes:
    register_class(cls)

    bpy.types.Scene.my_tool = PointerProperty(type=MyProperties)
    bpy.types.Scene.my_tool = PointerProperty(type=MY_PG_SceneProperties)

    def unregister():
    from bpy.utils import unregister_class
    @@ -216,4 +216,4 @@ def unregister():


    if __name__ == "__main__":
    register()
    register()
  6. p2or revised this gist Jan 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Blender_Basic-UI-Template.py
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@

    bl_info = {
    "name": "Add-on Template",
    "description": "",
    "description": "https://blender.stackexchange.com/a/57332",
    "author": "p2or",
    "version": (0, 0, 4),
    "blender": (3, 0, 0),
  7. p2or revised this gist Jan 22, 2024. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions Blender_Basic-UI-Template.py
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@
    #
    # ##### END GPL LICENSE BLOCK #####


    bl_info = {
    "name": "Add-on Template",
    "description": "",
    @@ -61,23 +62,23 @@ class MyProperties(PropertyGroup):

    my_int: IntProperty(
    name = "Int",
    description="A integer property",
    description="Integer property",
    default = 23,
    min = 10,
    max = 100
    )

    my_float: FloatProperty(
    name = "Float",
    description = "A float property",
    description = "Float Property",
    default = 23.7,
    min = 0.01,
    max = 30.0
    )

    my_float_vector: FloatVectorProperty(
    name = "Float Vector",
    description="Something",
    description="Float Vector Property",
    default=(0.0, 0.0, 0.0),
    #subtype='COLOR',
    min= 0.0, # float
    @@ -86,22 +87,22 @@ class MyProperties(PropertyGroup):

    my_string: StringProperty(
    name="String",
    description=":",
    description="String Property",
    default="",
    maxlen=1024,
    )

    my_path: StringProperty(
    name = "Directory",
    description="Choose a directory:",
    description="Choose a Directory:",
    default="",
    maxlen=1024,
    subtype='DIR_PATH' # FILE_PATH
    )

    my_enum: EnumProperty(
    name="Enum",
    description="Apply Data to attribute.",
    description="Enum Property",
    items=[ ('OP1', "Option 1", ""),
    ('OP2', "Option 2", ""),
    ]
    @@ -114,8 +115,10 @@ class MyProperties(PropertyGroup):

    class WM_OT_HelloWorld(Operator):
    bl_label = "Print Values Operator"
    bl_idname = "wm.hello_world"

    bl_idname = "wm.hello_world"
    # WindowManager namespace (wm.hello...) serves as example,
    # You could also use a custom one like: my_name.hello_world

    def execute(self, context):
    scene = context.scene
    mytool = scene.my_tool
  8. p2or renamed this gist Jan 22, 2024. 1 changed file with 25 additions and 7 deletions.
    32 changes: 25 additions & 7 deletions Blender_Basic-UI-Example.py → Blender_Basic-UI-Template.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,21 @@
    # ##### BEGIN GPL LICENSE BLOCK #####
    #
    # This program is free software; you can redistribute it and/or
    # modify it under the terms of the GNU General Public License
    # as published by the Free Software Foundation; either version 2
    # of the License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software Foundation,
    # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    #
    # ##### END GPL LICENSE BLOCK #####

    bl_info = {
    "name": "Add-on Template",
    "description": "",
    @@ -36,29 +54,29 @@
    class MyProperties(PropertyGroup):

    my_bool: BoolProperty(
    name="Enable or Disable",
    name="Bool",
    description="A bool property",
    default = False
    )

    my_int: IntProperty(
    name = "Int Value",
    name = "Int",
    description="A integer property",
    default = 23,
    min = 10,
    max = 100
    )

    my_float: FloatProperty(
    name = "Float Value",
    name = "Float",
    description = "A float property",
    default = 23.7,
    min = 0.01,
    max = 30.0
    )

    my_float_vector: FloatVectorProperty(
    name = "Float Vector Value",
    name = "Float Vector",
    description="Something",
    default=(0.0, 0.0, 0.0),
    #subtype='COLOR',
    @@ -67,7 +85,7 @@ class MyProperties(PropertyGroup):
    )

    my_string: StringProperty(
    name="User Input",
    name="String",
    description=":",
    default="",
    maxlen=1024,
    @@ -82,7 +100,7 @@ class MyProperties(PropertyGroup):
    )

    my_enum: EnumProperty(
    name="Enum:",
    name="Enum",
    description="Apply Data to attribute.",
    items=[ ('OP1', "Option 1", ""),
    ('OP2', "Option 2", ""),
    @@ -195,4 +213,4 @@ def unregister():


    if __name__ == "__main__":
    register()
    register()
  9. p2or revised this gist Jan 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Blender_Basic-UI-Example.py
    Original file line number Diff line number Diff line change
    @@ -195,4 +195,4 @@ def unregister():


    if __name__ == "__main__":
    register()
    register()
  10. p2or renamed this gist Jan 22, 2024. 1 changed file with 0 additions and 0 deletions.
  11. p2or renamed this gist Jan 22, 2024. 1 changed file with 19 additions and 12 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,9 @@
    # https://blender.stackexchange.com/q/57306/3710

    bl_info = {
    "name": "Add-on Template",
    "description": "",
    "author": "p2or",
    "version": (0, 0, 3),
    "blender": (2, 80, 0),
    "version": (0, 0, 4),
    "blender": (3, 0, 0),
    "location": "3D View > Tools",
    "warning": "", # used for warning icon and text in addons panel
    "wiki_url": "",
    @@ -62,7 +60,8 @@ class MyProperties(PropertyGroup):
    my_float_vector: FloatVectorProperty(
    name = "Float Vector Value",
    description="Something",
    default=(0.0, 0.0, 0.0),
    default=(0.0, 0.0, 0.0),
    #subtype='COLOR',
    min= 0.0, # float
    max = 0.1
    )
    @@ -79,18 +78,18 @@ class MyProperties(PropertyGroup):
    description="Choose a directory:",
    default="",
    maxlen=1024,
    subtype='DIR_PATH'
    subtype='DIR_PATH' # FILE_PATH
    )

    my_enum: EnumProperty(
    name="Dropdown:",
    name="Enum:",
    description="Apply Data to attribute.",
    items=[ ('OP1', "Option 1", ""),
    ('OP2', "Option 2", ""),
    ('OP3', "Option 3", ""),
    ]
    ]
    )


    # ------------------------------------------------------------------------
    # Operators
    # ------------------------------------------------------------------------
    @@ -113,6 +112,7 @@ def execute(self, context):

    return {'FINISHED'}


    # ------------------------------------------------------------------------
    # Menus
    # ------------------------------------------------------------------------
    @@ -128,6 +128,7 @@ def draw(self, context):
    layout.operator("object.select_all", text="Select/Deselect All").action = 'TOGGLE'
    layout.operator("object.select_all", text="Inverse").action = 'INVERT'
    layout.operator("object.select_random", text="Random")


    # ------------------------------------------------------------------------
    # Panel in Object Mode
    @@ -148,20 +149,26 @@ def poll(self,context):

    def draw(self, context):
    layout = self.layout
    layout.use_property_split = True
    layout.use_property_decorate = False # No animation.

    scene = context.scene
    mytool = scene.my_tool

    layout.prop(mytool, "my_bool")
    layout.prop(mytool, "my_enum", text="")
    layout.prop(mytool, "my_enum", expand=True)
    layout.prop(mytool, "my_int")
    layout.prop(mytool, "my_float")
    layout.prop(mytool, "my_float_vector", text="")
    layout.prop(mytool, "my_float_vector")
    layout.prop(mytool, "my_string")
    layout.prop(mytool, "my_path")
    layout.operator("wm.hello_world")

    layout.separator(factor=1.5)
    layout.menu(OBJECT_MT_CustomMenu.bl_idname, text="Presets", icon="SCENE")
    layout.operator("wm.hello_world")
    layout.separator()


    # ------------------------------------------------------------------------
    # Registration
    # ------------------------------------------------------------------------
  12. p2or revised this gist May 13, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion blender-basic-ui-example-28x.py
    Original file line number Diff line number Diff line change
    @@ -117,7 +117,7 @@ def execute(self, context):
    # Menus
    # ------------------------------------------------------------------------

    class OBJECT_MT_CustomMenu(bpy.types.Menu):
    class OBJECT_MT_CustomMenu(Menu):
    bl_label = "Select"
    bl_idname = "OBJECT_MT_custom_menu"

  13. p2or revised this gist Aug 16, 2019. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion blender-basic-ui-example-28x.py
    Original file line number Diff line number Diff line change
    @@ -74,6 +74,14 @@ class MyProperties(PropertyGroup):
    maxlen=1024,
    )

    my_path: StringProperty(
    name = "Directory",
    description="Choose a directory:",
    default="",
    maxlen=1024,
    subtype='DIR_PATH'
    )

    my_enum: EnumProperty(
    name="Dropdown:",
    description="Apply Data to attribute.",
    @@ -149,6 +157,7 @@ def draw(self, context):
    layout.prop(mytool, "my_float")
    layout.prop(mytool, "my_float_vector", text="")
    layout.prop(mytool, "my_string")
    layout.prop(mytool, "my_path")
    layout.operator("wm.hello_world")
    layout.menu(OBJECT_MT_CustomMenu.bl_idname, text="Presets", icon="SCENE")
    layout.separator()
    @@ -179,4 +188,4 @@ def unregister():


    if __name__ == "__main__":
    register()
    register()
  14. p2or revised this gist Aug 16, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions blender-basic-ui-example-28x.py
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    "name": "Add-on Template",
    "description": "",
    "author": "p2or",
    "version": (0, 0, 2),
    "version": (0, 0, 3),
    "blender": (2, 80, 0),
    "location": "3D View > Tools",
    "warning": "", # used for warning icon and text in addons panel
    @@ -88,8 +88,8 @@ class MyProperties(PropertyGroup):
    # ------------------------------------------------------------------------

    class WM_OT_HelloWorld(Operator):
    bl_idname = "wm.hello_world"
    bl_label = "Print Values Operator"
    bl_idname = "wm.hello_world"

    def execute(self, context):
    scene = context.scene
    @@ -110,8 +110,8 @@ def execute(self, context):
    # ------------------------------------------------------------------------

    class OBJECT_MT_CustomMenu(bpy.types.Menu):
    bl_idname = "object.custom_menu"
    bl_label = "Select"
    bl_idname = "OBJECT_MT_custom_menu"

    def draw(self, context):
    layout = self.layout
    @@ -126,8 +126,8 @@ def draw(self, context):
    # ------------------------------------------------------------------------

    class OBJECT_PT_CustomPanel(Panel):
    bl_idname = "object.custom_panel"
    bl_label = "My Panel"
    bl_idname = "OBJECT_PT_custom_panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Tools"
  15. p2or created this gist Feb 27, 2019.
    182 changes: 182 additions & 0 deletions blender-basic-ui-example-28x.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,182 @@
    # https://blender.stackexchange.com/q/57306/3710

    bl_info = {
    "name": "Add-on Template",
    "description": "",
    "author": "p2or",
    "version": (0, 0, 2),
    "blender": (2, 80, 0),
    "location": "3D View > Tools",
    "warning": "", # used for warning icon and text in addons panel
    "wiki_url": "",
    "tracker_url": "",
    "category": "Development"
    }


    import bpy

    from bpy.props import (StringProperty,
    BoolProperty,
    IntProperty,
    FloatProperty,
    FloatVectorProperty,
    EnumProperty,
    PointerProperty,
    )
    from bpy.types import (Panel,
    Menu,
    Operator,
    PropertyGroup,
    )


    # ------------------------------------------------------------------------
    # Scene Properties
    # ------------------------------------------------------------------------

    class MyProperties(PropertyGroup):

    my_bool: BoolProperty(
    name="Enable or Disable",
    description="A bool property",
    default = False
    )

    my_int: IntProperty(
    name = "Int Value",
    description="A integer property",
    default = 23,
    min = 10,
    max = 100
    )

    my_float: FloatProperty(
    name = "Float Value",
    description = "A float property",
    default = 23.7,
    min = 0.01,
    max = 30.0
    )

    my_float_vector: FloatVectorProperty(
    name = "Float Vector Value",
    description="Something",
    default=(0.0, 0.0, 0.0),
    min= 0.0, # float
    max = 0.1
    )

    my_string: StringProperty(
    name="User Input",
    description=":",
    default="",
    maxlen=1024,
    )

    my_enum: EnumProperty(
    name="Dropdown:",
    description="Apply Data to attribute.",
    items=[ ('OP1', "Option 1", ""),
    ('OP2', "Option 2", ""),
    ('OP3', "Option 3", ""),
    ]
    )

    # ------------------------------------------------------------------------
    # Operators
    # ------------------------------------------------------------------------

    class WM_OT_HelloWorld(Operator):
    bl_idname = "wm.hello_world"
    bl_label = "Print Values Operator"

    def execute(self, context):
    scene = context.scene
    mytool = scene.my_tool

    # print the values to the console
    print("Hello World")
    print("bool state:", mytool.my_bool)
    print("int value:", mytool.my_int)
    print("float value:", mytool.my_float)
    print("string value:", mytool.my_string)
    print("enum state:", mytool.my_enum)

    return {'FINISHED'}

    # ------------------------------------------------------------------------
    # Menus
    # ------------------------------------------------------------------------

    class OBJECT_MT_CustomMenu(bpy.types.Menu):
    bl_idname = "object.custom_menu"
    bl_label = "Select"

    def draw(self, context):
    layout = self.layout

    # Built-in operators
    layout.operator("object.select_all", text="Select/Deselect All").action = 'TOGGLE'
    layout.operator("object.select_all", text="Inverse").action = 'INVERT'
    layout.operator("object.select_random", text="Random")

    # ------------------------------------------------------------------------
    # Panel in Object Mode
    # ------------------------------------------------------------------------

    class OBJECT_PT_CustomPanel(Panel):
    bl_idname = "object.custom_panel"
    bl_label = "My Panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Tools"
    bl_context = "objectmode"


    @classmethod
    def poll(self,context):
    return context.object is not None

    def draw(self, context):
    layout = self.layout
    scene = context.scene
    mytool = scene.my_tool

    layout.prop(mytool, "my_bool")
    layout.prop(mytool, "my_enum", text="")
    layout.prop(mytool, "my_int")
    layout.prop(mytool, "my_float")
    layout.prop(mytool, "my_float_vector", text="")
    layout.prop(mytool, "my_string")
    layout.operator("wm.hello_world")
    layout.menu(OBJECT_MT_CustomMenu.bl_idname, text="Presets", icon="SCENE")
    layout.separator()

    # ------------------------------------------------------------------------
    # Registration
    # ------------------------------------------------------------------------

    classes = (
    MyProperties,
    WM_OT_HelloWorld,
    OBJECT_MT_CustomMenu,
    OBJECT_PT_CustomPanel
    )

    def register():
    from bpy.utils import register_class
    for cls in classes:
    register_class(cls)

    bpy.types.Scene.my_tool = PointerProperty(type=MyProperties)

    def unregister():
    from bpy.utils import unregister_class
    for cls in reversed(classes):
    unregister_class(cls)
    del bpy.types.Scene.my_tool


    if __name__ == "__main__":
    register()