1
$\begingroup$

I have a script for my addons layout here:

# made in response to
# http://blender.stackexchange.com/q/46496/935

bl_info = {
    "version": (1, 0),
    "blender": (2, 75, 0),
    "author": "sambler",
    "name": "Demo Menus",
    "description": "Demo showing use of different menus" ,
    "category": "test",
}


import bpy

class CustomMenu(bpy.types.Menu):
    """Demo custom menu"""
    # example menu from Templates->Python->ui_menu.py
    bl_label = "Custom Menu"
    bl_idname = "OBJECT_MT_custom_menu"

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

        layout.operator("wm.open_mainfile")
        layout.operator("wm.save_as_mainfile").copy = True

        layout.operator("object.shade_smooth")

        layout.label(text="Hello world!", icon='WORLD_DATA')

        # use an operator enum property to populate a sub-menu
        layout.operator_menu_enum("object.select_by_type",
                                  property="type",
                                  text="Select All by Type...",
                                  )

        # call another menu
        layout.operator("wm.call_menu", text="Unwrap").name = "VIEW3D_MT_uv_map"

class LayoutPanel(bpy.types.Panel):
    bl_label = "Demo layout"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Custom addon"

    def draw(self, context):
        layout = self.layout
        self.layout.operator("object.mode_set", text='Edit', icon='EDITMODE_HLT').mode='EDIT'

        layout.label("Some Operators")
        row = layout.row(align=True)
        row.alignment = 'EXPAND'
        ob = context.active_object
        row.operator("object.mode_set", text="Button1", icon='OBJECT_DATAMODE').mode='OBJECT'
        row.operator("object.mode_set", text="Button2", icon='SCULPTMODE_HLT').mode='SCULPT'
        row.operator("object.mode_set", text="Button3", icon='TPAINT_HLT').mode='TEXTURE_PAINT'
        row.prop(ob, "rotation_euler", text="Rotation")
        row = layout.row()
        box = row.box()

        row = box.row()
        row.label("Some menus", icon='LINENUMBERS_ON')

        row = box.row()
        # add the custom menu defined above
        box.menu(CustomMenu.bl_idname, 'My custom menu', icon='SCRIPTWIN')

        row = box.row()
        # add a standard blender menu - the add menu
        box.menu('INFO_MT_mesh_add', 'Add', icon='ZOOMIN')

        row = box.row()
        # add an enum property menu
        # this allows only certain values to be set for a property
        box.prop_menu_enum(context.scene, 'test_enum', text='enum property', icon='NLA')

enum_menu_items = [
                ('OPT1','Option 1','',1),
                ('OPT2','Option 2','',2),
                ('OPT3','Option 3','',3),
                ('OPT4','Option 4','',4),
                ]

def register():
    bpy.types.Scene.test_enum = bpy.props.EnumProperty(items=enum_menu_items)
    bpy.utils.register_class(CustomMenu)
    bpy.utils.register_class(LayoutPanel)

def unregister():
    bpy.utils.unregister_class(LayoutPanel)
    bpy.utils.unregister_class(CustomMenu)
    del bpy.types.Scene.test_enum


if __name__ == "__main__":
    register()

#  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. 

And in it, I can place the object rotation box, but not the texture space box.

This is a pic of what the code results in: enter image description here

Whenever I try to put the texture space in the box, the panel disappears amost completely: enter image description here

# made in response to
# http://blender.stackexchange.com/q/46496/935

bl_info = {
    "version": (1, 0),
    "blender": (2, 75, 0),
    "author": "sambler",
    "name": "Demo Menus",
    "description": "Demo showing use of different menus" ,
    "category": "test",
}


import bpy

class CustomMenu(bpy.types.Menu):
    """Demo custom menu"""
    # example menu from Templates->Python->ui_menu.py
    bl_label = "Custom Menu"
    bl_idname = "OBJECT_MT_custom_menu"

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

        layout.operator("wm.open_mainfile")
        layout.operator("wm.save_as_mainfile").copy = True

        layout.operator("object.shade_smooth")

        layout.label(text="Hello world!", icon='WORLD_DATA')

        # use an operator enum property to populate a sub-menu
        layout.operator_menu_enum("object.select_by_type",
                                  property="type",
                                  text="Select All by Type...",
                                  )

        # call another menu
        layout.operator("wm.call_menu", text="Unwrap").name = "VIEW3D_MT_uv_map"

