Python output node allow copy-past, format as text by default

# PY-DIALOG-TEXT-COPY.PY import clr clr.AddReference('System.Windows.Forms') clr.AddReference('System.Drawing') from System.Windows.Forms import Form, TextBox, Button, DockStyle, FormBorderStyle, ScrollBars from System.Drawing import Size, Font import System.Windows.Forms as WinForms # Input from Dynamo input_data = IN[0] if IN[0] is not None else "" format_flag = IN[1] if len(IN) > 1 else False # Format a deeply nested list as indented text def format_nested_list(data, indent=0): result = [] prefix = " " * indent if isinstance(data, list): for item in data: result.extend(format_nested_list(item, indent + 1)) else: result.append(f"{prefix}- {data}") return result # Format flat list of strings with "→" indentation and _MWE sub-items def format_dry_run_list(data): result = [] for item in data: if "→" in item: left, right = item.split("→", 1) result.append(f"- {left.strip()}") components = [comp.strip() for comp in right.strip().split('_MWE')] for comp in components: result.append(f" → {comp.strip('- ')}") result.append("") else: result.append(f"- {item.strip()}") result.append("") return "\r\n".join(result) # CRLF line endings for proper rendering # Determine formatting mode if isinstance(input_data, list): if format_flag: display_text = format_dry_run_list(input_data) else: display_text = "\r\n".join(format_nested_list(input_data)) else: display_text = str(input_data) # Create the Form form = Form() form.Text = "Output Viewer" form.Size = Size(600, 400) form.FormBorderStyle = FormBorderStyle.Sizable form.StartPosition = WinForms.FormStartPosition.CenterScreen # TextBox textbox = TextBox() textbox.Multiline = True textbox.ReadOnly = False textbox.ScrollBars = ScrollBars.Both textbox.Dock = DockStyle.Fill textbox.Text = display_text textbox.ShortcutsEnabled = True textbox.Font = Font("Consolas", 10) # Monospaced font # Close Button close_button = Button() close_button.Text = "Close" close_button.Dock = DockStyle.Bottom close_button.Height = 30 def on_close(sender, args): form.Close() close_button.Click += on_close # Add controls form.Controls.Add(textbox) form.Controls.Add(close_button) # Show the form form.ShowDialog() # Return original input OUT = input_data

Comments

Popular posts from this blog

Revit CSV file manager for families and re-exporting to a CSV file

Revit area plans adding new types and references (Gross and rentable)