Additional Rhino 6 GhPython feedback

Yeah, it sounds like you are a pretty advanced user. I am learning each of these techniques and I’m sure I will find ways to work around this problem as I move forward… but the point is that I am dancing around something here. The console used to be able to handle this in light and reliable way (in Rhino 5) and it doesn’t do that any more.

2 Likes

I know that @Alain has been working on improving the print output editor in a way that addressed your concerns. In Rhino 7 BETA, you can now choose to print the output as simple text. Also, copy-paste should now be simpler. I specifically asked this to be shipped with Rhino 7 SR0.

The default type hint was deliberately left as rhinoscriptsyntax. You can create your own defaults for this using a Grasshopper User Object. A GHUO can store default code, default type hints and default variable names both for input and outputs. It also stores the default window position and a few other minor settings. It stores also SDK mode ON/OFF. We can have it store more stuff if you need. Personally, maybe I’d like it to store font size.

2 Likes

That’s fantastic news! I only just quickly tested the Rhino 7 Beta and must have missed this. Many many apologies, should have looked closer. And setting this option appears to be persistent, again this is just awesome guys :clap:

Whoaah, that sounds like great news as well. How does that work when adding new input parameters via ZUI?

Also only just noticed AutoSolve :open_mouth:

In Rhino 6 you can replace the output as well. In case the DataGrid is the bottleneck here. In theory you can replace the label with any other usercontrol.

Here is a quick proof of concept. (It replaces the output grid with a simple text label)

import System.Reflection as rf
import System.Windows.Forms as forms

def print_ex(line):
    editor = ghdoc.Component.Attributes.Form
    outputPage = editor.GetType().GetField("outputPage", rf.BindingFlags.NonPublic | rf.BindingFlags.Instance).GetValue(editor);
    label = forms.Label()
    label.Text = line
    outputPage.Controls.Clear()
    outputPage.Controls.Add(label)
    outputPage.SuspendLayout();

print_ex("foobar")

The reflection call could be made only once per script execution, since this will be a potential bottleneck.

@AndersDeleuran @Alexander_Jacobson

Here is the workaround for RH6. Works extremly fast compared to the inbuild one. Give it a try. Of course its visible to the user, and I spend no time in making it more reliable or nice. But see it as quick solution.

"""Provides a scripting component.
    Inputs:
        x: The x script variable
        y: The y script variable
    Output:
        a: The a output variable"""

__author__ = "tomja"
__version__ = "2020.10.14"

import rhinoscriptsyntax as rs

from System.Text import StringBuilder
import System.String as ss
import System.Reflection as rf
import System.Windows.Forms as forms

outputPage = None
textBox = None
printdata = StringBuilder()
def print_f(line):
    global outputPage, textBox    
    if (outputPage == None and textBox == None):
        editor = ghdoc.Component.Attributes.Form
        outputPage = editor.GetType().GetField("outputPage", rf.BindingFlags.NonPublic | rf.BindingFlags.Instance).GetValue(editor);
        outputPage.Controls.Clear()
        textBox = forms.TextBox()
        textBox.Width = 1200
        textBox.Height = 200
        textBox.Multiline = True
        textBox.ScrollBars = forms.ScrollBars.Vertical
        textBox.AcceptsReturn = True
        textBox.AcceptsTab = True
        textBox.WordWrap = True
        outputPage.Controls.Add(textBox)
        outputPage.SuspendLayout()
        
    printdata.Append(line)

# Your code goes in here
for i in range(0,100000):
    print_f("test \r\n") 


# Add to the output before the script terminates
textBox.Text = printdata.ToString()
3 Likes