@braudpat a écrit :
SVP serait il possible de faire une micro-modif : ajouter l option C pour clore ??
Parce que c'est toi, et pour montrer comment c'est (relativement) simple avec .NET (en tout cas bien plus qu'en LISP ou ObjectARX/C++).
PS : Je ne pense pas aller plus loin dans l'ajout de nouvelles fonctionnalités.
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
namespace PolylineLengthJig
{
public class Commands
{
[CommandMethod("PLEN")]
public static void PlineLength()
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var ppr = ed.GetPoint("\nPremier point: ");
if (ppr.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
using (var pline = new Polyline())
{
pline.AddVertexAt(0, ppr.Value.Convert2d(new Plane()), 0.0, 0.0, 0.0);
pline.AddVertexAt(1, Point2d.Origin, 0.0, 0.0, 0.0);
pline.TransformBy(ed.CurrentUserCoordinateSystem);
var jig = new PlineLengthJig(pline);
while (true)
{
var pr = ed.Drag(jig);
if (pr.Status == PromptStatus.Cancel)
return;
if (pr.Status == PromptStatus.OK)
{
pline.AddVertexAt(pline.NumberOfVertices, Point2d.Origin, 0.0, 0.0, 0.0);
db.TransactionManager.QueueForGraphicsFlush();
}
else
{
pline.RemoveVertexAt(pline.NumberOfVertices - 1);
if (pr.Status == PromptStatus.Keyword)
{
pline.Closed = true;
}
else if (pline.NumberOfVertices < 2)
{
return;
}
var cSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
cSpace.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
break;
}
}
}
tr.Commit();
}
}
}
class PlineLengthJig : DrawJig
{
Polyline pline;
Point3d dragPt;
Plane plane;
public PlineLengthJig(Polyline pline)
{
this.pline = pline;
plane = new Plane(Point3d.Origin, pline.Normal);
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
var options = new JigPromptPointOptions("\nPoint suivant: ");
options.BasePoint = pline.GetPoint3dAt(pline.NumberOfVertices - 2);
options.UseBasePoint = true;
if (3 < pline.NumberOfVertices)
{
options.Keywords.Add("Clore");
options.AppendKeywordsToMessage = true;
}
options.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.GovernedByOrthoMode |
UserInputControls.GovernedByUCSDetect |
UserInputControls.NullResponseAccepted;
var result = prompts.AcquirePoint(options);
if (result.Value.IsEqualTo(dragPt))
return SamplerStatus.NoChange;
dragPt = result.Value;
return SamplerStatus.OK;
}
protected override bool WorldDraw(AcGi.WorldDraw draw)
{
var geo = draw.Geometry;
if (geo != null)
{
pline.SetPointAt(pline.NumberOfVertices - 1, dragPt.Convert2d(plane));
geo.Draw(pline);
var height = (double)AcAp.GetSystemVariable("viewsize") / 50.0;
geo.Text(dragPt, Vector3d.ZAxis, Vector3d.XAxis, height, 1.0, 0.0, pline.Length.ToString("0.00"));
}
return true;
}
}
}