Display Conduit inside Grasshopper c# / component


the intro:
i am trying to draw custom previews in rhino using c# (just points now, just to get started).
because i want to handle a very large amount of data i want to use an ECS (entity component system).
i have now chosen default ECS( GitHub - Doraku/DefaultEcs: Entity Component System framework aiming for syntax and usage simplicity with maximum performance for game development.), because i have gotten it to run on .net framework 4.8, all the other ones use a newer framework. (i am still running in rhino 7, because the c# component in rhino 8 is too buggy)

the problem:
i have tried to make a custom display conduit using the examples and explanation of:


but as soon as i build any of these to a dll i don’t see them in the viewport.
i guess this is because i am building to a .gha, which i then load into a grasshopper component, and type using… and then the namespace.
Any idea on how i can ‘activate’ this displayconduit from within a grasshopper component?

solutions i thought about
i don’t think i can use the standard grasshopper preview (/conduit) because i want to create mouse-over effects… so hover the mouse over meshes, and they get selected using a mesh-ray intersection.
Because i have a very large amount of complex data, i am using the ECS to preselect the meshes that are used for mouse-intersection detection, otherwise it would get too slow.
i have gotten the selection process working, indexing the right mesh, but previewing which mesh has been selected is what i can’t get working now.

code i tried
i don’t think it is really helpful if i paste code here, because for the display conduit i have only used the developer examples from rhino for now. nothing custom yet. but even the simplest examples like this one don’t work because i am not making a rhino plugin but want it to be loaded from grasshopper.
class MyConduit : Rhino.Display.DisplayConduit
protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e)
var bbox = new BoundingBox();
bbox.Union(new Point3d(0, 0, 0));

protected override void PreDrawObjects(DrawEventArgs e)
e.Display.DrawPoint(new Point3d(0, 0, 0));

any help would be greatly appreciated.

Before you go any deeper, are you aware of the built-in GH_Component DrawViewportMeshes and DrawViewportWires methods?

Hi AndresDeleuran,

thanks for your quick reply.
Yes i have toyed around with DrawViewportWires and Meshes.
i think i cannot use it because i can only run DrawViewPortWires from a C# component, but i want the preview to be updated on mouse movements, so not only when the SolveInstance() or RunScript() methods are triggered, but as soon as a mouse callback event is recieved.

But maybe you are right, and i should try working with DrawViewPortWires a bit more. It just feels a bit strange to use grasshopper to preview the meshes when the simulation i am running lives rather independently in it’s own class, so it is not directly tied to a component. i was hoping to use the displayconduit directly because that feels like it would be faster.

the other issue i run into with DrawViewPortWires is ECS related… as the ECS scrolls through the memory looking for objects to preview, it uses Span. this type is not supported by the grasshopper C# component. so if i have a method to select and preview a mesh, that should live in its own class (in .net framework 4.8 + .net standard 2.0) and store it in a static property, so it can then be access by the C# component for visualisation.

While these examples are written in GHPython, they do demonstrate how to implement mouse events for dynamically drawing stuff. It might help:

Should be very similar in C#, whether compiled or in a scripting component.

Hey Anders Deleuran,

Thanks for the example…
looks like it will serve me well. I don’t know python, but it looks like it does what i need.

I also tested the other suggestion you made with DrawViewportMeshes, and it works great. i was under the wrong impression that this would work like a preview (turn green when component is selected). So thanks again for pointing that out.

1 Like