Skip to content
Snippets Groups Projects
node_wrangler.py 226 KiB
Newer Older
  • Learn to ignore specific revisions
  •     """Set the viewer tile center to the mouse position"""
        bl_idname = "node.nw_viewer_focus"
        bl_label = "Viewer Focus"
    
    
    Campbell Barton's avatar
    Campbell Barton committed
        x: bpy.props.IntProperty()
        y: bpy.props.IntProperty()
    
    
        @classmethod
        def poll(cls, context):
            return nw_check(context) and context.space_data.tree_type == 'CompositorNodeTree'
    
        def execute(self, context):
            return {'FINISHED'}
    
        def invoke(self, context, event):
            render = context.scene.render
            space = context.space_data
            percent = render.resolution_percentage*0.01
    
    
            nodes, links = get_nodes_links(context)
            viewers = [n for n in nodes if n.type == 'VIEWER']
    
            if viewers:
                mlocx = event.mouse_region_x
                mlocy = event.mouse_region_y
                select_node = bpy.ops.node.select(mouse_x=mlocx, mouse_y=mlocy, extend=False)
    
                if not 'FINISHED' in select_node:  # only run if we're not clicking on a node
                    region_x = context.region.width
                    region_y = context.region.height
    
                    region_center_x = context.region.width  / 2
                    region_center_y = context.region.height / 2
    
                    bd_x = render.resolution_x * percent * space.backdrop_zoom
                    bd_y = render.resolution_y * percent * space.backdrop_zoom
    
                    backdrop_center_x = (bd_x / 2) - space.backdrop_offset[0]
                    backdrop_center_y = (bd_y / 2) - space.backdrop_offset[1]
    
                    margin_x = region_center_x - backdrop_center_x
                    margin_y = region_center_y - backdrop_center_y
    
                    abs_mouse_x = (mlocx - margin_x) / bd_x
                    abs_mouse_y = (mlocy - margin_y) / bd_y
    
                    for node in viewers:
                        node.center_x = abs_mouse_x
                        node.center_y = abs_mouse_y
                else:
                    return {'PASS_THROUGH'}
    
    class NWSaveViewer(bpy.types.Operator, ExportHelper):
        """Save the current viewer node to an image file"""
        bl_idname = "node.nw_save_viewer"
        bl_label = "Save This Image"
    
    Campbell Barton's avatar
    Campbell Barton committed
        filepath: StringProperty(subtype="FILE_PATH")
        filename_ext: EnumProperty(
    
                name="Format",
                description="Choose the file format to save to",
    
                items=(('.bmp', "BMP", ""),
    
                       ('.rgb', 'IRIS', ""),
                       ('.png', 'PNG', ""),
                       ('.jpg', 'JPEG', ""),
                       ('.jp2', 'JPEG2000', ""),
                       ('.tga', 'TARGA', ""),
                       ('.cin', 'CINEON', ""),
                       ('.dpx', 'DPX', ""),
                       ('.exr', 'OPEN_EXR', ""),
                       ('.hdr', 'HDR', ""),
                       ('.tif', 'TIFF', "")),
                default='.png',
                )
    
        @classmethod
        def poll(cls, context):
    
            valid = False
            if nw_check(context):
                if context.space_data.tree_type == 'CompositorNodeTree':
                    if "Viewer Node" in [i.name for i in bpy.data.images]:
                        if sum(bpy.data.images["Viewer Node"].size) > 0:  # False if not connected or connected but no image
                            valid = True
            return valid
    
    
        def execute(self, context):
            fp = self.filepath
            if fp:
                formats = {
                           '.bmp': 'BMP',
                           '.rgb': 'IRIS',
                           '.png': 'PNG',
                           '.jpg': 'JPEG',
                           '.jpeg': 'JPEG',
                           '.jp2': 'JPEG2000',
                           '.tga': 'TARGA',
                           '.cin': 'CINEON',
                           '.dpx': 'DPX',
                           '.exr': 'OPEN_EXR',
                           '.hdr': 'HDR',
                           '.tiff': 'TIFF',
                           '.tif': 'TIFF'}
                basename, ext = path.splitext(fp)
                old_render_format = context.scene.render.image_settings.file_format
                context.scene.render.image_settings.file_format = formats[self.filename_ext]
                context.area.type = "IMAGE_EDITOR"
                context.area.spaces[0].image = bpy.data.images['Viewer Node']
                context.area.spaces[0].image.save_render(fp)
                context.area.type = "NODE_EDITOR"
                context.scene.render.image_settings.file_format = old_render_format
                return {'FINISHED'}
    
    
    
    class NWResetNodes(bpy.types.Operator):
        """Reset Nodes in Selection"""
        bl_idname = "node.nw_reset_nodes"
        bl_label = "Reset Nodes"
        bl_options = {'REGISTER', 'UNDO'}
    
        @classmethod
        def poll(cls, context):
            space = context.space_data
            return space.type == 'NODE_EDITOR'
    
        def execute(self, context):
            node_active = context.active_node
            node_selected = context.selected_nodes
            node_ignore = ["FRAME","REROUTE", "GROUP"]
    
            # Check if one node is selected at least
            if not (len(node_selected) > 0):
                self.report({'ERROR'}, "1 node must be selected at least")
                return {'CANCELLED'}
    
            active_node_name = node_active.name if node_active.select else None
            valid_nodes = [n for n in node_selected if n.type not in node_ignore]
    
            # Create output lists
            selected_node_names = [n.name for n in node_selected]
            success_names = []
    
            # Reset all valid children in a frame
            node_active_is_frame = False
            if len(node_selected) == 1 and node_active.type == "FRAME":
                node_tree = node_active.id_data
                children = [n for n in node_tree.nodes if n.parent == node_active]
                if children:
                    valid_nodes = [n for n in children if n.type not in node_ignore]
                    selected_node_names = [n.name for n in children if n.type not in node_ignore]
                    node_active_is_frame = True
    
            # Check if valid nodes in selection
            if not (len(valid_nodes) > 0):
                # Check for frames only
                frames_selected = [n for n in node_selected if n.type == "FRAME"]
                if (len(frames_selected) > 1 and len(frames_selected) == len(node_selected)):
                    self.report({'ERROR'}, "Please select only 1 frame to reset")
                else:
                    self.report({'ERROR'}, "No valid node(s) in selection")
                return {'CANCELLED'}
    
            # Report nodes that are not valid
            if len(valid_nodes) != len(node_selected) and node_active_is_frame is False:
                valid_node_names = [n.name for n in valid_nodes]
                not_valid_names = list(set(selected_node_names) - set(valid_node_names))
                self.report({'INFO'}, "Ignored {}".format(", ".join(not_valid_names)))
    
            # Deselect all nodes
            for i in node_selected:
                i.select = False
    
            # Run through all valid nodes
    
            for node in valid_nodes:
    
    
                parent = node.parent if node.parent else None
                node_loc = [node.location.x, node.location.y]
    
                node_tree = node.id_data
                props_to_copy = 'bl_idname name location height width'.split(' ')
    
                reconnections = []
                mappings = chain.from_iterable([node.inputs, node.outputs])
                for i in (i for i in mappings if i.is_linked):
                    for L in i.links:
                        reconnections.append([L.from_socket.path_from_id(), L.to_socket.path_from_id()])
    
                props = {j: getattr(node, j) for j in props_to_copy}
    
                new_node = node_tree.nodes.new(props['bl_idname'])
                props_to_copy.pop(0)
    
                for prop in props_to_copy:
                    setattr(new_node, prop, props[prop])
    
                nodes = node_tree.nodes
                nodes.remove(node)
                new_node.name = props['name']
    
                if parent:
                    new_node.parent = parent
                    new_node.location = node_loc
    
                for str_from, str_to in reconnections:
                    node_tree.links.new(eval(str_from), eval(str_to))
    
                new_node.select = False
                success_names.append(new_node.name)
    
            # Reselect all nodes
            if selected_node_names and node_active_is_frame is False:
                for i in selected_node_names:
                    node_tree.nodes[i].select = True
    
            if active_node_name is not None:
                node_tree.nodes[active_node_name].select = True
                node_tree.nodes.active = node_tree.nodes[active_node_name]
    
            self.report({'INFO'}, "Successfully reset {}".format(", ".join(success_names)))
            return {'FINISHED'}
    
    
    
    def drawlayout(context, layout, mode='non-panel'):
        tree_type = context.space_data.tree_type
    
        col = layout.column(align=True)
        col.menu(NWMergeNodesMenu.bl_idname)
        col.separator()
    
        col = layout.column(align=True)
        col.menu(NWSwitchNodeTypeMenu.bl_idname, text="Switch Node Type")
        col.separator()
    
    
            col = layout.column(align=True)
            col.operator(NWAddTextureSetup.bl_idname, text="Add Texture Setup", icon='NODE_SEL')
    
            col.operator(NWAddPrincipledSetup.bl_idname, text="Add Principled Setup", icon='NODE_SEL')
    
            col.separator()
    
        col = layout.column(align=True)
        col.operator(NWDetachOutputs.bl_idname, icon='UNLINKED')
    
        col.operator(NWSwapLinks.bl_idname)
    
        col.menu(NWAddReroutesMenu.bl_idname, text="Add Reroutes", icon='LAYER_USED')
        col.separator()
    
        col = layout.column(align=True)
        col.menu(NWLinkActiveToSelectedMenu.bl_idname, text="Link Active To Selected", icon='LINKED')
    
        if tree_type != 'GeometryNodeTree':
            col.operator(NWLinkToOutputNode.bl_idname, icon='DRIVER')
    
        col.separator()
    
        col = layout.column(align=True)
        if mode == 'panel':
            row = col.row(align=True)
            row.operator(NWClearLabel.bl_idname).option = True
            row.operator(NWModifyLabels.bl_idname)
        else:
            col.operator(NWClearLabel.bl_idname).option = True
            col.operator(NWModifyLabels.bl_idname)
        col.menu(NWBatchChangeNodesMenu.bl_idname, text="Batch Change")
        col.separator()
        col.menu(NWCopyToSelectedMenu.bl_idname, text="Copy to Selected")
        col.separator()
    
        col = layout.column(align=True)
        if tree_type == 'CompositorNodeTree':
            col.operator(NWResetBG.bl_idname, icon='ZOOM_PREVIOUS')
    
        if tree_type != 'GeometryNodeTree':
            col.operator(NWReloadImages.bl_idname, icon='FILE_REFRESH')
    
        col.separator()
    
        col = layout.column(align=True)
        col.operator(NWFrameSelected.bl_idname, icon='STICKY_UVS_LOC')
        col.separator()
    
    
        col = layout.column(align=True)
    
        col.operator(NWAlignNodes.bl_idname, icon='CENTER_ONLY')
    
        col = layout.column(align=True)
        col.operator(NWDeleteUnused.bl_idname, icon='CANCEL')
        col.separator()
    
    
    class NodeWranglerPanel(Panel, NWBase):
        bl_idname = "NODE_PT_nw_node_wrangler"
    
        bl_space_type = 'NODE_EDITOR'
    
        bl_category = "Node Wrangler"
    
    Campbell Barton's avatar
    Campbell Barton committed
        prepend: StringProperty(
    
    Campbell Barton's avatar
    Campbell Barton committed
        append: StringProperty()
        remove: StringProperty()
    
    
        def draw(self, context):
    
            self.layout.label(text="(Quick access: Shift+W)")
    
            drawlayout(context, self.layout, mode='panel')
    
    #
    #  M E N U S
    #
    class NodeWranglerMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_node_wrangler_menu"
        bl_label = "Node Wrangler"
    
    
        def draw(self, context):
    
            self.layout.operator_context = 'INVOKE_DEFAULT'
    
            drawlayout(context, self.layout)
    
    
    class NWMergeNodesMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_merge_nodes_menu"
    
        bl_label = "Merge Selected Nodes"
    
        def draw(self, context):
            type = context.space_data.tree_type
            layout = self.layout
    
                layout.menu(NWMergeShadersMenu.bl_idname, text="Use Shaders")
    
            if type == 'GeometryNodeTree':
                layout.menu(NWMergeGeometryMenu.bl_idname, text="Use Geometry Nodes")
                layout.menu(NWMergeMathMenu.bl_idname, text="Use Math Nodes")
            else:
                layout.menu(NWMergeMixMenu.bl_idname, text="Use Mix Nodes")
                layout.menu(NWMergeMathMenu.bl_idname, text="Use Math Nodes")
                props = layout.operator(NWMergeNodes.bl_idname, text="Use Z-Combine Nodes")
                props.mode = 'MIX'
                props.merge_type = 'ZCOMBINE'
                props = layout.operator(NWMergeNodes.bl_idname, text="Use Alpha Over Nodes")
                props.mode = 'MIX'
                props.merge_type = 'ALPHAOVER'
    
    class NWMergeGeometryMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_merge_geometry_menu"
        bl_label = "Merge Selected Nodes using Geometry Nodes"
        def draw(self, context):
            layout = self.layout
            # The boolean node + Join Geometry node
            for type, name, description in geo_combine_operations:
                props = layout.operator(NWMergeNodes.bl_idname, text=name)
                props.mode = type
                props.merge_type = 'GEOMETRY'
    
    class NWMergeShadersMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_merge_shaders_menu"
    
        bl_label = "Merge Selected Nodes using Shaders"
    
        def draw(self, context):
            layout = self.layout
    
            for type in ('MIX', 'ADD'):
                props = layout.operator(NWMergeNodes.bl_idname, text=type)
    
                props.mode = type
                props.merge_type = 'SHADER'
    
    
    
    class NWMergeMixMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_merge_mix_menu"
    
        bl_label = "Merge Selected Nodes using Mix"
    
        def draw(self, context):
            layout = self.layout
            for type, name, description in blend_types:
    
                props = layout.operator(NWMergeNodes.bl_idname, text=name)
    
                props.mode = type
                props.merge_type = 'MIX'
    
    
    
    class NWConnectionListOutputs(Menu, NWBase):
        bl_idname = "NODE_MT_nw_connection_list_out"
        bl_label = "From:"
    
        def draw(self, context):
            layout = self.layout
            nodes, links = get_nodes_links(context)
    
            n1 = nodes[context.scene.NWLazySource]
    
            index=0
            for o in n1.outputs:
                # Only show sockets that are exposed. 
                if o.enabled:
    
                    layout.operator(NWCallInputsMenu.bl_idname, text=o.name, icon="RADIOBUT_OFF").from_socket=index
    
    
    
    class NWConnectionListInputs(Menu, NWBase):
        bl_idname = "NODE_MT_nw_connection_list_in"
        bl_label = "To:"
    
        def draw(self, context):
            layout = self.layout
            nodes, links = get_nodes_links(context)
    
            n2 = nodes[context.scene.NWLazyTarget]
    
            index = 0
            for i in n2.inputs:
    
                # Only show sockets that are exposed.
                # This prevents, for example, the scale value socket
                # of the vector math node being added to the list when
                # the mode is not 'SCALE'. 
                if i.enabled:
                    op = layout.operator(NWMakeLink.bl_idname, text=i.name, icon="FORWARD")
                    op.from_socket = context.scene.NWSourceSocket
                    op.to_socket = index
                    index+=1
    
    class NWMergeMathMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_merge_math_menu"
    
        bl_label = "Merge Selected Nodes using Math"
    
        def draw(self, context):
            layout = self.layout
            for type, name, description in operations:
    
                props = layout.operator(NWMergeNodes.bl_idname, text=name)
    
                props.mode = type
                props.merge_type = 'MATH'
    
    
    
    class NWBatchChangeNodesMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_batch_change_nodes_menu"
    
        bl_label = "Batch Change Selected Nodes"
    
        def draw(self, context):
            layout = self.layout
    
            layout.menu(NWBatchChangeBlendTypeMenu.bl_idname)
            layout.menu(NWBatchChangeOperationMenu.bl_idname)
    
    class NWBatchChangeBlendTypeMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_batch_change_blend_type_menu"
    
        bl_label = "Batch Change Blend Type"
    
        def draw(self, context):
            layout = self.layout
            for type, name, description in blend_types:
    
                props = layout.operator(NWBatchChangeNodes.bl_idname, text=name)
    
                props.blend_type = type
                props.operation = 'CURRENT'
    
    
    
    class NWBatchChangeOperationMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_batch_change_operation_menu"
    
        bl_label = "Batch Change Math Operation"
    
        def draw(self, context):
            layout = self.layout
            for type, name, description in operations:
    
                props = layout.operator(NWBatchChangeNodes.bl_idname, text=name)
    
                props.blend_type = 'CURRENT'
                props.operation = type
    
    
    
    class NWCopyToSelectedMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_copy_node_properties_menu"
    
        bl_label = "Copy to Selected"
    
        def draw(self, context):
            layout = self.layout
    
            layout.operator(NWCopySettings.bl_idname, text="Settings from Active")
            layout.menu(NWCopyLabelMenu.bl_idname)
    
    class NWCopyLabelMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_copy_label_menu"
    
        bl_label = "Copy Label"
    
        def draw(self, context):
            layout = self.layout
    
            layout.operator(NWCopyLabel.bl_idname, text="from Active Node's Label").option = 'FROM_ACTIVE'
            layout.operator(NWCopyLabel.bl_idname, text="from Linked Node's Label").option = 'FROM_NODE'
            layout.operator(NWCopyLabel.bl_idname, text="from Linked Output's Name").option = 'FROM_SOCKET'
    
    class NWAddReroutesMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_add_reroutes_menu"
    
        bl_label = "Add Reroutes"
        bl_description = "Add Reroute Nodes to Selected Nodes' Outputs"
    
        def draw(self, context):
            layout = self.layout
    
            layout.operator(NWAddReroutes.bl_idname, text="to All Outputs").option = 'ALL'
            layout.operator(NWAddReroutes.bl_idname, text="to Loose Outputs").option = 'LOOSE'
            layout.operator(NWAddReroutes.bl_idname, text="to Linked Outputs").option = 'LINKED'
    
    class NWLinkActiveToSelectedMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_link_active_to_selected_menu"
    
        bl_label = "Link Active to Selected"
    
        def draw(self, context):
            layout = self.layout
    
            layout.menu(NWLinkStandardMenu.bl_idname)
            layout.menu(NWLinkUseNodeNameMenu.bl_idname)
            layout.menu(NWLinkUseOutputsNamesMenu.bl_idname)
    
    class NWLinkStandardMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_link_standard_menu"
    
        bl_label = "To All Selected"
    
        def draw(self, context):
            layout = self.layout
    
            props = layout.operator(NWLinkActiveToSelected.bl_idname, text="Don't Replace Links")
    
            props.replace = False
            props.use_node_name = False
            props.use_outputs_names = False
    
            props = layout.operator(NWLinkActiveToSelected.bl_idname, text="Replace Links")
    
            props.replace = True
            props.use_node_name = False
            props.use_outputs_names = False
    
    
    
    class NWLinkUseNodeNameMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_link_use_node_name_menu"
    
        bl_label = "Use Node Name/Label"
    
        def draw(self, context):
            layout = self.layout
    
            props = layout.operator(NWLinkActiveToSelected.bl_idname, text="Don't Replace Links")
    
            props.replace = False
            props.use_node_name = True
            props.use_outputs_names = False
    
            props = layout.operator(NWLinkActiveToSelected.bl_idname, text="Replace Links")
    
            props.replace = True
            props.use_node_name = True
            props.use_outputs_names = False
    
    class NWLinkUseOutputsNamesMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_link_use_outputs_names_menu"
    
        bl_label = "Use Outputs Names"
    
        def draw(self, context):
            layout = self.layout
    
            props = layout.operator(NWLinkActiveToSelected.bl_idname, text="Don't Replace Links")
    
            props.replace = False
            props.use_node_name = False
            props.use_outputs_names = True
    
            props = layout.operator(NWLinkActiveToSelected.bl_idname, text="Replace Links")
    
            props.replace = True
            props.use_node_name = False
            props.use_outputs_names = True
    
    class NWVertColMenu(bpy.types.Menu):
        bl_idname = "NODE_MT_nw_node_vertex_color_menu"
        bl_label = "Vertex Colors"
    
        @classmethod
        def poll(cls, context):
    
            valid = False
            if nw_check(context):
                snode = context.space_data
    
                valid = snode.tree_type == 'ShaderNodeTree'
    
    
        def draw(self, context):
            l = self.layout
            nodes, links = get_nodes_links(context)
            mat = context.object.active_material
    
            objs = []
            for obj in bpy.data.objects:
                for slot in obj.material_slots:
                    if slot.material == mat:
                        objs.append(obj)
            vcols = []
            for obj in objs:
                if obj.data.vertex_colors:
                    for vcol in obj.data.vertex_colors:
                        vcols.append(vcol.name)
            vcols = list(set(vcols))  # get a unique list
    
            if vcols:
                for vcol in vcols:
                    l.operator(NWAddAttrNode.bl_idname, text=vcol).attr_name = vcol
            else:
    
                l.label(text="No Vertex Color layers on objects with this material")
    
    
    
    class NWSwitchNodeTypeMenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_node_type_menu"
        bl_label = "Switch Type to..."
    
        def draw(self, context):
            layout = self.layout
            tree = context.space_data.node_tree
            if tree.type == 'SHADER':
    
                layout.menu(NWSwitchShadersInputSubmenu.bl_idname)
                layout.menu(NWSwitchShadersOutputSubmenu.bl_idname)
                layout.menu(NWSwitchShadersShaderSubmenu.bl_idname)
                layout.menu(NWSwitchShadersTextureSubmenu.bl_idname)
                layout.menu(NWSwitchShadersColorSubmenu.bl_idname)
                layout.menu(NWSwitchShadersVectorSubmenu.bl_idname)
                layout.menu(NWSwitchShadersConverterSubmenu.bl_idname)
                layout.menu(NWSwitchShadersLayoutSubmenu.bl_idname)
    
            if tree.type == 'COMPOSITING':
                layout.menu(NWSwitchCompoInputSubmenu.bl_idname)
                layout.menu(NWSwitchCompoOutputSubmenu.bl_idname)
                layout.menu(NWSwitchCompoColorSubmenu.bl_idname)
                layout.menu(NWSwitchCompoConverterSubmenu.bl_idname)
                layout.menu(NWSwitchCompoFilterSubmenu.bl_idname)
                layout.menu(NWSwitchCompoVectorSubmenu.bl_idname)
                layout.menu(NWSwitchCompoMatteSubmenu.bl_idname)
                layout.menu(NWSwitchCompoDistortSubmenu.bl_idname)
                layout.menu(NWSwitchCompoLayoutSubmenu.bl_idname)
    
            if tree.type == 'TEXTURE':
                layout.menu(NWSwitchTexInputSubmenu.bl_idname)
                layout.menu(NWSwitchTexOutputSubmenu.bl_idname)
                layout.menu(NWSwitchTexColorSubmenu.bl_idname)
                layout.menu(NWSwitchTexPatternSubmenu.bl_idname)
                layout.menu(NWSwitchTexTexturesSubmenu.bl_idname)
                layout.menu(NWSwitchTexConverterSubmenu.bl_idname)
                layout.menu(NWSwitchTexDistortSubmenu.bl_idname)
                layout.menu(NWSwitchTexLayoutSubmenu.bl_idname)
    
            if tree.type == 'GEOMETRY':
                categories = [c for c in node_categories_iter(context)
                          if c.name not in ['Group', 'Script']]
                for cat in categories:
                    idname = f"NODE_MT_nw_switch_{cat.identifier}_submenu"
                    if hasattr(bpy.types, idname):
                        layout.menu(idname)
                    else:
                        layout.label(text="Unable to load altered node lists.")
                        layout.label(text="Please re-enable Node Wrangler.")
                        break
    
    
    
    class NWSwitchShadersInputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_input_submenu"
        bl_label = "Input"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_input_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchShadersOutputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_output_submenu"
        bl_label = "Output"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_output_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchShadersShaderSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_shader_submenu"
        bl_label = "Shader"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_shader_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchShadersTextureSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_texture_submenu"
        bl_label = "Texture"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_texture_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchShadersColorSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_color_submenu"
        bl_label = "Color"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_color_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchShadersVectorSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_vector_submenu"
        bl_label = "Vector"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_vector_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchShadersConverterSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_converter_submenu"
        bl_label = "Converter"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_converter_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchShadersLayoutSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_shaders_layout_submenu"
        bl_label = "Layout"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in shaders_layout_nodes_props:
    
                if node_type != 'FRAME':
    
                    props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                    props.to_type = ident
    
    
    class NWSwitchCompoInputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_input_submenu"
        bl_label = "Input"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_input_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoOutputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_output_submenu"
        bl_label = "Output"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_output_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoColorSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_color_submenu"
        bl_label = "Color"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_color_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoConverterSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_converter_submenu"
        bl_label = "Converter"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_converter_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoFilterSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_filter_submenu"
        bl_label = "Filter"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_filter_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoVectorSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_vector_submenu"
        bl_label = "Vector"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_vector_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoMatteSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_matte_submenu"
        bl_label = "Matte"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_matte_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoDistortSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_distort_submenu"
        bl_label = "Distort"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_distort_nodes_props:
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchCompoLayoutSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_compo_layout_submenu"
        bl_label = "Layout"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in compo_layout_nodes_props:
    
                if node_type != 'FRAME':
    
                    props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                    props.to_type = ident
    
    
    
    class NWSwitchMatInputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_mat_input_submenu"
        bl_label = "Input"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(blender_mat_input_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchMatOutputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_mat_output_submenu"
        bl_label = "Output"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(blender_mat_output_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchMatColorSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_mat_color_submenu"
        bl_label = "Color"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(blender_mat_color_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchMatVectorSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_mat_vector_submenu"
        bl_label = "Vector"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(blender_mat_vector_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchMatConverterSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_mat_converter_submenu"
        bl_label = "Converter"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(blender_mat_converter_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchMatLayoutSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_mat_layout_submenu"
        bl_label = "Layout"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(blender_mat_layout_nodes_props, key=lambda k: k[2]):
                if node_type != 'FRAME':
    
                    props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                    props.to_type = ident
    
    
    class NWSwitchTexInputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_input_submenu"
        bl_label = "Input"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_input_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchTexOutputSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_output_submenu"
        bl_label = "Output"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_output_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchTexColorSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_color_submenu"
        bl_label = "Color"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_color_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchTexPatternSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_pattern_submenu"
        bl_label = "Pattern"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_pattern_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchTexTexturesSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_textures_submenu"
        bl_label = "Textures"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_textures_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchTexConverterSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_converter_submenu"
        bl_label = "Converter"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_converter_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchTexDistortSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_distort_submenu"
        bl_label = "Distort"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_distort_nodes_props, key=lambda k: k[2]):
    
                props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                props.to_type = ident
    
    
    class NWSwitchTexLayoutSubmenu(Menu, NWBase):
        bl_idname = "NODE_MT_nw_switch_tex_layout_submenu"
        bl_label = "Layout"
    
        def draw(self, context):
            layout = self.layout
    
            for ident, node_type, rna_name in sorted(texture_layout_nodes_props, key=lambda k: k[2]):
                if node_type != 'FRAME':
    
                    props = layout.operator(NWSwitchNodeType.bl_idname, text=rna_name)
                    props.to_type = ident
    
    
    def draw_switch_category_submenu(self, context):
        layout = self.layout
        if self.category.name == 'Layout':
            for node in self.category.items(context):
                if node.nodetype != 'NodeFrame':
                    props = layout.operator(NWSwitchNodeType.bl_idname, text=node.label)
                    props.to_type = node.nodetype
        else:
            for node in self.category.items(context):
                props = layout.operator(NWSwitchNodeType.bl_idname, text=node.label)
                props.geo_to_type = node.nodetype
    
    
    def select_parent_children_buttons(self, context):