Unable to process blocks


My level of knowledge in c# is quite like " seen and understood" Long Nguyens super videos and the few others on the net.

i seem to have trouble getting any block instances into the grasshopper c# component.

I have tried with the system.object type hint (as all the others gave me errors), and then tried with Print(inputList[i].ToString); and it gave me a List of “objectInstance”. But as I want to use InstanceObject commands, they wouldn’t be valid for the type object. e.g. inputList[i].Geometry

I then tried with visual Studio, but pManager doesn’t propose anything that looks good to me, neither.

I am trying to get the brep out of the block (and all the other informations)
What am I missing? I really tried about two days to find an example in the net, but wasn’t successful.

thank you in advance


Hi @benedict,

To work with none-gh-types in gh components you an use the pManager.AddGenericParameter() function.

Something like this:

// inside of RegisterOutputParams
pManager.AddGenericParameter("Parent Block", "B", "Block of which this is a reference",GH_ParamAccess.item);

// inside of SolveInstance
InstanceReferenceGeometry reference = null;
if (!DA.GetData(0, ref reference)) return;

Also here is the full working source code of two of my components, doing what i think you want to achieve, One works on BlockDefinitions and the other on InstanceReferences:

DeconstructBlock.cs (3.3 KB) DeconstructBlockReference.cs (3.4 KB)

Let me know if you have any more questions :slight_smile:


Hi @lando.schumpich

thank you very much, it’s exactly what I’ve been looking for! Great!

you may regret have said that=) I have sooooo many questions, haha!

Hey @lando.schumpich

here’s already my second question.
to understand your code and the exact values it returns, I just copied the code and made exactly your element. I got a “Invalid cast. Elefront Block >> InstanceReferenecGeometry” error.
How would I get the Block into Grasshopper without the elefront extended geometry block element?

Thank you in advance


Well that really depends, Blokcs only live in the Rhino doc, so you need some way to get them out of there. I just fetch the blocks via their names from the doc:

        protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
            pManager.AddTextParameter("Name", "N", "Name of block to get", GH_ParamAccess.list);

        protected override void SolveInstance(IGH_DataAccess DA)
            List<string> names = new List<string>();

            if (!DA.GetDataList(0, names)) return;

            List<InstanceDefinition> blockDefinitions = new List<InstanceDefinition>();
            RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;

            foreach (var name in names)
                var blockDefinition = doc.InstanceDefinitions.Find(name);
                if (blockDefinition is null) break;
1 Like

Wow, hw fast you aswer. Thanks! I’ll have a look at that!