Panel generator bug

Hello,

Please see C# command, created as part of the Programming Architecture C# plugin course I’m following.

The command is meant to prompt the user to select 4 points, then 20 panels are distributed at random angles, marked with text dots, and a parent (and 2 sublayers) are meant to be generated. I’ve done my best to go through the videos again, but I cant’ find the problem. I had the command working fine, but now it’s only generating the parent layer “L” and is exiting the command.

Any help would be appreciated.

Thanks,

Dan

Hi @daniel.depoe!

Try making Panels.Rebuild look more like this:

public bool Rebuild()
{
  var rc = false;
  if (4 == cornerpts.Count)
  {
    var edge_curves = new CurveList();
    for (var i = 0; i < cornerpts.Count; i++)
    {
      LineCurve edge = (i == cornerpts.Count - 1)
        ? new LineCurve(cornerpts[i], cornerpts[0])
        : new LineCurve(cornerpts[i], cornerpts[i + 1]);
      if (edge.IsValid)
        edge_curves.Add(edge);
    }

    if (4 == edge_curves.Count)
    {
      var edge_brep = UsefulFunctions.XCreateBrepFromEdgeCurves(edge_curves);
      if (null != edge_brep && edge_brep.IsValid)
      {
        brep = edge_brep;
        rc = true;
      }
    }
  }
  return rc;
}

– Dale

Dale,

I had just narrowed in on the Rebuild method, your answer came at a great time.

Your rewrite worked!

What was it about the other code that wasn’t working? The iterator with the modulo?

Dan

Hi Daniel,

The for loop only iterated 3 times.

– Dale