.NET

Reply
Contributor
david.sexton
Posts: 16
Registered: ‎04-12-2006
Message 1 of 4 (124 Views)

Trying to erase a text object

124 Views, 3 Replies
06-08-2012 08:14 AM

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

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,051
Registered: ‎06-29-2007
Message 2 of 4 (122 Views)

Re: Trying to erase a text object

06-08-2012 08:17 AM in reply to: david.sexton

Hi,

 

transaction-committing is missing :smileywink:

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
david.sexton
Posts: 16
Registered: ‎04-12-2006
Message 3 of 4 (119 Views)

Re: Trying to erase a text object

06-08-2012 08:43 AM in reply to: Alfred.NESWADBA

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

*Expert Elite*
Alfred.NESWADBA
Posts: 9,051
Registered: ‎06-29-2007
Message 4 of 4 (116 Views)

Re: Trying to erase a text object

06-08-2012 08:53 AM in reply to: david.sexton

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 :smileywink:

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

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