Jump to content

Autocad VBA error 438


FernandoCad

Recommended Posts

Anyone knows why this code is giving me the "Run-time error 438  - Object doesn`t support this property or method"

 

Sub MacroAutomatica()
Dim polyline As AcadPolyline
Dim blkRef1 As AcadBlockReference, blkRef2 As AcadBlockReference, blkRef3 As AcadBlockReference
Dim obj As AcadEntity, att As AcadAttribute
Dim strAtt1 As String, strAtt2 As String



For Each polyline In ThisDrawing.ModelSpace.polylines
    ' Encontra o bloco de origem
    Set blkRef1 = Nothing
    For Each obj In ThisDrawing.ModelSpace
        If TypeOf obj Is AcadBlockReference And obj.Layer = strBlockLayer And _
        Round(obj.InsertionPoint(0), 2) = Round(polyline.startPoint(0), 2) And _
        Round(obj.InsertionPoint(1), 2) = Round(polyline.startPoint(1), 2) Then
            Set blkRef1 = obj
            For Each att In blkRef1.GetAttributes()
                If att.TagString = "ATRIBUTO_ORIGEM" Then
                    strAtt1 = att.TextString
                    Exit For
                End If
            Next att
            Exit For
        End If
    Next obj
    
    If blkRef1 Is Nothing Then
        MsgBox "O bloco de origem não foi encontrado para a polyline selecionada."
        GoTo ProximaPolyline
    End If
    
    ' Encontra o bloco de destino
    Set blkRef2 = Nothing
    For Each obj In ThisDrawing.ModelSpace
        If TypeOf obj Is AcadBlockReference And obj.Layer = strBlockLayer And _
        Round(obj.InsertionPoint(0), 2) = Round(polyline.endPoint(0), 2) And _
        Round(obj.InsertionPoint(1), 2) = Round(polyline.endPoint(1), 2) Then
            Set blkRef2 = obj
            For Each att In blkRef2.GetAttributes()
                If att.TagString = "ATRIBUTO_DESTINO" Then
                    strAtt2 = att.TextString
                    Exit For
                End If
            Next att
            Exit For
        End If
    Next obj
    
    If blkRef2 Is Nothing Then
        MsgBox "O bloco de destino não foi encontrado para a polyline selecionada."
        GoTo ProximaPolyline
    End If
    
    ' Encontra o bloco da etiqueta e altera seus atributos
    Set blkRef3 = Nothing
    For Each obj In ThisDrawing.ModelSpace
        If TypeOf obj Is AcadBlockReference And obj.Layer = strEtiquetaLayer And _
        Round(obj.InsertionPoint(0), 2) = Round(polyline.midPoint(0), 2) And _
        Round(obj.InsertionPoint(1), 2) = Round(polyline.midPoint(1), 2) Then
            Set blkRef3 = obj
            For Each att In blkRef3.GetAttributes()
                If att.TagString = "TROCO" Then
                    att.TextString = strAtt1
                ElseIf att.TagString = "EQUIP_DESTINO" Then
                    att.TextString = strAtt2
                End If
                Exit For
            Next att
            Exit For
        End If
    Next obj
    
ProximaPolyline:
Next polyline

' Limpa a seleção de polylines
ThisDrawing.SendCommand "_UNSELECTALL" & vbCr

' Informa o usuário que a macro foi executada com sucesso
MsgBox "A macro foi executada com sucesso!"
End Sub


 

Edited by SLW210
Code Tags!!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...