Find and Replace in Grasshopper Documents

04Feb12

Warning: Serious GH geekery ahead.

 

Since David Rutten added to GH the ability to set a default text panel background color, I’ve had my panels set to be white instead of the default bright yellow. But in all my old definitions, the panels remain yellow, and it drives me nuts. I was going through and changing them manually when it occurred to me that there was a much better way.

In a given definition, you can copy and paste all the components, and paste them into a text document. This gives you the XML representation of your definition, which contains all components, properties, and connections. I then hunted for the code that represented the background color of a text panel:

<item name="CustomBackColour" type_name="gh_drawing_color" type_code="36">
<ARGB>255;255;250;90</ARGB>

I then did a find and replace to switch out 255;255;250;90 with 255;255;255;255, a nice clean white. Copying all the text and pasting back into the GH definition converts everything back into components.

 

Moreover, if your definitions are saved in GHX format (which used to be the default), you can actually open them directly in a text editor and do the same thing (although note that older GHX’s may have slightly different code than you get from copying and pasting components from an open definition with the latest version of GH). The power of this is that, if you have a folder of GHX documents, you can do a batch find and replace and change some property across all the documents. Voila, no more yellow text panels in my old definitions.

 

This technique could easily extend to other properties and other components; with some clever find-and-replace, you could add margins to all your text panels, change the color of groups or scribbles, and if you’re able to find and replace with wildcards or regular expressions, even more complicated things are possible, such as setting the value of all sliders in a document to 0.0.

A word of warning: it is very easy to screw up your definition this way! I take no responsibility if your find-and-replacing results in the breaking of your definition. If the XML is not very precisely formed, pasting it into Grasshopper will not work at all.

Advertisements


No Responses Yet to “Find and Replace in Grasshopper Documents”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: