Access GH_Transform type from C# Script component

Hi there!

High-level question: is there any way to access GH_Goo types in C# Script components before they get converted to other types on inputs via the ScriptVariable?

Description: Probably a silly question, but I am blanking out. I am writing a C# Script component (must be so, cannot be a compiled one) and I want to access the history of transforms for a Transform object using GH_Transform.CompoundTransforms (as I guess the native Split component does). If the input type is set to Transform, then I lose that history as a I get the flat 4x4 matrix without the history. If I use a generic object:

  private void RunScript(System.Object T, ref object X)

    GH_Transform xform = T as GH_Transform;
    if (xform == null) {
    else {

…it stringifies to a Transform, but the cast fails:

My guess here is that the object gets “flattened” to a Transform as it enters the C# Script, before being further “flattened” to an object? Is there any way to access the original GH_Transform at this point?


No, almost all goo types will cast themselves to a ‘script safe’ type before they are even handed to the script assembly. I’m afraid you’ll need to create a component using Visual Studio.

If it has to be within a script component, you could still iterate over the inputs and access the volatile/persistent data?

GH_Structure<IGH_Goo> volatileData = this.Component.Params.Input[0].VolatileData as GH_Structure<IGH_Goo>;

foreach (IGH_Goo item in volatileData)
  GH_Transform xForm = item as GH_Transform;

  if (xForm != null)
    // Do something

No idea how to make that foolproof, but you can get the GH_Transform and its properties.

You can process VolatileData yourself, but you may lose the convenience of item/list access.

If the performance is not an issue, you can rebuild GH_Transform from Transform type, which is the real type you get. Just use var transform = new GH_Transform(T as Transform)

Well yes, you could do that. But using VS is sounding more and more attractive now…

Agreed, this is for sure an ugly solution with a lot of potential errors, but under the premise “has to be a script component, cannot be compiled” it would be an option :wink:

Thank you @dsonntag, that actually works pretty well. It is true that it feels flimsy, but it does the trick under the premise :slight_smile: