algorithmic modeling for Rhino
Hi
I use the following code to change change preview color of some geometry i create with a custom component.
It works if I only have one input for the first input parameter in the component.
However if I have multiple inputs only the first output geometry will change color and the rest will only be displayed as wireframe.
How can i solve this?
List<Brep> supportGeometry = new List<Brep>();
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Position", "Pos/SN", "Input PointCoordinates", GH_ParamAccess.item);
pManager.AddGenericParameter("NodeRestraint", "NR", "SupportRestraint", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("Support", "SN", "Support", GH_ParamAccess.item);
pManager.AddGenericParameter("Sphere", "S", "Resulting sphere", GH_ParamAccess.list);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
...
// create sphere and cone
Sphere sphere = new Sphere(supportPlane, scale);
Cone cone = new Cone(conePlane, num2, scale);
Sphere sphere = new Sphere(supportPlane, scale);
supportGeometry.Clear();
supportGeometry.Add(sphere.ToBrep());
supportGeometry.Add(cone.ToRevSurface().ToBrep());
DA.SetDataList(1, supportGeometry);
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(System.Drawing.Color.FromArgb(0, 0, 200), 0.5);
material.Transparency = 0.5;
for (int i = 0; i < supportGeometry.Count;i++ )
{
args.Display.DrawBrepShaded(supportGeometry[i], material);
}
}
Tags:
You clear your support geometry list in every SolveInstance. This means you always only get the last (not the first) brep in there.
You should override BeforeSolveInstance(), clear your support geometry there, and then only add to the list in SolveInstance.
--
David Rutten
david@mcneel.com
Hi David
Thank you for the help
However I think I have found three methods for this to work
protected override void BeforeSolveInstance()
{
supportGeometry.Clear();
}
or
public override void ClearData()
{
//supportGeometry.Clear();
}
or inside the solverinstance
if (DA.Iteration == 0)
{
supportGeometry.Clear();
}
They all seem to do the same but I guess there is a difference?
They all do somewhat the same.
--
David Rutten
david@mcneel.com
Thank you so much for your explanation.
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