Grasshopper

algorithmic modeling for Rhino

These days I try to learn C#,but always meet some problems....

the following script has a Error:Object reference not sent to an instance of an object(in red color)

There are 3 reference points in pta,1 reference in ptOri,all they have been set to list of Point3d.

script following:

private void RunScript(List<Point3d> ptA, List<Point3d> ptOri, ref object A)
{
    myPoint3d st = new myPoint3d(ptA);
    A = st.X;
}

//<Custom additional code>
public class myPoint3d
{
    private List<Point3d> p;
    //**************************
    public double X;
    public double Y;
    public double Z;
    public myPoint3d(List<Point3d> ip)
    {
        p[0] = new Point3d(ip[0]);//error the following script has a Error:Object reference not                  

                                                   sent to an instance of an object
        X = p[0].X;
        Y = p[0].Y;
        Z = p[0].Z;
    }
}

Views: 123

Attachments:

Replies to This Discussion

i have fixed this by searching the previous post.......

the keypoint is to use "new" to open a place to store the "p"

script:

private void RunScript(List<Point3d> ptA, List<Point3d> ptOri, ref object A)
{
myPoint3d st = new myPoint3d(ptA);
A = st.X;
}

//<Custom additional code>
public class myPoint3d
{
private List<Point3d> p ;
//**************************
public double X;
public double Y;
public double Z;
public myPoint3d(List<Point3d> ip)
{
 p = new List<Point3d>(ip);
p[0] = ip[0];
X = p[0].X;
Y = p[0].Y;
Z = p[0].Z;
}

}

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service