"empty" text strings in vba

Discussion in 'AutoCAD' started by Lunt, Aug 11, 2004.

  1. Lunt

    Lunt Guest

    Im coding an app where I am checking dwg for "empty" text strings (on a purge) then I want to delete all empty text strings from drawing..any suggestions?
    can I use dxf code for this?
     
    Lunt, Aug 11, 2004
    #1
  2. Lunt

    bcoward Guest

    pseudo

    For each text object

    If Obj.Text = VBNULLSTRING then Obj.Delete

    Next

    Code it and see if it works for you.

    Good luck,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, Aug 11, 2004
    #2
  3. Lunt

    Lunt Guest

    maybe i should clarify a bit...I need to check all text string objects (is a selectionset, dxf code, or collection?)....check all strings for "empty"
     
    Lunt, Aug 11, 2004
    #3
  4. Lunt

    TomD Guest

    a selectionset, dxf code, or collection?)....check all strings for "empty"

    I don't see why using DXF code filtering wouldn't work, something like:

    Dim vCode(1) as Integer, vVal(1) as Variant
    vCode(0) = 0: vVal(0) = "TEXT"
    vVal(1) = 1: vVal(1) = ""

    ....then the selection set stuff. I'm not certain this would work, but I
    can't think of any reason why it wouldn't.

    As a sidenote, I don't think the nullsting idea would work. Hopefully
    someone will correct me if I'm wrong on that one, I'm still fairly new to
    VBA.
     
    TomD, Aug 12, 2004
    #4
  5. vbnullstring is the prefered method but "" will work as well

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 12, 2004
    #5
  6. Lunt

    TomD Guest

    Thank you, Mike. That's one of the biggest things that confuses me with
    VBA, still.

    .....it is so much easier with lisp. ;)
     
    TomD, Aug 12, 2004
    #6
  7. Lunt

    Lunt Guest

    For Each acdEmptyString In ThisDrawing.ModelSpace

    If acdEmptyString.Text = " " Then acdEmptyString.Delete

    Next

    "Object does not support this property or method?hmmmm
     
    Lunt, Aug 12, 2004
    #7
  8. Lunt

    Lunt Guest

    I got it thanks.....
     
    Lunt, Aug 12, 2004
    #8
  9. Lunt

    Jackrabbit Guest

    If the drawings are large use selection sets instead of iterating through all of the entities...
    [pre]
    Public Sub DeleteNullStrings()
    Dim Entity As AcadEntity
    Dim Text As AcadText
    Dim MText As AcadMText

    For Each Entity In ThisDrawing.ModelSpace
    If TypeOf Entity Is AcadText Then
    Set Text = Entity
    If Text.TextString = vbNullString Then
    Text.Delete
    End If
    ElseIf TypeOf Entity Is AcadMText Then
    Set MText = Entity
    If MText.TextString = vbNullString Then
    MText.Delete
    End If
    End If
    Next Entity

    For Each Entity In ThisDrawing.PaperSpace
    If TypeOf Entity Is AcadText Then
    Set Text = Entity
    If Text.TextString = vbNullString Then
    Text.Delete
    End If
    ElseIf TypeOf Entity Is AcadMText Then
    Set MText = Entity
    If MText.TextString = vbNullString Then
    MText.Delete
    End If
    End If
    Next Entity
    End Sub
    [/pre]
     
    Jackrabbit, Aug 12, 2004
    #9
  10. Lunt

    MP Guest

    or to be on the safe side...

    If Trim(acdEmptyString.TextString) = "" Then acdEmptyString.Delete

    (in case theres' multiple spaces)
     
    MP, Aug 12, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.