I have a lot of grasshopper files with text panels which i would like to modify using a simple CLI app (rather than opening each file)
I hope to change:
- colour
- font
- text size
- text
- nickname
Is this possible?
GH_IO.dll appears to provide the necessary infrastructure to do this, however i haven’t been able to successfully actually modify a gh file.
I can access the information i care about thanks to davids help here https://discourse.mcneel.com/t/get-grasshopper-document-object-count-without-opening-grasshopper/78311/4
A simple example of what i’m trying to achieve is this:
convert:

to

1.start.gh (1.9 KB) 3.desired.gh (1.6 KB)
My attempt so far reads the panel colour, font and text size, but only writes a copy of the existing file
Program.cs (4.5 KB)
@DavidRutten Do you have an example of this kind of modification?
private static void ShowPanelData(GH_Archive archive)
{
int missing = 0;
var root = archive.GetRootNode;
var definition = root.FindChunk("Definition");
var objects = definition.FindChunk("DefinitionObjects");
var count = objects.GetInt32("ObjectCount");
for (int i = 0; i < count; i++)
{
var chunk = objects.FindChunk("Object", i);
if (chunk is null)
missing++;
else
{
var name = chunk.GetString("Name");
if (name == "Panel")
{
var container = chunk.FindChunk("Container");
var properties = container.FindChunk("PanelProperties");
var nickName = container.GetString("NickName");
var userText = container.GetString("UserText");
var colour = properties.GetDrawingColor("Colour");
var font = properties.FindChunk("Font");
var fontFamily = font.GetString("Family");
var fontSize = font.GetSingle("Size");
string panel = string.Format("Panel({0}, {1}, {2}, {3}, {4})", nickName, colour, fontFamily, fontSize, userText);
WriteLine(ConsoleColor.Gray, panel);
fontSize = 6;
Console.WriteLine();
}
}
}