Arbitrary debug output for grasshopper compo

Hi all,

I’m fairly new to grasshopper component development. I am trying to set arbitrary geometric or non-geometric objects as “debug outputs” of my components. This is to be used only through the development of the component.

What I have at the moment is a Generic parameter registered as below:

pManager.AddGenericParameter("Debug", "D", "Debug results.", GH_ParamAccess.list);

and a public property like this:

public object DebugOutputs { get; set; }

So for example I set the property to something arbitrarily like this:

// unionBlocks is a List<PolylineCurve>
DebugOutputs = unionBlocks;

which I pass to output of the component like this:

DA.SetData(1, solution.DebugOutputs);

On the grasshopper canvas then I have a separate C# component that casts the object to different things and outputs the results based on the object type. Something like this:

    private void RunScript(object x, object y, ref object a)
    {
        if(x is IList){

            var type = x.GetType();
            if (type.GetGenericArguments()[0] == typeof(PolylineCurve))
            {
                var list = x as List<PolylineCurve>;
                a = new DataTree<PolylineCurve>(list);
            }
            // so on and so forth
        }
        else
        {
            // get the type and cast it 
        }

    }

Before I go ahead and complete the code, I was wondering if there’s any better way for this already using vanilla grasshopper? I’ve looked at the GH_GeometricGoo class but that seems not quite the solution as the debug outputs can arbitrarily change (eg: polylines, points, meshes etc)

Thanks.
Hoss

As long as its about displaying geometrical data you could use pManager.AddGeometryParameter()
But note that some types do not derive from GeometryBase such as planes.

In general I think its not a good idea to implement something like this. Because you could introduce errors, which might have nothing in common with your implementation, but with the cast/conversion.

GH VS templates are designed not differ in between Debug and Release. I think this is a disadvantage.
So instead of using the DEBUG define you can create an own and do something like this:

// Comment out if not required (you can also define from the build command).
#define DEVOUT

#if DEVOUT
// Register parameters only for development
//pManager.Add(...)
//pManager.Add(...)
//pManager.Add(...)
#endif
// ...
#if DEVOUT
//DA.SetData(...)
//DA.SetData(...)
//DA.SetData(...)
#endif

If you wonder why this is better than an normal if and else, then the answer is that it only compiles if the flag is defined. But I would be careful and minimise using pre-processor directives, because you always want to test you production code, and not the test environment.