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

Mono condition to multy condition.

27 REPLIES 27
Reply
Message 1 of 28
gilseorin
1062 Views, 27 Replies

Mono condition to multy condition.

HI, all.
The code below is the example of selecting text, if selected appropriately, Msgbox show the information of height of the text. Additionally to this, I wish to add one more condition,
entity is text and the layername is " LEVEL".
Plz, help me. Good day.

_
Public Sub GetEntity()
Dim currentEditor As AcEd.Editor = AcAs.Application.DocumentManager.MdiActiveDocument.Editor
Dim entitySelectionOpts As AcEd.PromptEntityOptions = New AcEd.PromptEntityOptions("" & Microsoft.VisualBasic.Chr(10) & "Select Text: ")
entitySelectionOpts.SetRejectMessage("" & Microsoft.VisualBasic.Chr(10) & "Only Textes may be selected.")
entitySelectionOpts.AddAllowedClass(GetType(AcDb.DBText), True)
Dim entitySelectionResult As AcEd.PromptEntityResult = currentEditor.GetEntity(entitySelectionOpts)
If entitySelectionResult.Status = AcEd.PromptStatus.OK Then
DisplayTextHeight(entitySelectionResult.ObjectId)
End If
End Sub

Private Sub DisplayTextHeight(ByVal textId As AcDb.ObjectId)
Dim currentEditor As AcEd.Editor = AcAs.Application.DocumentManager.MdiActiveDocument.Editor
' Using
Dim trans As AcDb.Transaction = currentEditor.Document.TransactionManager.StartTransaction
Try
Dim selectedText As AcDb.DBText = CType(trans.GetObject(textId, AcDb.OpenMode.ForRead), AcDb.DBText)
AcAs.Application.ShowAlertDialog("Text: " + selectedText.Height.ToString)
Finally
CType(trans, IDisposable).Dispose()
End Try
End Sub
27 REPLIES 27
Message 21 of 28
Anonymous
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
Message 22 of 28
Anonymous
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
Message 23 of 28
cgay
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. 🙂

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]
Message 24 of 28
gilseorin
in reply to: gilseorin

Thank you,Paul.
It works great. I appreciate your kindness.
Be happy. And Have a Good Day.
Message 25 of 28
gilseorin
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.
Message 26 of 28
cgay
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
Message 27 of 28
gilseorin
in reply to: gilseorin

I just excuted as contents of coding you provided.
Only different thing is no ACAS, ACAD ... expression.
Message 28 of 28
Anonymous
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

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