Skip to content

Conversation

carls3d
Copy link
Contributor

@carls3d carls3d commented Jan 2, 2023

Added a dropdown menu to easily choose which node tree to convert.

Located in a new panel 'Node To Python' in the nodes space

Added a dropdown menu for choosing which node tree to convert.

Located in a new panel 'Node To Python' in the nodes space
@BrendanParmer BrendanParmer changed the base branch from main to v2.0 January 2, 2023 23:51
@BrendanParmer BrendanParmer self-assigned this Jan 2, 2023
@BrendanParmer BrendanParmer added the enhancement New feature or request label Jan 2, 2023
@BrendanParmer BrendanParmer added this to the v2.0 milestone Jan 2, 2023
Copy link
Owner

@BrendanParmer BrendanParmer left a comment

Choose a reason for hiding this comment

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

Awesome stuff! This is just what I was envisioning for the UI.

I've only got a few stylistic concerns, but I'm comfortable replacing the old system with this. I'll go ahead and make a few tweaks I outlined here

Thanks for your contribution!

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


@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

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


layout = self.layout.column_flow(columns=1)
layout.operator_context = "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


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


@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

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

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


def draw(self, context):
geo_node_groups_exist = len([node for node in bpy.data.node_groups if node.type == 'GEOMETRY']) > 0
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

row = col.row()
row.enabled = geo_node_groups_exist # Disables menu when len of geometry nodes is 0
row.alignment = 'Expand'.upper()
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'

@BrendanParmer BrendanParmer merged commit 0afc4e2 into BrendanParmer:v2.0 Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants