Skip to content

Instantly share code, notes, and snippets.

@sambler
Created March 27, 2016 15:40
Show Gist options
  • Save sambler/572a4979434dc98ab5b2 to your computer and use it in GitHub Desktop.
Save sambler/572a4979434dc98ab5b2 to your computer and use it in GitHub Desktop.
# made in response to
# http://blender.stackexchange.com/q/49552/935
bl_info = {
"version": (1, 0),
"blender": (2, 75, 0),
"author": "sambler",
"name": "testing addon",
"location": "blender",
"description": "test showing material nodes in toolshelf" ,
"warning": "only for testing",
"category": "test",
}
import bpy
class MaterialNodeViewPanel(bpy.types.Panel):
"""Display material nodes"""
bl_label = 'Node View Panel'
bl_idname = 'MAT_PT_nodes'
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
layout = self.layout
obj = context.object
if obj.type == 'LAMP':
# we need obj as a lamp object to get the node_tree property
obj = bpy.data.lamps[obj.name]
uses_nodes = obj.use_nodes
node_tree = obj.node_tree
outnode_type = 'OUTPUT_LAMP'
else:
mat = obj.active_material
if mat is None:
layout.row().label(text='No material')
return
uses_nodes = mat.use_nodes
node_tree = obj.active_material.node_tree
outnode_type = 'OUTPUT_MATERIAL'
if not uses_nodes:
layout.row().label(text='Enable nodes in the material properties')
return
node = None
for n in node_tree.nodes:
if n.type == outnode_type and n.is_active_output:
node = n
break
if node is None:
layout.row().label(text='No output node found')
else:
layout.template_node_view(node_tree, node, node.inputs['Surface'])
def register():
bpy.utils.register_class(MaterialNodeViewPanel)
def unregister():
bpy.utils.unregister_class(MaterialNodeViewPanel)
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.
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment