.NET

.NET

Reply
*Tony Tanzillo
Message 21 of 28 (180 Views)

Re: Mono condition to multy condition.

12-18-2006 09:28 AM in reply to: gilseorin
Why are you using a queue to buld a selection
filter? What's wrong with just initializing the
filter from a literal array of TypedValue[] ?????

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5428931@discussion.autodesk.com...
Maybe this will help:
[code]
Public Sub GetEntity()
Dim currentEditor As AcED.Editor = AcAS.Application.DocumentManager.MdiActiveDocument.Editor

'Setup Selection Options
Dim SelectionOpts As AcED.PromptSelectionOptions = New AcED.PromptSelectionOptions()
With SelectionOpts
SelectionOpts.MessageForAdding = ControlChars.NewLine & "Select Text Objects: "
SelectionOpts.MessageForRemoval = ControlChars.NewLine & "Only Text/MText Objects may be selected."
SelectionOpts.AllowDuplicates = False
End With

'Setup Selection Filter
Dim selfilQue As New Generic.Queue(Of AcadDS.TypedValue)
With selfilQue
.Enqueue(New Autodesk.AutoCAD.DatabaseServices.TypedValue(-4, "<AND"))
.Enqueue(New Autodesk.AutoCAD.DatabaseServices.TypedValue(8, "YourLayerName"))
.Enqueue(New Autodesk.AutoCAD.DatabaseServices.TypedValue(-4, "<OR"))
.Enqueue(New Autodesk.AutoCAD.DatabaseServices.TypedValue(0, "TEXT"))
.Enqueue(New Autodesk.AutoCAD.DatabaseServices.TypedValue(0, "MTEXT"))
.Enqueue(New Autodesk.AutoCAD.DatabaseServices.TypedValue(-4, "OR>"))
.Enqueue(New Autodesk.AutoCAD.DatabaseServices.TypedValue(-4, "AND>"))
End With
Dim selFil As New Autodesk.AutoCAD.EditorInput.SelectionFilter(selfilQue.ToArray)

'Query for the Objects
Dim SelectionResult As AcED.PromptSelectionResult = currentEditor.GetSelection(SelectionOpts, selFil)
If SelectionResult.Status = AcED.PromptStatus.OK Then
Using Doc As AcadAS.Document = AcadAS.Application.DocumentManager.MdiActiveDocument
Using trans As AcDB.Transaction = Doc.TransactionManager.StartTransaction
For Each selObj As AcED.SelectedObject In SelectionResult.Value
Using dbObj As AcDB.DBObject = trans.GetObject(selObj.ObjectId, AcDB.OpenMode.ForRead)
If TypeOf dbObj Is AcDB.DBText Then
Using selectedText As AcDB.DBText = DirectCast(dbObj, AcDB.DBText)
AcAS.Application.ShowAlertDialog(" Text: " & selectedText.Height.ToString)
End Using
ElseIf TypeOf dbObj Is AcDB.MText Then
Using selectedText As AcDB.MText = DirectCast(dbObj, AcDB.MText)
AcAS.Application.ShowAlertDialog("MText: " & selectedText.TextHeight.ToString)
End Using
End If
End Using
Next
trans.Commit()
End Using
End Using
End If
End Sub
[/code]

C
*Paul Richardson
Message 22 of 28 (180 Views)

Re: Mono condition to multy condition.

12-18-2006 10:52 AM in reply to: gilseorin
I'm using the same. Here is the test I did.

wrote in message news:5428776@discussion.autodesk.com...
VS. 2005 and AutoCAD 2007
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 23 of 28 (180 Views)

Re: Mono condition to multy condition.

12-18-2006 12:24 PM in reply to: gilseorin
Tony,

The code I posted used a queue because it was based upon a Filter class I have been using (in which I inherit a generic queue of TypedValue). I use a queue to ensure that one cannot add an item to the middle of the list. So when I call '.ToArray' I am assured that the list contains items added in the correct order (or it is at least my hope).

