FernandoCad Posted April 20, 2023 Posted April 20, 2023 (edited) 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 April 20, 2023 by SLW210 Code Tags!! Quote
SLW210 Posted April 20, 2023 Posted April 20, 2023 Please use Code Tags for Code. See the <> in the toolbar. Quote
BIGAL Posted April 20, 2023 Posted April 20, 2023 only dabble at the egdes of VBA, Is this correct obj.Layer = strBlockLayer. What is strblocklayer does it have a value ? Quote
Recommended Posts
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.