Grasshopper

algorithmic modeling for Rhino

Find and Replace in Grasshopper Documents

originally posted here

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, based on a trick I saw David mention in a troubleshooting post way back. 

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.

Views: 1403

Comment

You need to be a member of Grasshopper to add comments!

Comment by William Carroll on June 11, 2015 at 12:32pm

This is fantastic. Surprised no one ever commented on this... I am expecting a book on RegExs to come in the mail soon, hopefully to extend my currently limited knowledge on this topic. Might get around to some experimenting with this idea, so if anything interesting crops up, I'll post it here. Thanks

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service