Block attributes

Discussion in 'AutoCAD' started by Eric Stewart, Aug 8, 2003.

  1. Eric Stewart

    Eric Stewart Guest

    I would like to keep the value for the first attribute of every block in a
    drawing and remove the value for all other attributes. THe problem is that
    not all the blocks have the same number of attributes. I am not doing much
    in ACAD anymore so my VBA is a little rusty.

    Any help would be greatly appreciated.

    --
    What once brought fright
    Now seems oh so trite
    And I'm scared

    To reply directly to me use DEODORANT
     
    Eric Stewart, Aug 8, 2003
    #1
  2. Public Sub ClearAllAttributesExceptFirst()
      Dim AttributeRefs As Variant
      Dim BlockRef As AcadBlockReference
      Dim Entity As AcadEntity
      Dim I As Integer

    For Each Entity In ThisDrawing.ModelSpace
        If TypeOf Entity Is AcadBlockReference Then
          Set BlockRef = Entity
          AttributeRefs = BlockRef.GetAttributes
          For I = LBound(AttributeRefs) To UBound(AttributeRefs)
            If Not I = LBound(AttributeRefs) Then
              AttributeRefs(I).TextString = ""
            End If
          Next I
        End If
      Next Entity

    For Each Entity In ThisDrawing.PaperSpace
        If TypeOf Entity Is AcadBlockReference Then
          Set BlockRef = Entity
          AttributeRefs = BlockRef.GetAttributes
          For I = LBound(AttributeRefs) To UBound(AttributeRefs)
            If Not I = LBound(AttributeRefs) Then
              AttributeRefs(I).TextString = ""
            End If
          Next I
        End If
      Next Entity
    End Sub
     
    Mark_Abercrombie, Aug 8, 2003
    #2
  3. Public Sub ClearAllAttributesExceptFirst()   Dim AttributeRefs As Variant   Dim BlockRef As AcadBlockReference   Dim Entity As AcadEntity   Dim I As Integer

    For Each Entity In ThisDrawing.ModelSpace     If TypeOf Entity Is AcadBlockReference Then       Set BlockRef = Entity       AttributeRefs = BlockRef.GetAttributes       For I = LBound(AttributeRefs) To UBound(AttributeRefs)         If Not I = LBound(AttributeRefs) Then           AttributeRefs(I).TextString = ""         End If       Next I     End If   Next Entity

    For Each Entity In ThisDrawing.PaperSpace     If TypeOf Entity Is AcadBlockReference Then       Set BlockRef = Entity       AttributeRefs = BlockRef.GetAttributes       For I = LBound(AttributeRefs) To UBound(AttributeRefs)         If Not I = LBound(AttributeRefs) Then           AttributeRefs(I).TextString = ""         End If       Next I     End If   Next Entity End Sub
     
    Mark_Abercrombie, Aug 8, 2003
    #3
  4. When you grab the attributes from a block using 'getattributes', you
    save them to an array. You can then use 'ubound' to determine the number
    of elements, save the textstring of element(0), then iterate the array
    removing the other textstring values,,,,,

    arry = blkref.getattributes
    for i = 0 to ubound(arry)
    if i = 0 then
    'save info
    else
    array(i).textstring = ""
    end if
    next i
     
    Minkwitz Design, Aug 8, 2003
    #4
  5. minor simplification : )

    For I = LBound(AttributeRefs)+1 To UBound(AttributeRefs)
    AttributeRefs(I).TextString = ""
    Next I

    James
     
    James Belshan, Aug 8, 2003
    #5
  6. The loop should be skipped over if the first index is > the second...

    Sub test_for()
    For i = 1 To 0
    MsgBox "you won't see this msg box"
    Next 'i
    End Sub

    James
     
    James Belshan, Aug 8, 2003
    #6
  7. Eric Stewart

    Eric Stewart Guest

    Thanks for the help
     
    Eric Stewart, Aug 11, 2003
    #7
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.