.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Selecting a single entity.

3 REPLIES 3
Reply
Message 1 of 4
sgsawdy
481 Views, 3 Replies

Selecting a single entity.

With LISP I can force my selection to be a single entity and of a certain type. I have been able to restrict the type of entity I am selecting, but I have not been able to figure out how to restrict my selection to a single entity pick. My program must not allow more than one entity to be selected or it will not be able to perform the required function.

Any help is appreciated.

Scott
3 REPLIES 3
Message 2 of 4
chiefbraincloud
in reply to: sgsawdy


You use Editor.GetEntity... but assuming you are currently using the selection methods, the way you tell GetEntity to only allow a certain type of object is different than the filtering in selection sets. You have to call SetRejectMessage, then AddAllowedClass on the PromptEntityOptions. Here is a simple example, which returns through byref arguments. You use the AllowedType argument by passing GetType(BlockReference) for example.



Friend Shared Sub EntSelect(ByRef SelObj As ObjectId, ByRef PickPoint As Point3d, ByVal PromptString As String, ByVal AllowedType As System.Type, ByVal RejectMsg As String)



SelObj = Nothing



Dim ed As Editor = AppServ.Application.DocumentManager.MdiActiveDocument.Editor



Try



Dim prEntOps As New PromptEntityOptions(PromptString)



Dim prEntRes As PromptEntityResult



prEntOps.SetRejectMessage(RejectMsg)



prEntOps.AddAllowedClass(AllowedType, True)



prEntOps.AllowNone = False



prEntOps.AllowObjectOnLockedLayer = True



prEntOps.AppendKeywordsToMessage = False



prEntRes = ed.GetEntity(prEntOps)



If prEntRes.Status <> PromptStatus.OK Then Return



PickPoint = prEntRes.PickedPoint



SelObj = prEntRes.ObjectId



Catch ex As System.Exception



ed.WriteMessage(ex.Message & " In: " & ex.Source & vbCrLf & ex.StackTrace & vbCrLf)



Return



Finally



ed = Nothing



End Try



End Sub

Dave O.                                                                  Sig-Logos32.png
Message 3 of 4
Anonymous
in reply to: sgsawdy


You can use the Editor's GetEntity() method to select a
single

object (which is equivalent to LISP's (entsel)
function).

 

You can also restrict the selection to a certain type of
object

using the AddAllowedClass() method of the
PromptEntityOptions

class (but you must call the SetRejectMessage() method
first).


 

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000
through 2009

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
With
LISP I can force my selection to be a single entity and of a certain type. I
have been able to restrict the type of entity I am selecting, but I have not
been able to figure out how to restrict my selection to a single entity pick.
My program must not allow more than one entity to be selected or it will not
be able to perform the required function. Any help is appreciated.
Scott
Message 4 of 4
sgsawdy
in reply to: sgsawdy

Thanks, based on the answers here I was able to come up with the following to get what I needed.

Dim myPrmpt1 As New EditorInput.PromptSelectionOptions
myPrmpt1.AllowDuplicates = False
myPrmpt1.SinglePickInSpace = True
myPrmpt1.SingleOnly = True
myPrmpt1.AllowSubSelections = False
myPrmpt1.RejectObjectsFromNonCurrentSpace = True
myPrmpt1.MessageForAdding = "Select text entity to duplicate: "

myTV(0) = New DatabaseServices.TypedValue(0, "TEXT,MTEXT")
Dim myFilter As New EditorInput.SelectionFilter(myTV)
myTPSR = myEd.GetSelection(myPrmpt1, myFilter)


Works great.

Scott

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost