More block attributes help

More block attributes help

Anonymous
Not applicable
389 Views
3 Replies
Message 1 of 4

More block attributes help

Anonymous
Not applicable
Can someone please help me with this?
For some reason this code works most of the time, but ocassionally when I
run it I get a "Subscript out of range" error. The error is ocurring on the
line
"attr(1).TextString = UserForm1.TextBox4.Text".
I can't figure out why.

Graeme


For j = 0 To dwg.ModelSpace.Count - 1
' call acad entites variable ent
Set Ent = dwg.ModelSpace.Item(j)
' If ent is a block then call it variable blkREF
If TypeOf Ent Is AcadBlockReference Then

If Left(Ent.Name, 13) = "name1" Or Ent.Name = "name2" Then
Set blkREF = Ent
attr = blkREF.GetAttributes


If attr(0).TextString = UserForm1.TextBox1.Text Then
If attr(1).TextString = UserForm1.TextBox2.Text Then
attr(0).TextString = UserForm1.TextBox3.Text
attr(1).TextString = UserForm1.TextBox4.Text
End If
End If
End If
'If Not Ent.ObjectName = "AcDbBlockReference" Then
'Set blkREF = Nothing
'End If
End If
Next j
0 Likes
390 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Are you certain that all of the blocks return two (or more) attributes?
0 Likes
Message 3 of 4

Anonymous
Not applicable
No, one of the blocks retunrs more than 2 attributes but I'm only interested
in the first two attributes. Could my index be wrong?

wrote in message news:[email protected]...
Are you certain that all of the blocks return two (or more) attributes?
0 Likes
Message 4 of 4

Anonymous
Not applicable
It's Ok I think I got it.

It was finding a block that had no attributes so I added an If statement for
BlkRef.HasAttributes.

thanks

Graeme

"Graeme" wrote in message
news:[email protected]...
No, one of the blocks retunrs more than 2 attributes but I'm only interested
in the first two attributes. Could my index be wrong?

wrote in message news:[email protected]...
Are you certain that all of the blocks return two (or more) attributes?
0 Likes