|
|
#1 |
|
Full Member
![]() ![]() Using: AutoCAD 2009 Join Date: Apr 2009
Posts: 64
|
I am using the code below to get a user to select a polyline. This is working beautifully. But now I also need the point where the user clicked on the Polyline, i.e. the X and Y coordinates.
Any Ideas? Dim myPEO AsNew Autodesk.AutoCAD.EditorInput.PromptEntityOptions(v bLf & "Select a Polyline:") myDWG = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.MdiActiveDocument myDB = myDWG.Database myEd = myDWG.Editor myPEO.SetRejectMessage("You must select a PolyLine." & vbCrLf) myPEO.AddAllowedClass(GetType(Autodesk.AutoCAD.DatabaseServices.Polyline), False) myPER = myEd.GetEntity(myPEO) myPS = myPER.Status SelectCase myPS Case Autodesk.AutoCAD.EditorInput.PromptStatus.OK 'MsgBox("Good job!") myTransMan = myDWG.TransactionManager myTrans = myTransMan.StartTransaction myEnt = myPER.ObjectId.GetObject (Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRea d) 'MsgBox("Entity is on layer " & myEnt.Layer) 'Where did he click?! Case Autodesk.AutoCAD.EditorInput.PromptStatus.Cancel 'MsgBox("You cancelled.") ExitSub Case Autodesk.AutoCAD.EditorInput.PromptStatus.Error MsgBox("Error warning.") ExitSub CaseElse ExitSub EndSelect Last edited by Jozi68 : 6th Nov 2009 at 10:29 am. Reason: Resolved |
|
|
|
|
|
#2 |
|
Super Member
![]() ![]() ![]() ![]() Using: Mechanical 2009 Join Date: Aug 2005
Location: Rhode Island
Posts: 1,184
|
Look at:
Code:
Autodesk.AutoCAD.EditorInput.PickPointSelectedObject Code:
PickPointSelectedObject.PickPoint |
|
|
|
|
|
#3 |
|
Full Member
![]() ![]() Using: AutoCAD 2009 Join Date: Apr 2009
Posts: 64
|
Thanx Seant, could you please give more detail? I'm not sure how to implement this.
|
|
|
|
|
|
#4 |
|
Super Member
![]() ![]() ![]() ![]() Using: Mechanical 2009 Join Date: Aug 2005
Location: Rhode Island
Posts: 1,184
|
It will have to wait till later as I'm about to head out the door. Sorry.
|
|
|
|
|
|
#5 |
|
Full Member
![]() ![]() Using: AutoCAD 2007 Join Date: Jul 2009
Location: Marseille France
Posts: 85
|
Hi,
Here's a little sample (C#) Code:
using System.Windows.Forms;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace PickPoint
{
public class Class1
{
[CommandMethod("Test")]
public void Test()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a polyline: ");
peo.SetRejectMessage("You must select a polyline\n");
peo.AddAllowedClass(typeof(Polyline), false);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId id = per.ObjectId;
Point3d picked = per.PickedPoint;
Polyline pline = tr.GetObject(id, OpenMode.ForRead) as Polyline;
Point3d onPlinePt = pline.GetClosestPointTo(picked, ed.GetCurrentView().ViewDirection, false);
MessageBox.Show("Picked point: " + picked.ToString() + "\nClosest point on polyline: " + onPlinePt.ToString());
tr.Commit();
}
}
}
}
}
Code:
Imports System.Windows.Forms
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application
Namespace PickPoint
Public Class Class1
<CommandMethod("Test")> _
Public Sub Test()
Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim peo As New PromptEntityOptions(vbLf & "Select a polyline: ")
peo.SetRejectMessage("You must select a polyline" & vbLf)
peo.AddAllowedClass(GetType(Polyline), False)
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status = PromptStatus.OK Then
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim id As ObjectId = per.ObjectId
Dim picked As Point3d = per.PickedPoint
Dim pline As Polyline = TryCast(tr.GetObject(id, OpenMode.ForRead), Polyline)
Dim onPlinePt As Point3d = pline.GetClosestPointTo(picked, ed.GetCurrentView().ViewDirection, False)
MessageBox.Show(("Picked point: " & picked.ToString() & vbLf & "Closest point on polyline: ") + onPlinePt.ToString())
tr.Commit()
End Using
End If
End Sub
End Class
End Namespace
Last edited by gile : 4th Nov 2009 at 03:26 pm. |
|
|
|
|
|
#6 |
|
Super Member
![]() ![]() ![]() ![]() Using: Mechanical 2009 Join Date: Aug 2005
Location: Rhode Island
Posts: 1,184
|
Gile, that is a particularly concise and direct method which appears hard to beat.
I was hopeful that the Editor.GetSelection route would allow for additional filtering (if a person were interested in that sort of thing) but every attempt I’ve made to combine a SinglePick version of PromptEntityOptions along with SelectionFilters has crashed AutoCAD. That would be a fairly useful option, so I’ll keep looking. The example below works well enough but doesn’t bring anything new to the table. Code:
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Public Class STSCCommands
<CommandMethod("Pop")> _
Public Sub PointOnPoly()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim pso As PromptSelectionOptions = New PromptSelectionOptions()
pso.MessageForAdding = "Select a Poly: "
pso.SinglePickInSpace = True
pso.SingleOnly = True
Dim result As PromptSelectionResult = ed.GetSelection(pso)
If result.Status = PromptStatus.OK And result.Value.Count > 0 Then
Using trn As Transaction = db.TransactionManager.StartTransaction
Dim ppso As PickPointSelectedObject = DirectCast(result.Value(0), PickPointSelectedObject)
Dim poly As Polyline = TryCast(trn.GetObject(result.Value(0).ObjectId, OpenMode.ForRead), Polyline)
If poly IsNot Nothing Then
Dim p3d As Point3d = poly.GetClosestPointTo(ppso.PickPoint.PointOnLine, False)
ed.WriteMessage(p3d.ToString())
End If
End Using
End If
End Sub
|
|
|
|
|
|
#7 |
|
Full Member
![]() ![]() Using: AutoCAD 2007 Join Date: Jul 2009
Location: Marseille France
Posts: 85
|
Seant,
To mimic the Editor.GetEntiy with Editor.GetSelection it seems to me it needs: PromptSelectionOptions.SelectEverythingInAperture (rather than SinglePickInSpace) and PromptSelectionOptions.SingleOnly as the LISP expression: (ssget "_:S:E") Here's a C# example (works on A2007 and A2010) Code:
[CommandMethod("TEST")]
public void test()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
TypedValue[] filter = { new TypedValue(0, "LWPOLYLINE") };
SelectionFilter selFilter = new SelectionFilter(filter);
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.MessageForAdding = "Select a polyline: ";
pso.SelectEverythingInAperture = true;
pso.SingleOnly = true;
PromptSelectionResult psr = ed.GetSelection(pso, selFilter);
if (psr.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId[] ids = psr.Value.GetObjectIds();
ObjectId id = ids[0];
Polyline pline = tr.GetObject(id, OpenMode.ForRead) as Polyline;
PickPointSelectedObject ppso = psr.Value[0] as PickPointSelectedObject;
Point3d picked = ppso.PickPoint.PointOnLine;
Point3d onPlinePt = pline.GetClosestPointTo(picked, ed.GetCurrentView().ViewDirection, false);
MessageBox.Show("Picked point: " +
picked.ToString() +
"\nClosest point on polyline: " +
onPlinePt.ToString());
tr.Commit();
}
}
}
|
|
|
|
|
|
#8 |
|
Super Member
![]() ![]() ![]() ![]() Using: Mechanical 2009 Join Date: Aug 2005
Location: Rhode Island
Posts: 1,184
|
Gile, nicely done.
|
|
|
|
|
|
#9 |
|
Full Member
![]() ![]() Using: AutoCAD 2007 Join Date: Jul 2009
Location: Marseille France
Posts: 85
|
Just a little thing for these routines to work whatever the current UCS and current view.
Using Editor.GetEntity, the PickedPoint is UCS coordinates, so have to replace : Code:
Point3d picked = per.PickedPoint; Code:
Point3d picked = per.PickedPoint.TransformBy(ed.CurrentUserCoordinateSystem); Code:
Point3d onPlinePt = pline.GetClosestPointTo(picked, ed.GetCurrentView().ViewDirection, false); Code:
PickPointSelectedObject ppso = psr.Value[0] as PickPointSelectedObject; PickPointDescriptor ppd = ppso.PickPoint; Point3d onPlinePt = pline.GetClosestPointTo(ppd.PointOnLine, ppd.Direction, false); |
|
|
|
|
|
#10 |
|
Super Member
![]() ![]() ![]() ![]() Using: Mechanical 2009 Join Date: Aug 2005
Location: Rhode Island
Posts: 1,184
|
Yes, I did notice that feature in Post #9, a critical feature in 3D work. It would have been processed at some point along the way. Yesterday, the amount of attention I could devote towards any aspect of the problem was focused primarily on filtering. Thanks again for the heads up.
![]() |
|
|
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| select all entites at a point using vba | giskumar | AutoLISP, VBA, the CUI & Customisation | 0 | 12th Oct 2009 12:21 pm |
| List coordinate by select point group | jason tay | AutoLISP, VBA, the CUI & Customisation | 37 | 27th Apr 2009 12:36 am |
| I have to shift-select to select multiple objects | PDS | AutoCAD Beginners' Area | 9 | 15th May 2008 03:02 pm |
| Point select program stuck in a loop.. | hardwired | AutoLISP, VBA, the CUI & Customisation | 0 | 8th Jan 2008 04:07 pm |
| Select a Point without knowing it | NCDesign | AutoLISP, VBA, the CUI & Customisation | 4 | 30th Jul 2007 01:26 pm |