GH Versioning


I would like to output in ShapeDiver my GH file version :

It’s working great !

my custom ‘GH version output’ C# Script :

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using System.Text.RegularExpressions;

/// <summary>
/// This class will be instantiated on demand by the Script component.
/// </summary>
public class Script_Instance : GH_ScriptInstance
#region Utility functions
  /// <summary>Print a String to the [Out] Parameter of the Script component.</summary>
  /// <param name="text">String to print.</param>
  private void Print(string text) { /* Implementation hidden. */ }
  /// <summary>Print a formatted String to the [Out] Parameter of the Script component.</summary>
  /// <param name="format">String format.</param>
  /// <param name="args">Formatting parameters.</param>
  private void Print(string format, params object[] args) { /* Implementation hidden. */ }
  /// <summary>Print useful information about an object instance to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj) { /* Implementation hidden. */ }
  /// <summary>Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component. </summary>
  /// <param name="obj">Object instance to parse.</param>
  private void Reflect(object obj, string method_name) { /* Implementation hidden. */ }

#region Members
  /// <summary>Gets the current Rhino document.</summary>
  private readonly RhinoDoc RhinoDocument;
  /// <summary>Gets the Grasshopper document that owns this script.</summary>
  private readonly GH_Document GrasshopperDocument;
  /// <summary>Gets the Grasshopper script component that owns this script.</summary>
  private readonly IGH_Component Component;
  /// <summary>
  /// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
  /// Any subsequent call within the same solution will increment the Iteration count.
  /// </summary>
  private readonly int Iteration;

  /// <summary>
  /// This procedure contains the user code. Input parameters are provided as regular arguments,
  /// Output parameters as ref arguments. You don't have to assign output parameters,
  /// they will have a default value.
  /// </summary>
  private void RunScript(ref object version)
    var ghdoc = this.GrasshopperDocument;

    if (ghdoc != null)
      var filename = ghdoc.DisplayName;
      //Print("Nom du fichier: " + filename); // Afficher le nom du fichier

      var versionMatch = Regex.Match(filename, @"v(\d+\.\d+)");

      if (versionMatch.Success)
        version = versionMatch.Groups[1].Value;
        //Print("Aucun numéro de version trouvé dans le nom du fichier");
        version = "?";
      //Print("Aucun document Grasshopper actif");
      version = "?";

  // <Custom additional code> 

  // </Custom additional code> 

A previous upload with human validation for this script works once.

But now, i get this upload error :

Any tips please ?

Looking at the script, it doesn’t do harmful things and therefore could be confirmed. You could do a small modification to it (e.g. change a variable name), upload the model again, and we will confirm the script.

However, be aware that the filename of your model (and therefore the value of GH_Document.DisplayName) is not the original filename of the model you uploaded to ShapeDiver. This filename is based on the unique id our backend system assigns to your model. An example: Your script which tries to extract a version identifier from your filename is therefore going to fail.

As an alternative you could bake your version number into the Grasshopper model.

Note that we do store the original filenames of uploaded models, such that we can set the original filename when a user wants to download one of her Grasshopper models again.

Thanks Alexander for your reply. In this case, I’ll store app version manually, directly in a panel inside GH.