New: GhToGhx - A Tool for Converting and Compressing Grasshopper Files

I made CommandLine a tool for converting Grasshopper files (.gh) to xml (.ghx) with the option to compress the xml file to GZip. In this way the gh files can be made “searchable” (converting entire folder structures in one go). This tool has proved to be useful for me and I thought I’d share the tool with the community, including sources. (download links below)

Ghx files (xml) are suitable for storing in version control systems (VCS) and DIFF tools can spot differences between versions. Some search tools can scan zipped files directly (for example Powergrep), and therefore I added a command to GZip the xml files as well (the tool’s commands operates recursively on folderstructures starting from a folder provided as a first argument when starting the program)

The latest release of a compiled exe file can be downloaded [edit:] from BitBucket Downloads page
Howto: Drop the file anywhere on your harddisk, and remove the file extension (it’s a fake extension), and also place your own copy of the file GH_IO.dll in the same folder as the exe file, and then it should simply work). The source files are available at Bitbucket GhToGhx.

The tool can also be used interactively (pictured), or called from a batch script, see example bat-file here below (again, remove the fake .txt extension. Also replace all the paths inside the bat-file with your own):
batchrun_ghtoghx.bat.txt (1.7 KB)

Fig 1. Command Line options always shown. More info and screenshots will soon be uploaded to Bitbucket GhToGhx (The info there is not updated, but will be soon):

See also a previous post on the subject:

Batch Mode
Below a list of commands that can be run in batch (or manually via the Console as pictured above). What it does; It:

  1. Converts all .gh files in a specified folder - and its sub-folders - to ghx format and places them in a temp folder (…\_ghx) under respective file’s path. (cmd X)
    This folder can then be removed if the ghx file isn’t needed anymore (cmd R).
    If the .gh file has a twin .ghx file it will not be converted, nor does the Remove R command touch it in any way.

  2. Compresses all .gh files in a given folder - and its sub-folders - into GZip format (filename .ghx.gz) and places them in a temp folder (…\_gzip) under respective .gh file’s path. (cmd Z)
    This folder can then be removed if the ghx file isn’t needed anymore.
    The corresponding Remove r command doesn’t touch any other .gzip files than those it has created itself.

  3. Lists all files and folders and saves the output into logfiles on disk. (cmd g, x, z and d)

  4. Deletes all Converted (cmd R) and Compressed files (cmd r) and corresponding temp-folders.

  5. Deletes the log files. (cmd C)

    REM ---------------------------------------------------------------------------------
    REM Prefix “+” means verbose (console display)
    REM Prefix “-” means !verbose (no or very little console display)
    REM Postfix “L” means = Do log to file
    REM g means List regular .gh files
    REM X means Convert to .ghx (xml) format
    REM x means List ghx files
    REM Z means Compress to .ghx.gz (GZip) format
    REM z means List compressed files
    REM d means List temp directories for ghx and gzip files
    REM ---------------------------------------------------------------------------------

    REM - LOG regular Grasshopper files (.gh)
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +gL
    REM - CREATE Xml versions (ghx)
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +XL
    REM - CREATE compressed GZip versions (gzip)
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +ZL
    REM - LOG ghx file-lists to disk
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +xL
    REM - LOG GZip file-lists to disk
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +zL
    REM - LOG Ghx and GZip foldername lists to disk
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +dL
    REM - REMOVE ghx folders and files (“L” doesn’t play any role here)
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +R
    REM - REMOVE GZip folders and files
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +r
    REM - CLEAR Log files
    .\ghtoghx.exe D:\DEV\CAD\GH\GH_Workbench__ScriptComponents\CScriptComponents.ghx +C?

Let me know if you need more features.

// Rolf


A new release of the GhToGhx conversion tool is available for download (latest is GhToGhx 1.1.6.exe).

Noteworthy: The tool does not modify any original files, it only makes copies into sub-folders.


The Wiki has documentation for every command (also some not visible in the menu)


// 1.1.6: Enhancement: ColorTheme(s) made changeable via CommandLine or Console Window (pick theme with digit 0, 1, or 2).
// 1.1.5: Refactoring. Dedicated write methods for Folder paths and Filenames. ColorTheme extended. Introduced Xml Documentation with GhostDoc). Fixed isse #4 (scrambled display of temp-paths).
// 1.1.4: Heavy refactoring, move entire app content to a separate class. Introduced XUnit Test, and ColorTheme.
// 1.0.3: Added options to hide menu ("m" toggle) and menu-header ("h" toggle). Separated drawing of menu to Draw methods. Version info in header.
// 1.0.2: Fixed erroneous log message in command for removing temp folders (_gzip was reported as _ghx)


// Rolf

1 Like

This looks great thanks, though I think it maybe better in Grasshopper than Gallery Category
If it could be made a pinned post too so it does not get lost that would help.