algorithmic modeling for Rhino
Hi everyone,
I have lately been working on Mouse Interactive tool at work, and I have made it work with a c# component, so now I want to compile it into my own component. Which should be easy enough, however I am getting one error which I cannot solve for the life of me.
As part of this component I have overwritten the display pipeline to enable for custom display options, and to speed up the process of previewing a lot of geometry.
When I wrote it in my c# native grasshopper component there wasnt any problems, but when compiled into its own component using Giulio Piacintino visual studio template.
Any help is appreciated, and the code is as follows(which was kindly shared by David Reeves), I have changed one thing from the grasshopper to the visual studio compiled component, which is the " if(_clippingBox.IsValid){}" statement, which was to prevent it from getting a display pipeline error before anything had been added to the component:
//--------------------------------
//overiding the different preview function to prevent errors
public override BoundingBox ClippingBox
{
get
{
return _clippingBox;
}
}
//--------------------------------
public override void DrawViewportWires(IGH_PreviewArgs args)
{
if (_clippingBox.IsValid)
{
//display for Lines and Points
base.DrawViewportWires(args);
// add custom display code here
// access draw methods under "args.Display"
//args.Display.DrawPointCloud(_cloud, 3);
for (int i = 0; i < objT[1].Length; i++)
{
if (BB[1][i] && P)
{
args.Display.DrawLine((Line)objT[1][i], System.Drawing.Color.FromArgb(0, 0, 0), 3);
}
else if (!BB[1][i])
{
args.Display.DrawLine((Line)objT[1][i], System.Drawing.Color.FromArgb(0, 0, 0), 1);
}
}
}
}
//---------------------------
//---------------------------
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
if (_clippingBox.IsValid) {
//display for Surfaces & Meshes
base.DrawViewportMeshes(args);
// add custom display code here
// access draw methods under "args.Display"
for (int i = 0; i < objT[0].Length; i++)
{
if (BB[0][i] && P)
{
System.Drawing.Color col = System.Drawing.Color.FromArgb(255, 255, 153);
args.Display.DrawMeshShaded((Mesh)objT[0][i], new Rhino.Display.DisplayMaterial(col));
}
else if (!BB[0][i])
{
args.Display.DrawMeshShaded((Mesh)objT[0][i], new Rhino.Display.DisplayMaterial());
}
}
}
}
//---------------------------
Tags:
Essentially what I am curious about is what does "base." refer to in a native grasshopper c# component versus that of a visual studio one? I think that might be where the mix up is happening...
What is the compile error?
In general, the Grasshopper SDK and the scripting plug-in interface are quite different. The latter is a simplified version of the previous.
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
EDIT: Probably the only easy way for me to really help is if you send the whole solution in a zip file.
There isnt an error in the compiling, the component compiles just fine, the problem, is the override view commands doesnt output anything and I get an error in Rhino - see attached.
A simplified version(from David Reeves) of what I am trying to get to work is attached as well. This version is a simple GH c# component and works like a charm, if you put it into a compiled/your own component, it doesnt preview anything and throws the before mentioned error.
Thanks for your help.
Hi again Jens,
Can you attach the simplified project?
Thanks
Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com
Do you mean the c# or the visual studio one?
Hi Giulio,
I have attached a zip file, which has the original grasshopper script - that works, and then a visualt studio file with the code and compiled components-see the bin folder in the zip file.
Thank you for your time.
The problem is you create an invalid clipping box once and it completely destroys the display for ever and ever. Don't ever send Unset values to the Rhino display as it will choke on them.
Fair point, which explains why it produces an error when it has no geometry to make a boundingbox from - but what about when it has a boundingbox? and I get the same problem.
Maybe you can clarify this David, when you call "base" in the c# component what does it refer to then versus when you call "base" in visual studio?
You're also getting p1 twice and never touch p0, that's why the display is always horked.
C# and Visual Studio are not two different programming languages. When you call 'base' in C# (regardless of whether you're using VS) it means you're accessing the base class.
So for example if you override a method on the base class, but you want to call the original method rather than your override, you use base.MethodName().
Here's the fixed code.
hehe, sorry I hadnt seen that "red ears" - it was a quick thing I put together... That being said this was a different example from what I am really working on, so based on the code in the initial post do you think the problem is similar to what you saw here? simply a messed up Boundingbox?
Anyway thank you for clarifying the base thing for me, makes good sense. The reason for my question was the different inheritances(or at least it seemed like that to me). C# comp inherits from GH_Scriptinstance and in visual studio its from GH_Component, and that just confused me.
Thank you very much for the additional code! ! hopefully I can fix it now :) I will post a comment/video here once finished...
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by