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

Trying to erase a text object

3 REPLIES 3
Reply
Message 1 of 4
david_sexton
344 Views, 3 Replies

Trying to erase a text object

Hello, all.  I've got a sub that grabs all of the text objects in a drawing and then compares the first 20 characters to a defined string.  I want it to be able to erase any objects that are a match prior to moving on to the next object in the selection set.  With the following code, it does everything but erase the object.  Obviously, I'm missing something but I just can't see why it isn't working.  Any suggestions?

 

Thanks for your time and consideration

Dave

 

    Public Sub RemoveDisclaimer()
        Dim myDB As Database = HostApplicationServices.WorkingDatabase
        Dim myDWG As Document = DocumentManager.MdiActiveDocument
        Dim myED As Editor = myDWG.Editor

        Dim dsText As DBText
        Dim dsMText As MText

        Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
            'select all text objects in the drawing
            Dim myBlockTable As BlockTable = myDB.BlockTableId.GetObject(OpenMode.ForRead)
            Dim myTypedValue(3) As TypedValue
            myTypedValue.SetValue(New TypedValue(DxfCode.Operator, "<or"), 0)
            myTypedValue.SetValue(New TypedValue(DxfCode.Start, "Text"), 1)
            myTypedValue.SetValue(New TypedValue(DxfCode.Start, "MText"), 2)
            myTypedValue.SetValue(New TypedValue(DxfCode.Operator, "or>"), 3)
            Dim myFilter As New SelectionFilter(myTypedValue)
            Dim myPSR As PromptSelectionResult = myED.SelectAll(myFilter)
            Dim mySelectionSet As SelectionSet = myPSR.Value

            Dim dsStandard As String = "THIS ENGINEERING JUD"
            Dim dsFCD As String = "THIS FIRESTOP CUSTOM"

            Dim strText As String
            Dim strMText As String

            'cycle through each text object, if it's a match then erase the object
            For Each mySelectedObject In mySelectionSet
                Select Case mySelectedObject.ObjectId.ObjectClass.Name
                    Case "AcDbText"
                        dsText = myTrans.GetObject(mySelectedObject.ObjectId, OpenMode.ForWrite, False, True)
                        strText = dsText.TextString
                        If Left(strText, 20) = dsStandard Or Left(strText, 20) = dsFCD Then
                            dsText.Erase(True)
                            dsText.Dispose()

                        End If
                    Case "AcDbMText"
                        dsMText = myTrans.GetObject(mySelectedObject.ObjectId, OpenMode.ForWrite, False, True)
                        strMText = dsMText.Contents
                        If Left(strMText, 20) = dsFCD Then
                            dsMText.Erase(True)
                            dsMText.Dispose()

                        End If
                End Select
            Next 'mySelectedObject
        End Using 'myTrans

    End Sub

 

3 REPLIES 3
Message 2 of 4

Hi,

 

transaction-committing is missing 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4

So, I'm a moron.  I wrote that code late yesterday and didn't get a chance to test it until this morning.  I stared at it for 2 hours!!  Thanks a lot!!

 

Dave

Message 4 of 4

Hi,

 

>> So, I'm a moron

Oh no, don't say or think something like that.

IMHO all of us have already searched for a bug in our code before recognizing that .Commit it missing 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

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