1
$\begingroup$

The script works perfect

class ObjectShading(bpy.types.Panel):
bl_label = "Shading"
bl_idname = "ObjectShading"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Claas"

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

    obj = context.object
    mesh = obj.data

    row = layout.row()
    row.label(text="AutoEdgeBreak:")
    row = layout.row()
    row.prop(mesh, "use_auto_smooth", text="BreakEdge")
    row.active = mesh.use_auto_smooth and not mesh.has_custom_normals
    row.prop(mesh, "auto_smooth_angle", text="Angle")
    row = layout.row()
    row.label(text="ManualSmooth:")
    row = layout.row()
    row.operator("object.shade_smooth", text="Smooth", icon="SMOOTHCURVE")
    row.operator("object.shade_flat", text="Sharp", icon="LINCURVE")
    row = layout.row()
    row.prop(obj, "draw_type", text="Draw Type")
    row = layout.row()
    row.prop(obj, "show_wire", text="Wire")
    row.prop(obj, "show_transparent", text="Transparency")
    row.prop(obj, "show_x_ray", text="X-Ray")
    row = layout.row()
    #row.prop(mat, "alpha")
    split = layout.split()

But when I add the following value definition no buttons are drawn

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

    obj = context.object
    mesh = obj.data
    mat = context.material
    cmat = mat.cycles

What I try to do is to add an alpha value slider so I can set transparency for display and value in one area.

row.prop(mat, "alpha")
$\endgroup$
1
$\begingroup$

Yes, errors in the script's draw function will stop it from drawing beyond the line where the error happens (or it will stop drawing your panel entirely). The error you got is:

location: <unknown location>:-1
Traceback (most recent call last):
  File "/ui_panel.py", line ---, in draw
AttributeError: 'Context' object has no attribute 'material'

Fix this error and the panel will draw OK. It means context.material is the problem.

Get in the habit of starting Blender from Terminal during experimentation / development process. This will allow you to read the errors that occur when Blender doesn't explicitly tell you something's wrong.

$\endgroup$
  • $\begingroup$ Ok now I understand why I don't always see errors. Have to google how to start it from terminal under win10. $\endgroup$ – Claas Kuhnen Jan 2 '16 at 22:55
  • $\begingroup$ Using windows you can open a terminal window from Window -> Toggle System Console. See blender.org/manual/.../console_window.html --- but Blender on Linux and OSX don't have that feature. $\endgroup$ – zeffii Jan 2 '16 at 22:59
  • $\begingroup$ OS X you open terminal and then drag blender into the window and hit enter. $\endgroup$ – Claas Kuhnen Jan 2 '16 at 23:07
  • $\begingroup$ sure. but windows is the only platform with the Window -> Toggle System Console in Blender. (just to be clear) $\endgroup$ – zeffii Jan 2 '16 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.