Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions node_to_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,62 @@ def create_main():
file.close()
return {'FINISHED'}

class NodeToPythonMenu(bpy.types.Menu):
bl_idname = "NodeToPythonMenu"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: bpy documentation recommends something like "NODE_MT_node_to_python" for the bl_idname

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would need to replace reference in line 507 as well

bl_label = ""

@classmethod
def poll(cls, context):
return not (False)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: return True


def draw(self, context):
geo_node_groups = [node for node in bpy.data.node_groups if node.type == 'GEOMETRY']

layout = self.layout.column_flow(columns=1)
layout.operator_context = "INVOKE_DEFAULT"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: use single-quotes for enum INVOKE_DEFAULT

for i in range(len(geo_node_groups)):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: use something like for geo_ng in geo_node_groups: instead of iterating through the indices and accessing each element of the list

op = layout.operator(NodeToPython.bl_idname, text=geo_node_groups[i].name)
op.node_group_name = geo_node_groups[i].name

class NodeToPythonPanel(bpy.types.Panel):
bl_label = 'Node To Python'
bl_idname = 'NodeToPythonPanel'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: bl_idname should be something like NODE_PT_node_to_python

bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_context = ''
bl_category = 'NodeToPython'

@classmethod
def poll(cls, context):
return not (False)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: return True


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

def draw(self, context):
geo_node_groups_exist = len([node for node in bpy.data.node_groups if node.type == 'GEOMETRY']) > 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: would move this logic closer to the row.enabled line. would be a little more legible if we make this list its own variable like in the menu class

menu_text = 'Nodes'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: would use "Geometry Node Groups" instead, double-quotes for non-enum strings. it's simple enough where I'd just explicitly set the text in the row.menu() line


layout = self.layout
col = layout.column()
row = col.row()
row.enabled = geo_node_groups_exist # Disables menu when len of geometry nodes is 0
row.alignment = 'Expand'.upper()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: just 'EXPAND' here

row.operator_context = "INVOKE_DEFAULT" if True else "EXEC_DEFAULT"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: just 'INVOKE_DEFAULT'

row.menu('NodeToPythonMenu', text=menu_text)

def menu_func(self, context):
self.layout.operator(NodeToPython.bl_idname, text=NodeToPython.bl_label)

def register():
bpy.utils.register_class(NodeToPythonMenu)
bpy.utils.register_class(NodeToPythonPanel)
bpy.utils.register_class(NodeToPython)
bpy.types.VIEW3D_MT_object.append(menu_func)

def unregister():
bpy.utils.unregister_class(NodeToPythonMenu)
bpy.utils.unregister_class(NodeToPythonPanel)
bpy.utils.unregister_class(NodeToPython)
bpy.types.VIEW3D_MT_object.remove(menu_func)

Expand Down