you’ll have to override the DrawViewportWires and/or DrawViewportMeshes on your GH_Component derived class. This means you’ll have to exactly duplicate the existing functionality for those parameters you don’t want to change and provide alternative functionality for those you do want to change.
Do note that there’s nothing you can do to make a line parameter draw arrowheads, all you can do is change the colour and thickness of all the lines. If you want more advanced preview or have per-line control, then I recommend you simply set the output Line parameter to Hidden=true and keep a separate list of preview data inside your component.
Just to be sure, you’re doing this in C# and Visual Studio? Or are you working in the scripting components?
wow this is awesome! I was just about to ask about the output parameter.
This clarifies it. Thanks a lot!
I’m encountering another issue, I don’t really understand. I have a loop in my SolveInstance, during which the lines change (it’s a FFD fast fluid dynamics solver). but instead of replacing the grasshopper-lines, they are being added to the output list in every iteration:
while (true)
{
if (f.checkBox1.Checked == true)
{
doc.NewSolution(false);
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
Rhino.RhinoApp.Wait();
t += dt;
ffd.time_step();
List<Line> velolist = new List<Line>();
for (int i = 0; i < Nx; i++)
{
for (int u = 0; u < Ny; u++)
{
double[] vel = de.get_velocity((i - 0.5) * omega.hx, (u - 0.5) * omega.hy, (5 - 0.5) * omega.hz);
Line arrowlines = new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(i * omega.hx, u * omega.hy, 5 * omega.hz),
new Vector3d(vel[0], vel[1], vel[2]));
velolist.Add(arrowlines);
}
}
DA.SetDataList(0, velolist);
}
else
{
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
Rhino.RhinoApp.Wait();
}
}
If I set doc.NewSolution(true); then no lines are drawn.
I also get the “Grasshopper Breakpoint - An object expired during a solution”- error, which I just click away. But probably that already gives me a hint, that my general code setup is not as it should be?
actually I think, your code example also answeres my new question.
I would just call DA.SetDataList(lines) once in solveInstance, after that in my infinite loop I just change _lines, _width, _colors etc. and the overridden DrawViewportWires does the rest.
I’m really sorry to ask again but I just can’t figure out how to implement the dynamic redraw.
What I try to achieve is something similar to Processing, where it’s
public void draw(){ }
is being called forever, until you close the app.
Am I right, that in order to get the same in Grasshopper, I would need to call
SolveInstance(){ }
in an infinite loop?
My current attempt is, that within SolveInstance I have a separate class which would then draw Rhino.Geometry and refresh the viewport during the iterations. Sth like this:
public class MyComponent : GH_Component{
int counter=0;
(...)
protected override SolveInstance(){
solver s = new solver();
while(counter < 100){
s.runAndDraw(); //new geometry being redrawn in Rhino in every iteration here
}
}
}
However, the problem I have with this solution, is that within this while-loop, the solver won’t react to changes being made in the Grasshopper Canvas.
I would appreciate a lot any ideas on this!
Thanks and best, Christoph