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
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
transaction-committing is missing
- alfred -
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!!
>> 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 -
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!