class NODE_OT_povray_node_texture_map_add(Operator): bl_idname = "povray.nodetexmapadd" bl_label = "Texture map" def execute(self, context): tree=bpy.context.object.active_material.node_tree tmap = tree.nodes.new('ShaderNodeValToRGB') tmap.location=(self.x/100,self.y/100) bpy.context.object.active_material.node_tree.nodes.active=tmap el=tmap.color_ramp.elements.new(0.5) for el in tmap.color_ramp.elements: el.color=(0,0,0,1) for inp in tmap.inputs: tmap.inputs.remove(inp) for outp in tmap.outputs: tmap.outputs.remove(outp) pattern=tmap.inputs.new('NodeSocketVector', "Pattern") pattern.hide_value=True for i in range(0,3): tmap.inputs.new('NodeSocketColor', "Shader") tmap.outputs.new('NodeSocketShader', "BSDF") tmap.label="Texture Map" def modal(self, context, event): if event.type == 'MOUSEMOVE': # Apply self.x = event.mouse_x self.y = event.mouse_y self.execute(context) elif event.type == 'LEFTMOUSE': # Confirm return {'FINISHED'} elif event.type in ('RIGHTMOUSE', 'ESC'): # Cancel return {'CANCELLED'} def invoke(self, context, event): self.x = event.mouse_x self.y = event.mouse_y self.execute(context) return {'RUNNING_MODAL'}
import bpyclass ForLanuHumNodeModal(bpy.types.Operator): bl_idname = "for_lanuhum.node_modal" bl_label = "For LanuHum Node Modal" def execute(self, context): space = context.space_data tree = space.edit_tree v2d = context.region.view2d x, y = v2d.region_to_view(self.x, self.y) tmap = tree.nodes.new('ShaderNodeValToRGB') tmap.location = (x, y) tmap.label="Texture Map" el = tmap.color_ramp.elements.new(0.5) for el in tmap.color_ramp.elements: el.color = (0,0,0,1) for inp in tmap.inputs: tmap.inputs.remove(inp) for outp in tmap.outputs: tmap.outputs.remove(outp) pattern = tmap.inputs.new('NodeSocketVector', "Pattern") pattern.hide_value = True for i in range(0,3): tmap.inputs.new('NodeSocketColor', "Shader") tmap.outputs.new('NodeSocketShader', "BSDF") return {'FINISHED'} def modal(self, context, event): # Apply if event.type == 'MOUSEMOVE': self.x = event.mouse_region_x self.y = event.mouse_region_y # Comment next line if you want to # create a node on left mouse click self.execute(context) return {'RUNNING_MODAL'} # Confirm elif event.type == 'LEFTMOUSE': # Uncomment next line if you want to # create a node on left mouse click # self.execute(context) return {'FINISHED'} # Cancel elif event.type in ('RIGHTMOUSE', 'ESC'): return {'CANCELLED'} return {'RUNNING_MODAL'} def invoke(self, context, event): context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'}bpy.utils.register_class(ForLanuHumNodeModal)
Очень сложно понять, чего ты хочешь добиться
class PovrayNodeModal(bpy.types.Operator): bl_idname = "povray.node_modal" bl_label = "Node Modal" add=True def execute(self, context): space = context.space_data tree = space.edit_tree for node in tree.nodes: node.select=False if self.add==True: tmap = tree.nodes.new('ShaderNodeValToRGB') tmap.label="Texture Map" el = tmap.color_ramp.elements.new(0.5) for el in tmap.color_ramp.elements: el.color = (0,0,0,1) for inp in tmap.inputs: tmap.inputs.remove(inp) for outp in tmap.outputs: tmap.outputs.remove(outp) pattern = tmap.inputs.new('NodeSocketVector', "Pattern") pattern.hide_value = True for i in range(0,3): tmap.inputs.new('NodeSocketColor', "Shader") tmap.outputs.new('NodeSocketShader', "BSDF") tree.nodes.active=tmap self.add=False aNode=tree.nodes.active aNode.select=True v2d = context.region.view2d x, y = v2d.region_to_view(self.x, self.y) aNode.location = (x, y) def modal(self, context, event): if event.type == 'MOUSEMOVE': self.x = event.mouse_region_x self.y = event.mouse_region_y self.execute(context) return {'RUNNING_MODAL'} elif event.type == 'LEFTMOUSE': return {'FINISHED'} elif event.type in ('RIGHTMOUSE', 'ESC'): return {'CANCELLED'} return {'RUNNING_MODAL'} def invoke(self, context, event): context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'}