Hi,
Here is a sample code that might help in getting started with jigging of spline. It is a modified version of the code from this blog post dealing with polyline jigging.
http://through-the-interface.typepad.com/through_the_interface/2010/12/jigging-an-autocad-polyline-w...
Here is the code :
using System;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
[assembly: CommandClass(typeof(SplineJig.SplineJigCmds))]
namespace SplineJig
{
public class SplineDrawJig : DrawJig
{
// members
private Point3d _point;
private Point3dCollection _points = new Point3dCollection();
public Point3dCollection Coordinates
{
get
{
return _points;
}
}
public SplineDrawJig()
{
}
public void DoIt()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptResult jigRes = null;
do
{
jigRes = ed.Drag(this);
if (jigRes.Status == PromptStatus.OK)
{
_points.Add(_point);
}
else if (jigRes.Status == PromptStatus.None)
{
break;
}
}
while (jigRes.Status == PromptStatus.OK);
}
protected override Autodesk.AutoCAD.EditorInput.SamplerStatus
Sampler(Autodesk.AutoCAD.EditorInput.JigPrompts prompts)
{
JigPromptPointOptions jigOpts = new JigPromptPointOptions();
jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted);
jigOpts.Message = "Select fit point: ";
PromptPointResult jigRes = prompts.AcquirePoint(jigOpts);
Point3d pt = jigRes.Value;
if (pt == _point)
{
return SamplerStatus.NoChange;
}
_point = pt;
if (jigRes.Status == PromptStatus.OK)
{
return SamplerStatus.OK;
}
return SamplerStatus.Cancel;
}
protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
if (_points.Count == 0)
{
return true;
}
Point3dCollection vertices = new Point3dCollection();
foreach (Point3d point in _points)
{
vertices.Add(point);
}
vertices.Add(_point);
int totalVertices = vertices.Count;
if(totalVertices >= 2)
{
Line chordLine = new Line(vertices[totalVertices - 1], vertices[totalVertices-2]);
draw.Geometry.Draw(chordLine);
}
Spline spline = new Spline(vertices, KnotParameterizationEnum.Chord, 3, 0.0);
draw.Geometry.Draw(spline);
return true;
}
}
public class SplineJigCmds
{
public SplineJigCmds() { }
[CommandMethod("SplineJig")]
static public void SplineJig()
{
try
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Database db = ed.Document.Database;
SplineDrawJig splineJig = new SplineDrawJig();
splineJig.DoIt();
// order of the curve can be between 2 and 26
int order = 6;
// determines extent of interpolation through all the points
double fitTolerance = .5;
Spline spline = new Spline(splineJig.Coordinates, KnotParameterizationEnum.Chord, 3, 0.0);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(spline);
tr.AddNewlyCreatedDBObject(spline, true);
tr.Commit();
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Hope this helps.
Balaji
Developer Technical Services
Autodesk Developer Network