RhinoCommon

Good evening everyone,

I’m new here. Please help me.
I have (Error) in C# - The name does not exist in the current context.

for (i = 0; i < 10; i = i + 2)
{
an algorithm of actions at the end of which I get - Brep[] or Brep
}             

How to access a local variable (Brep or Brep) outside of a for loop in c#?

Thanks in advance for your help.
Dzintars

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            int i;
            var gc = new GetObject();
            

            gc.SetCommandPrompt("Select some breps");
            gc.EnablePreSelect(false, true);
            gc.GeometryFilter = ObjectType.Brep;
            gc.GetMultiple(1, 0);

            if (gc.CommandResult() != Result.Success)
                return gc.CommandResult();

            RhinoList <Brep> breps = new RhinoList<Brep>();

            for (i = 0; i < 10; i = i + 2)
                
            {
                Brep brep = gc.Object(i).Brep();
                if (null != brep)
                breps.Add(brep);

                Curve[] DuplicateEdgeCurves = brep.DuplicateEdgeCurves();
         
                Curve DuplicateEdgeCurve0 = DuplicateEdgeCurves[0];
                Curve DuplicateEdgeCurve1 = DuplicateEdgeCurves[1];
                Curve DuplicateEdgeCurve2 = DuplicateEdgeCurves[2];
                doc.Objects.AddCurve(DuplicateEdgeCurve0);
                doc.Objects.AddCurve(DuplicateEdgeCurve1);
                doc.Objects.AddCurve(DuplicateEdgeCurve2);
}

DuplicateEdgeCurve1 (not visible outside the loop).

Thanks in advance for your help.
Dzintars

Can someone help me ?!
Thanks.

Hi @dzintarswagners,

How about this?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject();
  go.SetCommandPrompt("Select surface and polysurface to duplicate edge curves");
  go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter;
  go.SubObjectSelect = false;
  go.GetMultiple(1, 0);
  if (go.CommandResult() != Result.Success)
    return go.CommandResult();

  foreach (var objref in go.Objects())
  {
    var brep = objref.Brep();
    if (null != brep)
    {
      var curves = brep.DuplicateEdgeCurves();
      if (null != curves)
      {
        foreach (var curve in curves)
        {
          var obj_id = doc.Objects.AddCurve(curve);
          if (obj_id != Guid.Empty)
          {
            var rh_obj = doc.Objects.Find(obj_id);
            if (null != rh_obj)
              rh_obj.Select(true);
          }
        }
      }
    }
  }

  doc.Views.Redraw();

  return Result.Success;
}

You can find many more samples in the Rhino Developer Samples repository on GitHub.

– Dale

Hi Dale,

Thanks a lot for your help.
Please tell me, how can I get the access to separate (specific) curve in code (in the same function)?
How can I identify specific curves in my curves array?
Identify specific curves and then immediately work with these individual curves in code (in the same function).

Thanks in advance for your support.
Dzintars

Well, that is what this statement does:

foreach (var curve in curves)

What does this mean? What problem are you trying to solve?

– Dale

Hi Dale,

I have 1000 breps (surface or polysurface) in my array.
After these 1000 surfaces will processed with long method, I need to get access to each individual result of method with which each brep was processed.

Dzintars

Let’s say a function converted 1000 separate surfaces using one algorithm in a for loop.
After the for loop has performed a function with all 1000 separate surfaces, I need to access to the result of a specific surface (let say 394, 256 and 579).

Dzintars

Hi @dzintarswagners,

I’d define a class that would hold the results of the edge duplication. The class could also store an index, a reference to the Brep, and the face index or component index. Then build an array or list of these class objects.

– Dale

Hi Dale,

Thanks a lot for your comments.
Can you send me a short example of code, how can i implement this.
Thanks a lot in advance.
Dzintars

Hi Dale,

I would really appreciate your comments as soon as possible.
Thanks in advance.
Dzintars

How about this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go = new GetObject();
  go.SetCommandPrompt("Select surface and polysurface to duplicate edge curves");
  go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter;
  go.SubObjectSelect = false;
  go.GetMultiple(1, 0);
  if (go.CommandResult() != Result.Success)
    return go.CommandResult();

  // Create a list that contains lists of curves
  var curve_lists = new List<List<Curve>>();

  for (var i = 0; i < go.ObjectCount; i++)
  {
    var objref = go.Object(i);
    var brep = objref.Brep();
    if (null != brep)
    {
      var curves = brep.DuplicateEdgeCurves();
      if (null != curves)
        curve_lists.Add(curves.ToList());
    }
  }

  for (var i = 0; i < curve_lists.Count; i++)
  {
    var curves = curve_lists[i];
    foreach (var curve in curves)
    {
      var obj_id = doc.Objects.AddCurve(curve);
      if (obj_id != Guid.Empty)
      {
        var rh_obj = doc.Objects.Find(obj_id);
        if (null != rh_obj)
          rh_obj.Select(true);
      }
    }
  }

  doc.Views.Redraw();

  return Result.Success;
}

– Dale

Hi Dale,

Now everything is OK.
Many thanks for your help.
Dzintars

A post was split to a new topic: Delete duplicate objects

I need to remove BREPS (duplicates).
Something like this (Point3d.CullDuplicates Method) is for BREP class?

Dzintars