Created
January 1, 2016 11:04
-
-
Save sambler/d053348c5d34b2fb4937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are | |
# met: | |
# | |
# * Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above | |
# copyright notice, this list of conditions and the following disclaimer | |
# in the documentation and/or other materials provided with the | |
# distribution. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# | |
# made in response to | |
# http://blender.stackexchange.com/q/44014/935 | |
import bpy | |
bl_info = { | |
"version": (1, 0), | |
"blender": (2, 75, 0), | |
"name": "testing addon", | |
"description": """Sample addon to demonstrate displaying a CollectionProperty within a panel""" , | |
"category": "test", | |
} | |
class UserItems(bpy.types.PropertyGroup): | |
user_str = bpy.props.StringProperty() | |
user_int = bpy.props.IntProperty() | |
class UserAddOptions(bpy.types.Operator): | |
"""Add a user item""" | |
bl_idname = "object.add_user_items" | |
bl_label = "Add custom user items" | |
def execute(self, context): | |
item = bpy.context.scene.user_items.add() | |
item.user_int = 5 | |
item.user_str = 'custom value' | |
return{'FINISHED'} | |
class UserDelOptions(bpy.types.Operator): | |
"""remove a user item""" | |
bl_idname = "object.del_user_item" | |
bl_label = "Remove a custom user item" | |
del_item = bpy.props.IntProperty(name='item index to remove') | |
def execute(self, context): | |
context.scene.user_items.remove(self.del_item) | |
return{'FINISHED'} | |
class OptionsPanel(bpy.types.Panel): | |
"""testing panel in the 3dview properties region""" | |
bl_label = 'Optional data Panel' | |
bl_idname = 'OBJECT_PT_options' | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'UI' | |
bl_context = 'object' | |
def draw(self, context): | |
scn = context.scene | |
layout = self.layout | |
col = layout.column() | |
row = col.row() | |
row.prop(scn, 'option01') | |
row = col.row() | |
row.prop(scn, 'option02') | |
box = col.box() | |
col = box.column() | |
row = col.row() | |
if scn.show_my_options: | |
row.prop(scn, "show_my_options", icon="DOWNARROW_HLT", text="", emboss=False) | |
else: | |
row.prop(scn, "show_my_options", icon="RIGHTARROW", text="", emboss=False) | |
row.label('My options here') | |
if scn.show_my_options: | |
row = col.row() | |
col = row.column(align=True) | |
col.prop(scn.render, 'resolution_x', text='X') | |
col.prop(scn.render, 'resolution_y', text='Y') | |
if scn.option01: | |
row = col.row() | |
row.label('extra options go here') | |
row = col.row() | |
row.label('and more rows for other data') | |
if scn.option02: | |
row = col.row() | |
row.label('dynamic options go here') | |
row = col.row() | |
row.operator(UserAddOptions.bl_idname) | |
for idx, item in enumerate(scn.user_items): | |
row = col.row() | |
row.prop(item,'user_str') | |
row.operator(UserDelOptions.bl_idname, text='', | |
icon='X').del_item = idx | |
row = col.row() | |
row.prop(item,'user_int') | |
def register(): | |
bpy.utils.register_module(__name__) | |
bpy.types.Scene.show_my_options = bpy.props.BoolProperty(name='Show Custom Props', default=False) | |
bpy.types.Scene.option01 = bpy.props.BoolProperty(name='First options', default=False) | |
bpy.types.Scene.option02 = bpy.props.BoolProperty(name='Dynamic options', default=False) | |
bpy.types.Scene.user_items = bpy.props.CollectionProperty(type=UserItems) | |
def unregister(): | |
del bpy.types.Scene.show_my_options | |
del bpy.types.Scene.option01 | |
del bpy.types.Scene.option02 | |
del bpy.types.Scene.user_items | |
bpy.utils.unregister_module(__name__) | |
if __name__ == "__main__": | |
register() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment