- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
[platform win10,AutoCAD 2018]
I want to implement a dynamic drawing tool.DWG files have many Polylines that represent points. When the drawing tool starts and the mouse moves to the point, the coordinates of the point are prompted (extended data is written to the point).
I referred to an article: https://www.keanw.com/2006/11/two_methods_for.html . Gets the entities in range by the SelectCrossingWindow() function, which works when used in a command function. I write a test program to get the text entity near the picked point:
public static void SelectCrossingEditor()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
try
{
PromptPointOptions ptOpts =
new PromptPointOptions(
"\nPick a point at which to select all text entities: "
);
PromptPointResult ptRes =
ed.GetPoint(ptOpts);
if (PromptStatus.OK == ptRes.Status)
{
Point3d p = ptRes.Value;
Point3d p1 =
new Point3d(p.X - 100, p.Y - 100, 0.0);
Point3d p2 =
new Point3d(p.X + 100, p.Y + 100, 0.0);
TypedValue[] values =
{
new TypedValue(
(int)DxfCode.Start,
"TEXT"
)
};
SelectionFilter filter = new SelectionFilter(values);
PromptSelectionResult res =
ed.SelectCrossingWindow(p1, p2, filter);
if(res.Status== PromptStatus.OK)
{
SelectionSet ss = res.Value;
int n = 0;
if (ss != null)
{
n = ss.Count;
}
ed.WriteMessage(
string.Format(
"\n{0} text entit{1} selected.",
n, 1 == n ? "y" : "ies"
)
);
}
}
}
catch (System.Exception e)
{
ed.WriteMessage("\nException {0}.", e);
}
}
But when SelectCrossingWindow() function used in DrawJig's WorldDraw function, it always returns an Error, even if the mouse position is in the text position.
How to solve this problem?
Solved! Go to Solution.