# node.add_node by code -> use_transform doesn't work

Cycles Render, Node Editor,

I want to add a tooltip for the shader buttons in the node toolshelf. I create a class for that that contains the tooltip and creates the node. And call it by a button then.

It works somehow. I have my tooltip and the class adds the node. But the use_transform setting gets ignored. Means the created node is stuck under the tool shelf or where ever it gets created, which is somehow random. I have to pick it up again.

What do i overlook here? Why is use_transform=True ignored?

Examplecode. First button is the one with my tooltip. The second one works directly. Note that you need to have an object and a material to get the first button to work. I haven't solved that part yet:

import bpy
import os
import bpy.utils.previews

################ Tooltip class ###############################

# Tooltip
class NODEEDITOR_texture_image(bpy.types.Operator):
"""Image Texture\nHere you can load an image as a texture"""
bl_idname = "node.texture_image"
bl_label = "texture image"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
return {'FINISHED'}

###########################################################################

class NodesIconPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "All Nodes"
bl_idname = "nodes.common_buttons"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'TOOLS'
bl_category = "All Nodes"

@staticmethod
def draw(self, context):
layout = self.layout
default_context = bpy.app.translations.contexts.default

##### Textbutton with Tooltip

layout.operator("node.texture_image", text="Image Texture with Tooltip")

#### Textbutton usual
props.use_transform = True

# -----------------------------------------------------------

def register():

# Register all classes

bpy.utils.register_module(__name__)

def unregister():

# Unregister all classes

bpy.utils.unregister_module(__name__)

# This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.

if __name__ == "__main__":
register()


• It works for me. – cmomoney Dec 15 '16 at 18:22
• Have you tried with both buttons? The problem is not that it does not create the node. It is that the node does not stick to the mouse as it should. The use_transform part fails. – Tiles Dec 15 '16 at 18:39
• The nodes does stick to the mouse. It works as expected. I even looked in the INFO and it lists the operator with the use_transform set to True. – cmomoney Dec 15 '16 at 18:43
• With both buttons? – Tiles Dec 15 '16 at 18:44
• I am still baffled that it works for you while it fails for me at two Windows 7 pc's with blender 2.76 up to 2.78. A Windows issue maybe? But the API should work OS independant. - I guess i have to give up here. Anyways. Many thanks for having a look and testing. – Tiles Dec 16 '16 at 8:08

There are two operators called: bpy.ops.node.add_node() and bpy.ops.node.translate_attach_remove_on_cancel(). To get the same result, you put the second(modal) operator in your return and use the INVOKE_DEFAULT option:

class NODEEDITOR_texture_image(bpy.types.Operator):
"""Image Texture\nHere you can load an image as a texture"""
bl_idname = "node.texture_image"
bl_label = "texture image"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):