HiddenLineDrawing creates duplicate curve on layer Default

Hi,

I am trying to convert geometry to a drawing via HiddenLineDrawing.
It works really well, but…
Not always, but sometimes (I know this is not a very good and precise statement) it happens that on top of the curves I create there are the exact same curves put on Layer Default.

No idea why, any help highly appreciated! :slight_smile:

foreach (var item in auxiliaryGeometries)
{
    parameters.AddGeometry(item, null);
}

HiddenLineDrawing hld = HiddenLineDrawing.Compute(parameters, true);

foreach (var hld_curve in hld.Segments)
{
    if (hld_curve != null)
    {
        if (hld_curve.CurveGeometry.GetLength() > 0)
        {
              ObjectAttributes attr = new ObjectAttributes();
              attr.ColorSource = ObjectColorSource.ColorFromLayer;
              attr.LinetypeSource = ObjectLinetypeSource.LinetypeFromLayer;
              
              if (hld_curve.SegmentVisibility == HiddenLineDrawingSegment.Visibility.Hidden)
              {
                  attr.LayerIndex = hiddenLayer.Index;
              }

              if (hld_curve.SegmentVisibility == HiddenLineDrawingSegment.Visibility.Visible)
              {
                  attr.LayerIndex = visibleLayer.Index;
              }

              Curve curve = hld_curve.CurveGeometry.DuplicateCurve();
              curve.Transform(forward);
              
             Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(curve, attr);
        }
    }
}

Thanks,
T.

Hi Tobias,

my first thought is that I do not see your hiddenLayer and visibleLayer defined here, so they might not be defined well or nonexistent.

But more probable than that, you only covered two options for SegmentVisibility with your IF statements. Is it possible that some of the segments are neither Hidden nor Visible (there is Unset, Duplicate, Projecting, Clipped) and then their attr.LayerIndex does not get assigned to the hiddenLayer or visibleLayer, and thus stays Default?

@dimcic
Oh my gosh, you are right.
This is kind of embarrassing :slight_smile:

As I added every curve to the document and not the ones I caught with the loop before.
I changed that and it works. :slight_smile:

Thanks a lot.

No problem. Glad I could help. :+1:

1 Like