Inconsistent Behavior of GetOffsetCurves() with Positive Offset — Outside Offset Not Guaranteed

Inconsistent Behavior of GetOffsetCurves() with Positive Offset — Outside Offset Not Guaranteed

praveen.cMXB2H
Enthusiast Enthusiast
198 Views
2 Replies
Message 1 of 3

Inconsistent Behavior of GetOffsetCurves() with Positive Offset — Outside Offset Not Guaranteed

praveen.cMXB2H
Enthusiast
Enthusiast

I'm experiencing inconsistent behavior with the GetOffsetCurves() method in the AutoCAD .NET API when applying a positive offset to a Polyline.

In most cases, the positive offset correctly creates an outside offset, but in some cases, it unexpectedly creates an inside offset, even though the polylines are closed and appear to have consistent structure and direction.

My requirement is to always create an offset on the outside of the closed polyline, regardless of its orientation or how it was drawn.  

Please check below code:

public Polyline ApplyObstacleOffset(Transaction tr, Polyline polyline , BlockTableRecord space, double BOffset)
{
    Polyline updated = null;

    if (polyline != null)
    {
        DBObjectCollection offsetCurves = polyline.GetOffsetCurves(BOffset);

        foreach (DBObject obj in offsetCurves)
        {
            Polyline offsetPolyline = obj as Polyline;
            if (offsetPolyline != null)
            {
                space.AppendEntity(offsetPolyline);
                tr.AddNewlyCreatedDBObject(offsetPolyline, true);
            }
            updated = offsetPolyline;
        }
    }

    return updated;
}

0 Likes
199 Views
2 Replies
Replies (2)
Message 2 of 3

AllenJessup
Mentor
Mentor

You'd get better results posting in one of the Customization forums. I'd have your post moved but I'm not sure which software you're writing for.

Allen Jessup
CAD Manager - Designer
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 3 of 3

_gile
Consultant
Consultant

Hi,

 

The offset side depends on the Polyline direction (right side, if offset distance is positive; left side otherwise).

You could get some inspiration from this extension method (it depends on other classes in the same library).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes