Grasshopper

algorithmic modeling for Rhino

Hi,

I am working on a C# plugin (edited in visual studio) - at the moment I still only have two output entries: point3d and NurbsCurve.Startpoints. My input are just 3 Point3d and 2 Curves joining these points.

As expected, my Point3d output is a list of 3 points, but for some reason, the  NurbsCurve.Startpoints output is also a list of 3 points, with the last point being a duplicate of the second one.

Any idea why this happens, when I clearly only have 2 Curves and therefore only 2 Startpoints?

Thanks!

Views: 634

Replies to This Discussion

Without seeing the code is complicated help. Your have correctly set the access type (item, list, tree) in all parameters?

No code is tricky, sorry - I am not on my computer atm.

I will try to attach the code here later today; but this is basically the access type definitions I am using:

Register Input:

pManager.AddPoint3dParameter("Points", "P", "description", GH_ParamAccess.item);

pManager.AddCurveParameter("Curves", "C", "description", GH_ParamAccess.item);

Register Output:

pManager.AddPoint3dParameter("Nodes", "N", "description", GH_ParamAccess.item);

pManager.AddPoint3dParameter("Tails", "T", "description", GH_ParamAccess.item);

Tails are the NurbsCurve.Startpoints.. and that is where I am getting 3 points, instead of the expected 2 points.

Many Thanks!

Since all parameter names are plural, I guess their access should be of type list. But this depends on the function you're doing, and you have not given information about what makes this script.


If your input parameters have access of item type, then what is happening is that the first point will operate with only the first curve, the second point will operate with the second curve, and the third point will operate with the second curve. So from here it is already wrong.


When you change the type of access, you also need to change the code in the solveinstance. Instead of DA.GetData(,), it will be DA.GetDataList(,), and the variable that receives this parameter must be of type list, and all the code correspond to these changes.


But without seeing the code I'm not sure if this is the problem.

That might be the problem. I actually started with list access type, but I ended up changing it to item, since I could not execute the NurbsCurve.StartPoint command on the Curves (always got an error like: not possible to convert List into Point3d).  Sorry, C# beginner here ;) I will post the code later.. thanks Daniel.


/// -------------------- INPUT PARAMETERS ---------------------------
///
protected override void
RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddPointParameter("Points", "P", "description", GH_ParamAccess.item);
pManager.AddCurveParameter("Curves", "C", "description", GH_ParamAccess.item);
}

/// -------------------- OUTPUT PARAMETERS ---------------------------
///
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddPointParameter("Nodes", "N", "description", GH_ParamAccess.item);
pManager.AddPointParameter("Tails", "T", "description", GH_ParamAccess.item);
}

/// -------------------- CODE BLOCK ---------------------------

/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object can be used to retrieve data from input parameters and
/// to store data in output parameters.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{

// Declare local variables to store input lists.
//Point3d Points = new Point3d();
Point3d Points = new Point3d();
Curve Curves = new NurbsCurve(null);

if (!DA.GetData(0, ref Points)) return;
if (!DA.GetData(1, ref Curves)) return;

// -----------------------------------------------------------------------------------------------
//Declare FUNCTION

Point3d Nodes = GetNodes(Points);
DA.SetData(0, Nodes);

Point3d Tails = GetTails(Curves);
DA.SetData(1, Tails);

}
private Point3d GetNodes(Point3d Points)

{
Point3d Nodes = new Point3d();
Nodes = Points;
return Nodes;
}

private Point3d GetTails(Curve Curves)

{
Point3d Tails = new Point3d();
Tails = Curves.PointAt(0);
return Tails;
}

Any idea?

I have not tried the code but something like that should be.
Have you consulted the SDK samples?



/// -------------------- INPUT PARAMETERS ---------------------------
///
protected override void
RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddPointParameter("Points", "P", "description", GH_ParamAccess.list);
pManager.AddCurveParameter("Curves", "C", "description", GH_ParamAccess.list);
}
/// -------------------- OUTPUT PARAMETERS ---------------------------
///
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddPointParameter("Nodes", "N", "description", GH_ParamAccess.list);
pManager.AddPointParameter("Tails", "T", "description", GH_ParamAccess.list);
}
/// -------------------- CODE BLOCK ---------------------------

/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object can be used to retrieve data from input parameters and
/// to store data in output parameters.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
// Declare local variables to store input lists.

Point3d Points = new Point3d();

Curve Curves = new NurbsCurve(null);

List<Point3d> Points = null;

List<Curve> Curves = null;

if (!DA.GetDataList(0, ref Points)) return;
if (!DA.GetDataList(1, ref Curves)) return;

//Nodes is Points¿? Then it is a superfluous parameter..

List<Point3d>Tails = new List<Point3d>();

for (int i = 0; i <= Curves.Count - 1; i++) {
Tails.Add(Curves[i].PointAtStart);
}

DA.SetDataList(0, Points);
DA.SetDataList(1, Tails);

}

// -----------------------------------------------------------------------------------------------
//Declare FUNCTION

Point3d Nodes = GetNodes(Points);
DA.SetData(0, Nodes);

Point3d Tails = GetTails(Curves);
DA.SetData(1, Tails);
}
private Point3d GetNodes(Point3d Points)

{
Point3d Nodes = new Point3d();
Nodes = Points;
return Nodes;
}
private Point3d GetTails(Curve Curves)
{
Point3d Tails = new Point3d();
Tails = Curves.PointAt(0);
return Tails;
}

Thanks Daniel, I will give it a go!

btw; is there a way to convert lists into operable matrixes?

nodes = points is superfluous indeed.. i'm just trying to figure out my way around  ;)

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service