Message 1 of 7

Not applicable
07-19-2020
04:04 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have been making a small program to change the name of attributes in a block.
The jist of it is:
1º- check if it's one of two types of blocks;
2º- if it is, check if the attribute with the tag "TIPO_EQUIPAMENTO" is "TOPO";
3º- if it is, check if the attribute with the tag "TIPO_AREA" is "PRAC";
4º- if it is, get the attribute with the tag "UN" (X=UN value);
5º- add the x to the attribute with the tag "MERCADO" (Y= MERCADO value; MERCADO value = y & x).
I think I have the logic all there, but it says I have too many End ifs and it does not make sense.
The code is:
'unlock layers
ThisDrawing.Layers("MC_BLOCO_INFO_AREAS").Lock = False
ThisDrawing.Layers("MC_BLOCO_TEXTOS_COMERCIAL").Lock = False
ThisDrawing.Layers("MC_BLOCO_TEXTOS_INV").Lock = False
Dim ss As AcadSelectionSet
Dim filtertype As Variant
Dim filterdata As Variant
Dim grpCode(0) As Integer
Dim grpValue(0) As Variant
grpCode(0) = 2
filtertype = grpCode
'Blocks to filter
grpValue(0) = "BLOCO LAT TOP,BLOCO TOPO PEP"
filterdata = grpValue
'if there are no blocks
If (ThisDrawing.SelectionSets.Count > 0) Then
ThisDrawing.SelectionSets.Item(0).Delete
End If
'block selection
Set ss = ThisDrawing.SelectionSets.Add("blocos")
ss.Select acSelectionSetAll, , , filtertype, filterdata
Dim blk As AcadBlockReference
Dim flg As Boolean
Dim idx As Long
Dim attr As Variant
Dim i As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim x As String
Dim y As String
i = 0
a = 0
b = 0
c = 0
Set blk = ss(0)
'loop selection and process blocks
Dim updated As Boolean '' for debugging only
For Each blk In ss
If (blk.HasAttributes) Then
attr = blk.GetAttributes()
updated = False
For i = 0 To UBound(attr)
If UCase(attr(i).TagString) = "TIPO_EQUIPAMENTO" And _
attr(i).TextString = "TOPO" Then
For a = 0 To UBound(attr)
If UCase(attr(i).TagString) = "TIPO_AREA" And _
attr(i).TextString = "PRAC" Then
For b = 0 To UBound(attr)
If UCase(attr(i).TagString) = "UN" Then
x = attr(i).TextString
For c = 0 To UBound(attr)
If UCase(attr(i).TagString) = "MERCADO" Then
y = attr(i).TextString
attr(i).TextString = y & x
updated = True
End If
Exit For
End If
Exit For
End If
Exit For
End If
updated = True
Next
End If
Next
'update drawing
ThisDrawing.Regen acAllViewports
'lock layers
ThisDrawing.Layers("MC_BLOCO_INFO_AREAS").Lock = True
ThisDrawing.Layers("MC_BLOCO_TEXTOS_COMERCIAL").Lock = True
ThisDrawing.Layers("MC_BLOCO_TEXTOS_INV").Lock = True
'done
MsgBox "Update completed!"
Can someone tell where it failed? in attachment is a target block if you want to test it out.
Solved! Go to Solution.