Code Red > .NET
Pline jig with double
krkec:
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;
--- 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);
}
}
}
--- End code ---
Here is function code:
--- 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();
}
}
}
--- End code ---
I tried everyting please help.
Jeff_M:
I reckon that this one stumped all the readers.... 3+ year old post, read 428 times, not one response. When I found this in a search I was hopeful of locating an answer to a very similar question I have. Actually, it's pretty much identical, wherein I need to prompt the user for an elevation after a point is successfully picked by the user. I have the Jig working as I need, complete with similar options allowed by the ACAD Polyline command, but I need to store the vertices of the polyline, including user entered Z values, for creating a Civil3D featureline (which is essentially a 3dpoly with arcs) from the polyline. Hoping a bump here will stir some interest...
huiz:
I think you should keep a List<double> for the Z-values next to the Jig polyline and afterwards create the Feature Line with the vertices and bulges combined with the doubles.
Jeff_M:
Right, Huiz, but, how to get the doubles for the Z as the user selects a point? I think the Jig needs to be stopped/paused, get the double, resume the Jig. I'm just not coming up with the How to do that.
Atook:
Can you just drop something in the SamplerStatus Override?
Like this?
--- Code - C#: ---protected override SamplerStatus Sampler(JigPrompts prompts){ PromptPointResult ppResult; JigPromptPointOptions jigOpts = new JigPromptPointOptions { UserInputControls = UserInputControls.NullResponseAccepted, }; ppResult = prompts.AcquirePoint(jigOpts); if (ppResult.Status==PromptStatus.Keyword) else if (ppResult.Status==PromptStatus.OK) { if (ppResult.Value.DistanceTo(LastPoint) < 0.1) { return SamplerStatus.NoChange; } // get us an ELEVATION, YEAH! PromptDoubleResult pdr = Active.Editor.GetDouble("Enter Elevation: "); double z = 0; if (pdr.Status==PromptStatus.OK) { LastPoint = ppResult.Value; z = pdr.Value; // do something cool here } } }}
Navigation
[0] Message Index
[#] Next page
Go to full version