.NET

Reply
Active Contributor
aliensinearth
Posts: 31
Registered: ‎09-02-2013
Message 1 of 4 (213 Views)
Accepted Solution

Selection set by single point .

213 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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (205 Views)

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
aliensinearth
Posts: 31
Registered: ‎09-02-2013
Message 3 of 4 (196 Views)

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.
Valued Contributor
FRFR1426
Posts: 87
Registered: ‎04-05-2012
Message 4 of 4 (147 Views)

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
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.