Skip to content

Added quick dropdown menu - #26

Merged
BrendanParmer merged 1 commit into
BrendanParmer:v2.0from
carls3d:main
Jan 3, 2023
Merged

BrendanParmer merged 1 commit into
BrendanParmer:v2.0from
carls3d:main

Conversation

@carls3d

@carls3d carls3d commented Jan 2, 2023

Copy link
Copy Markdown
Contributor

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

@BrendanParmer BrendanParmer left a comment

Copy link
Copy Markdown
Owner

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!

Comment thread node_to_python.py
return {'FINISHED'}

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

Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread node_to_python.py

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

style: return True

Comment thread node_to_python.py
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
Copy Markdown
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

Comment thread node_to_python.py

layout = self.layout.column_flow(columns=1)
layout.operator_context = "INVOKE_DEFAULT"
for i in range(len(geo_node_groups)):

Copy link
Copy Markdown
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

Comment thread node_to_python.py

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

Copy link
Copy Markdown
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

Comment thread node_to_python.py

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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

style: return True

Comment thread node_to_python.py
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
Copy Markdown
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

Comment thread node_to_python.py
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
Copy Markdown
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

Comment thread node_to_python.py

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
Copy Markdown
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

Comment thread node_to_python.py
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
Copy Markdown
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