Skip to content

Instantly share code, notes, and snippets.

@p2or
Last active May 21, 2023 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save p2or/1eea9dc4ead2bde6316b to your computer and use it in GitHub Desktop.
Save p2or/1eea9dc4ead2bde6316b to your computer and use it in GitHub Desktop.
GroupsInScene #Blender
bl_info = {
"name": "tester",
"description": "",
"author": "",
"version": (0, 0, 3),
"blender": (2, 70, 0),
"location": "3D View > Toolbox",
"warning": "", # used for warning icon and text in addons panel
"wiki_url": "",
"tracker_url": "",
"category": "Test"
}
import bpy
import re
import math
from mathutils import Vector
from math import pi
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
AddonPreferences,
PropertyGroup,
)
# ------------------------------------------------------------------------------------------------
# get object type list
# ------------------------------------------------------------------------------------------------
def get_groupItems():
items = None
def func(self, context):
items = [(group.name, group.name, "") for group in bpy.data.groups]
return items
return func
# ------------------------------------------------------------------------
# store properties in the active scene
# ------------------------------------------------------------------------
class MySettings(PropertyGroup):
search_selection = StringProperty(name="Group")
enum_selection = EnumProperty(
name="Apply Data to:",
description="Apply Data to attribute.",
items=get_groupItems()
)
# ------------------------------------------------------------------------
# myTool in objectmode
# ------------------------------------------------------------------------
class OBJECT_PT_my_panel(Panel):
bl_idname = "OBJECT_PT_my_panel"
bl_label = "My Panel"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_category = "TESTER"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
scene = context.scene
mytool = scene.my_tool
layout.prop_search(mytool, "search_selection", bpy.data, "groups")
layout.prop(mytool, "enum_selection", text="")
print (mytool.search_selection)
print (mytool.enum_selection)
# ------------------------------------------------------------------------
# register and unregister functions
# ------------------------------------------------------------------------
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.my_tool = PointerProperty(type=MySettings)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment