Community
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!
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!
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);
}
}
}
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.