hi
I want to modify Kean Walmsely polyline Jig. For before every point user will be asked for entering double and this double will be subtacted form points y value.
Here is class code;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prolazi
{
class PlineJig : EntityJig
{
// Maintain a list of vertices...
// Not strictly necessary, as these will be stored in the
// polyline, but will not adversely impact performance
Point3dCollection m_pts;
// Use a separate variable for the most recent point...
// Again, not strictly necessary, but easier to reference
Point3d m_tempPoint;
Plane m_plane;
double nadsloj = 1;
double cent;
double promjerC = 300;
public PlineJig(Matrix3d ucs)
: base(new Polyline())
{
// Create a point collection to store our vertices
m_pts = new Point3dCollection();
// Create a temporary plane, to help with calcs
Point3d origin = new Point3d(0, 0, 0);
Vector3d normal = new Vector3d(0, 0, 1);
normal = normal.TransformBy(ucs);
m_plane = new Plane(origin, normal);
// Create polyline, set defaults, add dummy vertex
Polyline pline = Entity as Polyline;
pline.SetDatabaseDefaults();
pline.Normal = normal;
pline.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
JigPromptPointOptions jigOpts =
new JigPromptPointOptions();
jigOpts.UserInputControls =
(UserInputControls.Accept3dCoordinates |
UserInputControls.NullResponseAccepted |
UserInputControls.NoNegativeResponseAccepted
);
//JigPromptOptions jpo = new JigPromptOptions();
if (m_pts.Count == 0)
{
// For the first vertex, just ask for the point
jigOpts.Message =
"\nStart point of polyline: ";
}
else if (m_pts.Count > 0)
{
//cent = funkcije.odnadsloj(nadsloj) + promjerC * 0.0005;
// For subsequent vertices, use a base point
jigOpts.BasePoint = m_pts[m_pts.Count - 1];
jigOpts.UseBasePoint = true;
jigOpts.Message = "\nPolyline vertex: ";
}
else // should never happen
return SamplerStatus.Cancel;
// Get the point itself
PromptPointResult res =
prompts.AcquirePoint(jigOpts);
// Check if it has changed or not
// (reduces flicker)
if (m_tempPoint == res.Value)
{
return SamplerStatus.NoChange;
}
else if (res.Status == PromptStatus.OK)
{
m_tempPoint = res.Value;
//m_tempPoint = new Point3d(res.Value.X, res.Value.Y - cent, 0);
return SamplerStatus.OK;
}
return SamplerStatus.Cancel;
}
protected override bool Update()
{
// Update the dummy vertex to be our
// 3D point projected onto our plane
Polyline pline = Entity as Polyline;
pline.SetPointAt(
pline.NumberOfVertices - 1,
m_tempPoint.Convert2d(m_plane)
);
return true;
}
public Entity GetEntity()
{
return Entity;
}
public void AddLatestVertex()
{
cent = funkcije.odnadsloj(nadsloj) + promjerC * 0.0005;
Point3d k = new Point3d(m_tempPoint.X, m_tempPoint.Y - cent, 0);
//_tempPoint = k;
m_pts.Add(k);
Polyline pline = Entity as Polyline;
// Create a new dummy vertex...
// can have any initial value
pline.AddVertexAt(
pline.NumberOfVertices,
new Point2d(0, 0),
0, 0, 0
);
}
public void RemoveLastVertex()
{
// Let's remove our dummy vertex
Polyline pline = Entity as Polyline;
pline.RemoveVertexAt(m_pts.Count);
}
}
}
Here is function code:
[CommandMethod("MYPOLY")]
public void MyPolyJig()
{
Document doc =
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
// Get the current UCS, to pass to the Jig
Matrix3d ucs =
ed.CurrentUserCoordinateSystem;
// Create our Jig object
PlineJig jig = new PlineJig(ucs);
// Loop to set the vertices directly on the polyline
bool bSuccess = true, bComplete = false;
do
{
PromptResult res = ed.Drag(jig);
bSuccess =
(res.Status == PromptStatus.OK);
// A new point was added
if (bSuccess)
jig.AddLatestVertex();
// Null input terminates the command
bComplete =
(res.Status == PromptStatus.None);
if (bComplete)
// Let's clean-up the polyline before adding it
jig.RemoveLastVertex();
} while (bSuccess && !bComplete);
// If the jig completed successfully, add the polyline
if (bComplete)
{
// Append entity
Database db = doc.Database;
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
BlockTable bt =
(BlockTable)tr.GetObject(
db.BlockTableId,
OpenMode.ForRead,
false
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite,
false
);
btr.AppendEntity(jig.GetEntity());
tr.AddNewlyCreatedDBObject(jig.GetEntity(), true);
tr.Commit();
}
}
}
I tried everyting please help.