.NET

Reply
Contributor
Posts: 16
Registered: ‎04-12-2006
Message 1 of 4 (114 Views)

Trying to erase a text object

114 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: 8,512
Registered: ‎06-29-2007
Message 2 of 4 (112 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
Posts: 16
Registered: ‎04-12-2006
Message 3 of 4 (109 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: 8,512
Registered: ‎06-29-2007
Message 4 of 4 (106 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
-------------------------------------------------------------------------

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community