Plane translation

Hi,

I have simple question about plane translations, why does the transformation in a list does not do anything:

  private void RunScript(object x, object y, ref object A)
  {
    List<Plane> planes = new List<Plane>();
    planes.Add(Plane.WorldXY);
    planes.Add(Plane.WorldXY);
    planes[0].Translate(new Vector3d(0,0,10)); //No effect

    A = planes;
  }

And this will do the job:

 private void RunScript(object x, object y, ref object A)
  {
    List<Plane> planes = new List<Plane>();
    planes.Add(Plane.WorldXY);
    planes.Add(Plane.WorldXY);
    planes[0].Translate(new Vector3d(0,0,10));

    Plane planeCopy = new Plane(planes[0]);
    planeCopy.Translate(new Vector3d(0,0,10));
    planes[0] = planeCopy;
    
    A = planes;
  }

Plane is a value type (struct) not a reference type (class). When you do

planes[0].Translate(new Vector3d(0,0,10));

you first get a copy of planes[0], then you apply the translation to that copy, but the item in the list is not changed.

2 Likes