.NET

Reply
Active Contributor
34 Posts
5 Kudos
Registered: ‎09-02-2013
Post 1 of 4
Accepted Solution

Selection set by single point .

227 Views, 3 Replies
09-02-2013 04:43 AM

I am using following lisp code to select line object by single point.

(setq pt (getpoint "\nPick a point"))
(setq ss (ssget pt))

 

What is the .Net equivalent to achieve this? (select object by a single point I provide)

Thanks in advance.

Try this code snip:

 Dim ppo As New PromptPointOptions(vbLf & "Pick a Point: ")
Dim ppr As PromptPointResult
ppr = ed.GetPoint(ppo)
If ppr.Status <> PromptStatus.OK Then
ed.WriteMessage(vbCrLf & "wrong point specification!")
Exit Sub
End If
Dim p As Point3d = ppr.Value
'------------------------------------------------------------''
Dim vd As Vector3d = New Vector3d(1e-4, 1e-4, 1e-4) '<-- dicrease a fuzz to suit
Dim pMin As Point3d = p - vd
Dim pMax As Point3d = p + vd
Dim tvs() As TypedValue = New TypedValue() { New TypedValue(0, "line")}
Dim points As Point3dCollection = New Point3dCollection
points.Add(pMin)
points.Add(pMax)
Dim sf As SelectionFilter = New SelectionFilter(tvs)
Dim sres As PromptSelectionResult = ed.SelectFence(points, sf)
If sres.Status <> PromptStatus.OK Then
ed.WriteMessage("\nWrong selection!")
Return
End If
If sres.Value.Count = 0 Then
ed.WriteMessage("\nNothing selected!")
Return
End If
'' cast entity as Line
Dim eid As ObjectId = sres.Value.GetObjectIds(0)
Dim ent As Entity = TryCast(tr.GetObject(eid, OpenMode.ForRead), Entity)
''-----------------------------------------------------------''
Dim ln As Line = TryCast(ent, Line)
If ln IsNot Nothing Then
ed.WriteMessage(vbLf + "{0},{1},{2}", ln.StartPoint.X, ln.StartPoint.Y, ln.StartPoint.Z)
End If

 

*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 2 of 4

Re: Selection set by single point .

09-02-2013 07:18 AM in reply to: aliensinearth

Try this code snip:

                   Dim ppo As New PromptPointOptions(vbLf & "Pick a Point: ")
                    Dim ppr As PromptPointResult
                    ppr = ed.GetPoint(ppo)
                    If ppr.Status <> PromptStatus.OK Then
                        ed.WriteMessage(vbCrLf & "wrong point specification!")
                        Exit Sub
                    End If
                    Dim p As Point3d = ppr.Value
                    '------------------------------------------------------------''
                    Dim vd As Vector3d = New Vector3d(1e-4, 1e-4, 1e-4) '<--  dicrease a fuzz to suit
                    Dim pMin As Point3d = p - vd
                    Dim pMax As Point3d = p + vd              
                    Dim tvs() As TypedValue = New TypedValue() { New TypedValue(0, "line")}
                    Dim points As Point3dCollection = New Point3dCollection
                    points.Add(pMin)
                    points.Add(pMax)
                    Dim sf As SelectionFilter = New SelectionFilter(tvs)
                    Dim sres As PromptSelectionResult = ed.SelectFence(points, sf)
                    If sres.Status <> PromptStatus.OK Then
                        ed.WriteMessage("\nWrong selection!")
                        Return
                    End If

                    If sres.Value.Count = 0 Then
                        ed.WriteMessage("\nNothing selected!")
                        Return
                    End If
                    '' cast entity as Line
                    Dim eid As ObjectId = sres.Value.GetObjectIds(0)
                    Dim ent As Entity = TryCast(tr.GetObject(eid, OpenMode.ForRead), Entity)
                    ''-----------------------------------------------------------''
                    Dim ln As Line = TryCast(ent, Line)
                    If ln IsNot Nothing Then
                        ed.WriteMessage(vbLf + "{0},{1},{2}", ln.StartPoint.X, ln.StartPoint.Y, ln.StartPoint.Z)
                    End If

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
34 Posts
5 Kudos
Registered: ‎09-02-2013
Post 3 of 4

Re: Selection set by single point .

09-02-2013 08:27 AM in reply to: Hallex
Thank you very much Hallex. It is working fine.
But one small problem is that, If two objects lie in the same point, Lisp code selects the top object in display order. But .Net is selecting both objects. It's OK i will manage.
Thanks once again.
Distinguished Contributor
109 Posts
7 Kudos
Registered: ‎04-05-2012
Post 4 of 4

Re: Selection set by single point .

09-04-2013 04:56 AM in reply to: aliensinearth
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!