Hello,
I am successfully able to scale the curves as I wanted in C# grasshopper,
but when I use same code in VS after build solution succeeded, in Grasshopper it is showing me error.
where am I going wrong?
attached scrip and picture of image
List<Curve>floorCurves = new List<Curve>();
for(int k =0; k<allFloors.Count; k++)
{
allFloors[k].DuplicateCurve();
Curve c = allFloors[k];
AreaMassProperties cA = AreaMassProperties.Compute(c);
Point3d cent = cA.Centroid;
double sk = Math.Sin(k * Scale);
double sC = (sk - (-1)) / (1 - (-1)) * (1 - 0.85) + 0.85;
//Remap Formula
//(Value - fromSource) / (toSource - fromSource) * (toTarget - fromTarget) + fromTarget;
Transform scl = Transform.Scale(cent, sC );
c.Transform(scl);
Curve cO = c;
floorCurves.Add(cO);
}
return floorCurves;

This code is pointless:
allFloors[k].DuplicateCurve();
The duplicate method returns a new curve, since you’re not storing it in a variable, there’s no reason to call that method. This however does make sense:
Curve c = allFloors[k].DuplicateCurve();
This, also:
Curve cO = c;
floorCurves.Add(cO);
does nothing more than:
floorCurves.Add(c);
does.
1 Like
The error you’re getting relates to this line of code:
AreaMassProperties cA = AreaMassProperties.Compute(c);
c
is a null reference it seems, although I find that suspicious since c
equals allFloors[k]
and allFloors[k]
had a method invoked on it prior to your call to AreaMassProperties.Compute()
. So if it was null it would have blown up earlier.
Could it be that c
isn’t closed or planar?
How about this code:
List<Curve> floorCurves = new List<Curve>();
foreach (Curve floorCurve in allFloors)
if (floorCurve != null)
{
AreaMassProperties am = AreaMassProperties.Compute(floorCurve);
double sk = Math.Sin(k * Scale);
double sc = (sk + 1) / 2.0 * (1 - 0.85) + 0.85;
Transform dilation = Transform.Scale(m.Centroid, sc);
floorCurve = floorCurve.DuplicateCurve();
floorCurve.Transform(dilation);
floorCurves.Add(floorCurve);
}
return floorCurves;
k is incremental, therefore i didnt use foreach.
I replaced it with your code only used for loop instead, but still its showing same error after build is succeeded.
I think then you better post that curve that is causing the exception. Can’t really debug this otherwise.
for example curve input was simple ellipse from rhino.
Thanks for the support, It was the problem in my script in visual studio(I fixed it now), script was working fine in Grasshopper c#.
Thank you!