Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cycling through attributes to find values..

Status
Not open for further replies.

basepointdesignz

Programmer
Jul 23, 2002
566
GB
Hi,

I'm having a difficult time trying to get part of a VBA program to work. I have (among others) 7 attributes in a titleblock, which represent revision description on the drawing and what I want to do is loop through the 7 attiributes and check which is the next blank entry and put a value in that one.
So, basically it loops through the attributes and checks if it contains a value (textstring) and if it does, then check the next one, if not then put the new value in there..

Here's the part of the code that's doing my head in (the attribute tags are REV1 - REV7)
You may notice that the attributes are not in numerical order - that's how the attributes are arranged in the block when editing the attributes inside AutoCAD:

Code:
' Change revision number for all CONSTRUCTION drawings..
Private Sub CONSTRUCTION_STATUS()


' Loop through every layout in the drawing..
For Each layoutX In ThisDrawing.Layouts
ThisDrawing.ActiveLayout = layoutX

For Each entX In ThisDrawing.PaperSpace
    ' If the found object is a block..
    If entX.EntityName = "AcDbBlockReference" Then
            If entX.HasAttributes Then  'Check if object has attributes..
            blnAttributes = True  ' True if yes..
            Exit For
            End If
    End If
Next  ' End countx HasAttributes check loop..
            
            
' Start main loop to get attribute values for the attributes..
For Each entX In ThisDrawing.PaperSpace
    ' If the found object is a block..
    If entX.EntityName = "AcDbBlockReference" Then
                attribZ = entX.GetAttributes
                
                    For countx = LBound(attribZ) To UBound(attribZ)
                        Select Case attribZ(countx).TagString
                        
                                ' "Titleblock" block..
                            Case "STATUS"
                                attribZ(countx).TextString = status_text

                            Case "REVNUM"
                                If CheckBox1.Value = True Then
                                    attribZ(countx).TextString = revnumber
                                ElseIf CheckBox1.Value = False Then
                                    attribZ(countx).TextString = ComboBox1.Text
                                End If
                            
                            Case "REV2"
                                If attribZ(countx).TextString <> &quot;&quot; Then
                                    ' Check the next one..
                                Else: attribZ(countx).TextString = revnumber & &quot; - &quot; & revdetails & &quot; - &quot; & Date
                                      GoTo SkipTO
                                End If
                            Case &quot;REV5&quot;
                                If attribZ(countx).TextString <> &quot;&quot; Then
                                    ' Check the next one..
                                Else: attribZ(countx).TextString = revnumber & &quot; - &quot; & revdetails & &quot; - &quot; & Date
                                      GoTo SkipTO
                                End If
                            Case &quot;REV7&quot;
                                If attribZ(countx).TextString <> &quot;&quot; Then
                                    ' If the list is full up..
                                    MsgBox &quot;The revision list on this titleblock is full!!&quot;, , &quot;Revisons List: Full..&quot;
                                Else: attribZ(countx).TextString = revnumber & &quot; - &quot; & revdetails & &quot; - &quot; & Date
                                      GoTo SkipTO
                                End If
                            Case &quot;REV6&quot;
                                If attribZ(countx).TextString <> &quot;&quot; Then
                                    ' Check the next one..
                                Else: attribZ(countx).TextString = revnumber & &quot; - &quot; & revdetails & &quot; - &quot; & Date
                                      GoTo SkipTO
                                End If
                            Case &quot;REV4&quot;
                                If attribZ(countx).TextString <> &quot;&quot; Then
                                    ' Check the next one..
                                Else: attribZ(countx).TextString = revnumber & &quot; - &quot; & revdetails & &quot; - &quot; & Date
                                      GoTo SkipTO
                                End If
                            Case &quot;REV3&quot;
                                If attribZ(countx).TextString <> &quot;&quot; Then
                                    ' Check the next one..
                                Else: attribZ(countx).TextString = revnumber & &quot; - &quot; & revdetails & &quot; - &quot; & Date
                                      GoTo SkipTO
                                End If
                            Case &quot;REV1&quot;
                                If attribZ(countx).TextString <> &quot;&quot; Then
                                    ' Check the next one..
                                Else: attribZ(countx).TextString = revnumber & &quot; - &quot; & revdetails & &quot; - &quot; & Date
                                      GoTo SkipTO
                                End If

                        

        
                            
                            
SkipTO:
                End Select

                    Next countx ' End countx loop..
                    
    End If
Next  ' End attributes loop..

Next layoutX ' End layout loop..


response = MsgBox(&quot;All the layouts have now been been updated..&quot; & Chr(10) & Chr(10) & &quot;Finish with the program now?..&quot;, vbQuestion + vbYesNo, &quot;End the Program..&quot;)
    If response = vbNo Then
        Exit Sub
    End If
    If response = vbYes Then
        statusform.Hide
    End If
End Sub

No matter how I construct the IFs and CASE statements, all the attributes are filled with the value, not the first blank one!!! It just doesn't seem to recognise the GoTo SkipTO function.. Arrgh!!!

Any ideas?

Cheers,

Paul @ basepoint designz..


basepoint designz
renegade@bpdesignz.com
 
The SkipTo: needs to be after Next countx. Also, you may want to first create a selection set of all the Block Inserts in the DWG in Paper Space based on Group Codes - this will eliminate having to cycle through every object in every layout trying to find your blocks. Something like this...

Sub getTitleBlocks()
Dim MySS As AcadSelectionSet
Dim GrpC(0 to 1) As Integer
Dim GrpV(0 to 1) As Variant
GrpC(0) = 2: GrpV(0) = &quot;tb&quot; 'Name of Block
GrpC(1) = 67: GrpV(1) = 1

Set MySS = ThisDrawing.SelectionSets.Add(&quot;TBs&quot;)
MySS.Select acSelectionSetAll, , , GrpC, GrpV
MsgBox MySS.Count & &quot; Title Blocks Found.&quot;
MySS.Delete
End Sub

Hope That Helps,

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top