Message 1 of 10
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all
Hello ... Mr _gile
Is it possible to modify the code he wrote Mr _gile
in the page forums.autodesk.com/t5/net/jigging-text-block-along-selected-polyline/td-p/8403298
To read as in the attached picture
[CommandMethod("JIGTEXT")]
public static void JigTextAlonPpolyline()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var entityOptions = new PromptEntityOptions("\nSelect polyline: ");
entityOptions.SetRejectMessage("\nmust be a Polyline.");
entityOptions.AddAllowedClass(typeof(Polyline), true);
var entityResult = ed.GetEntity(entityOptions);
if (entityResult.Status != PromptStatus.OK)
return;
var stringOptions = new PromptStringOptions("\nEnter a text: ");
stringOptions.AllowSpaces = true;
var stringResult = ed.GetString(stringOptions);
if (stringResult.Status != PromptStatus.OK)
return;
using (var tr = db.TransactionManager.StartTransaction())
{
var pline = (Polyline)tr.GetObject(entityResult.ObjectId, OpenMode.ForRead);
using (var text = new DBText())
{
text.SetDatabaseDefaults();
text.Normal = pline.Normal;
text.Justify = AttachmentPoint.BottomCenter;
text.AlignmentPoint = Point3d.Origin;
text.TextString = stringResult.StringResult;
var jig = new TextJig(text, pline);
var result = ed.Drag(jig);
if (result.Status == PromptStatus.OK)
{
var currentSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
currentSpace.AppendEntity(text);
tr.AddNewlyCreatedDBObject(text, true);
}
}
tr.Commit();
}
}
class TextJig : EntityJig
{
DBText text;
Polyline pline;
Point3d dragPt;
Plane plane;
Database db;
public TextJig(DBText text, Polyline pline)
: base(text)
{
this.text = text;
this.pline = pline;
plane = new Plane(Point3d.Origin, pline.Normal);
db = HostApplicationServices.WorkingDatabase;
}
protected override SamplerStatus Sampler(JigPrompts prompts)
{
var options = new JigPromptPointOptions("\nSpecicfy insertion point: ");
options.UserInputControls =
UserInputControls.Accept3dCoordinates |
UserInputControls.UseBasePointElevation;
var result = prompts.AcquirePoint(options);
if (result.Value.IsEqualTo(dragPt))
return SamplerStatus.NoChange;
dragPt = result.Value;
return SamplerStatus.OK;
}
protected override bool Update()
{
var point = pline.GetClosestPointTo(dragPt, false);
var angle = pline.GetFirstDerivative(point).AngleOnPlane(plane);
text.AlignmentPoint = point;
text.Rotation = angle;
text.AdjustAlignment(db);
return true;
}
}
Thank you so much
Solved! Go to Solution.