.NET

Reply
Contributor
18 Posts
0 Kudos
Registered: ‎04-12-2006
Post 1 of 4

Trying to erase a text object

132 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*
9,804 Posts
1,210 Kudos
Registered: ‎06-29-2007
Post 2 of 4

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
18 Posts
0 Kudos
Registered: ‎04-12-2006
Post 3 of 4

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*
9,804 Posts
1,210 Kudos
Registered: ‎06-29-2007
Post 4 of 4

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
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post