And why is using a queue a horrible thing? It saves on having to set each TypedValue member by array index (which should help with maintainability).

I guess that if the biggest concern that you have with my sample is why I used a particular variable type, I should consider myself lucky. :smileyhappy:

I believe the code sample I posted answers the OPs question, plus it may give insight in how to use many new features in VS2005.

Now having said all that here is the array:
[code]
Dim selfilQue(6) As AcDB.TypedValue
selfilQue(0) = New AcDB.TypedValue(-4, "<AND")
selfilQue(1) = New AcDB.TypedValue(8, "YourLayerName")
selfilQue(2) = New AcDB.TypedValue(-4, "<OR")
selfilQue(3) = New AcDB.TypedValue(0, "TEXT")
selfilQue(4) = New AcDB.TypedValue(0, "MTEXT")
selfilQue(5) = New AcDB.TypedValue(-4, "OR>")
selfilQue(6) = New AcDB.TypedValue(-4, "AND>")
[/code]
Distinguished Contributor
gilseorin
Posts: 177
Registered: ‎09-05-2006
Message 24 of 28 (180 Views)

Re: Mono condition to multy condition.

12-18-2006 01:14 PM in reply to: gilseorin
Thank you,Paul.
It works great. I appreciate your kindness.
Be happy. And Have a Good Day.
Distinguished Contributor
gilseorin
Posts: 177
Registered: ‎09-05-2006
Message 25 of 28 (180 Views)

Re: Mono condition to multy condition.

12-18-2006 01:20 PM in reply to: gilseorin
Thank you for your kind reply.
Your code works great one time.
And from second time occurs an error.
But great, 'cause I learned new skill from your code.
Thank you again.
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 26 of 28 (180 Views)

Re: Mono condition to multy condition.

12-19-2006 06:28 AM in reply to: gilseorin
You are welcome. I didn't add any error handling to it though. Can you post the error? What are the failure circumstances?

C
Distinguished Contributor
gilseorin
Posts: 177
Registered: ‎09-05-2006
Message 27 of 28 (180 Views)

Re: Mono condition to multy condition.

12-19-2006 09:31 AM in reply to: gilseorin
I just excuted as contents of coding you provided.
Only different thing is no ACAS, ACAD ... expression.
*Tony Tanzillo
Message 28 of 28 (180 Views)

Re: Mono condition to multy condition.

12-19-2006 03:56 PM in reply to: gilseorin
Sorry, but I don't really understand what you're getting at.

Regarding: "The code I posted used a queue because it was based upon a Filter class I have been using":

But what does that have to do with basic selection set filter usage? Are you trying to teach the OP how to use your private code, or how to use a selection set filter?

Is there a point to muddying the waters or confusing them with a queue, when the basic initialization of a selection set filter neither requires nor should use a queue to begin with? In this case, where the filter itself is expressed literally in code, there is absolutely no point or purpose to using a queue.

Typically, when initializing a filter that's expressed literally in code, you just initialize the selection filter to an array of typed values, using (C#):

SelectionFilter filter = new SelectionFilter(
new TypedValue[] { new TypedValue(0, "TEXT,MTEXT"),
new TypedValue(8, "MYLAYER) });

>> And why is using a queue a horrible thing? It saves on having to set each TypedValue member by array index (which should help with maintainability). <<

Huh? Do you see any array indices in the code above?

>> I believe the code sample I posted answers the OPs question, plus it may give insight in how to use many new features in VS2005. <<

No not really.

First, the OP's and your use of logical operators in the filter list is in this case, unnecessary and needlessly overcomplicated. See the example code above where the entity type contains multiple stings separated by a comma - because it is a wildcard pattern.

Second, you didn't really introduce the OP to the basic use of SelectionFilter. You only confused the whole subject by needlessly introducing a queue, where its use is completely pointless.

Insofar as insight, it certainly does offer some. Most notably, on why one should avoid the temptation of using a particular class, inappropriately, and only for the sake of using the class.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.