class LayoutPanel(bpy.types.Panel):
    bl_label = "Demo layout"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Custom addon"

    def draw(self, context):
        layout = self.layout
        self.layout.operator("object.mode_set", text='Edit', icon='EDITMODE_HLT').mode='EDIT'

        layout.label("Some Operators")
        row = layout.row(align=True)
        row.alignment = 'EXPAND'
        ob = context.active_object
        mesh = context.mesh
        row.column().prop(mesh, "texspace_location", text="Location")
        row.operator("object.mode_set", text="Button1", icon='OBJECT_DATAMODE').mode='OBJECT'
        row.operator("object.mode_set", text="Button2", icon='SCULPTMODE_HLT').mode='SCULPT'
        row.operator("object.mode_set", text="Button3", icon='TPAINT_HLT').mode='TEXTURE_PAINT'
        row.prop(ob, "rotation_euler", text="Rotation")
        row = layout.row()
        box = row.box()

        row = box.row()
        row.label("Some menus", icon='LINENUMBERS_ON')

        row = box.row()
        # add the custom menu defined above
        box.menu(CustomMenu.bl_idname, 'My custom menu', icon='SCRIPTWIN')

        row = box.row()
        # add a standard blender menu - the add menu
        box.menu('INFO_MT_mesh_add', 'Add', icon='ZOOMIN')

        row = box.row()
        # add an enum property menu
        # this allows only certain values to be set for a property
        box.prop_menu_enum(context.scene, 'test_enum', text='enum property', icon='NLA')

enum_menu_items = [
                ('OPT1','Option 1','',1),
                ('OPT2','Option 2','',2),
                ('OPT3','Option 3','',3),
                ('OPT4','Option 4','',4),
                ]

def register():
    bpy.types.Scene.test_enum = bpy.props.EnumProperty(items=enum_menu_items)
    bpy.utils.register_class(CustomMenu)
    bpy.utils.register_class(LayoutPanel)

def unregister():
    bpy.utils.unregister_class(LayoutPanel)
    bpy.utils.unregister_class(CustomMenu)
    del bpy.types.Scene.test_enum


if __name__ == "__main__":
    register()

#  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. 

I've tried several different methods for getting it (the texspace_location) in the menu, and I'd really like to know how to get this to work.

$\endgroup$
3
  • 1
    $\begingroup$ First problem in second code is line 52 mesh = context.mesh consult the system console for errors such as these (AttributeError: 'Context' object has no attribute 'mesh'). Replace with mesh = ob.data. $\endgroup$
    – batFINGER
    Commented Jun 29, 2016 at 4:32
  • $\begingroup$ Well, that fixed it! Thanks :) to think the solution was so simple. $\endgroup$
    – Dassie
    Commented Jun 29, 2016 at 4:58
  • $\begingroup$ NP, thought I'd elaborate with an answer re setting auto_texspace, otherwise the texspace_location is disabled. $\endgroup$
    – batFINGER
    Commented Jun 29, 2016 at 5:02

1 Answer 1

2
$\begingroup$

First problem in second code is line 52 mesh = context.mesh consult the system console for errors such as these (AttributeError: 'Context' object has no attribute 'mesh'). Replace with mesh = ob.data

auto_texspace needs to be turned off to change texspace_location

import bpy

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Texspace test"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'

    bl_category = "Texspace Test"

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

        obj = context.object
        mesh = obj.data
        row = layout.row()
        row.prop(mesh, "auto_texspace")
        if not mesh.auto_texspace:
            row = layout.row()
            row.prop(mesh, "texspace_location", text="Location")

def register():
    bpy.utils.register_class(HelloWorldPanel)

def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)

if __name__ == "__main__":
    register()
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .