.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create an offset from a 3D polyline

1 REPLY 1
Reply
Message 1 of 2
eduardo_salvador02
145 Views, 1 Reply

Create an offset from a 3D polyline

eduardo_salvador02
Enthusiast
Enthusiast

Hello, would anyone know how I could create an OffSet from a 3D Polyline? I need it to identify all the angles and axes in which this 3D Polyline moves, create other 3D Polylines based on this first one and separate them in the model with an OffSet.

If anyone knows I'd be grateful!

0 Likes

Create an offset from a 3D polyline

Hello, would anyone know how I could create an OffSet from a 3D Polyline? I need it to identify all the angles and axes in which this 3D Polyline moves, create other 3D Polylines based on this first one and separate them in the model with an OffSet.

If anyone knows I'd be grateful!

1 REPLY 1
Message 2 of 2

waga.asanka
Contributor
Contributor
public static void Offset3DPolyline_V2(Document doc, ObjectId polylineId, double offsetDistance)
{
    // Start a transaction
    using (Transaction tr = doc.TransactionManager.StartTransaction())
    {
        try
        {
            // Open the polyline for reading
            Polyline3d polyline = tr.GetObject(polylineId, OpenMode.ForRead) as Polyline3d;


            // Verify that the entity is a 3D polyline
            if (polyline != null && polyline.PolyType == Poly3dType.SimplePoly)
            {
                // Open the BlockTable for writing
                BlockTable bt = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForWrite) as BlockTable;

                // Open the current space block (ModelSpace) for writing
                BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                var Plane = polyline.GetPlane();

                var normal = Plane.Normal;

                // Offset the object in the first direction
                foreach (ACAD_DBS.Polyline3d acEnt in polyline.GetOffsetCurvesGivenPlaneNormal(normal, offsetDistance))
                {
                    // Add each offset object
                    btr.AppendEntity(acEnt);
                    tr.AddNewlyCreatedDBObject(acEnt, true);
                }

                // Offset the object in the second direction (negative offset)
                foreach (ACAD_DBS.Polyline3d acEnt in polyline.GetOffsetCurvesGivenPlaneNormal(normal, -offsetDistance))
                {
                    // Add each offset object
                    btr.AppendEntity(acEnt);
                    tr.AddNewlyCreatedDBObject(acEnt, true);
                }
            }
            else
            {
                doc.Editor.WriteMessage("Selected entity is not a valid 3D polyline.");
            }

            // Commit the transaction
            tr.Commit();
        }
        catch (System.Exception ex)
        {
            doc.Editor.WriteMessage("Error: " + ex.Message);
        }
    }
}
0 Likes

public static void Offset3DPolyline_V2(Document doc, ObjectId polylineId, double offsetDistance)
{
    // Start a transaction
    using (Transaction tr = doc.TransactionManager.StartTransaction())
    {
        try
        {
            // Open the polyline for reading
            Polyline3d polyline = tr.GetObject(polylineId, OpenMode.ForRead) as Polyline3d;


            // Verify that the entity is a 3D polyline
            if (polyline != null && polyline.PolyType == Poly3dType.SimplePoly)
            {
                // Open the BlockTable for writing
                BlockTable bt = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForWrite) as BlockTable;

                // Open the current space block (ModelSpace) for writing
                BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                var Plane = polyline.GetPlane();

                var normal = Plane.Normal;

                // Offset the object in the first direction
                foreach (ACAD_DBS.Polyline3d acEnt in polyline.GetOffsetCurvesGivenPlaneNormal(normal, offsetDistance))
                {
                    // Add each offset object
                    btr.AppendEntity(acEnt);
                    tr.AddNewlyCreatedDBObject(acEnt, true);
                }

                // Offset the object in the second direction (negative offset)
                foreach (ACAD_DBS.Polyline3d acEnt in polyline.GetOffsetCurvesGivenPlaneNormal(normal, -offsetDistance))
                {
                    // Add each offset object
                    btr.AppendEntity(acEnt);
                    tr.AddNewlyCreatedDBObject(acEnt, true);
                }
            }
            else
            {
                doc.Editor.WriteMessage("Selected entity is not a valid 3D polyline.");
            }

            // Commit the transaction
            tr.Commit();
        }
        catch (System.Exception ex)
        {
            doc.Editor.WriteMessage("Error: " + ex.Message);
        }
    }
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report