Message 1 of 7
Macro Not Working on AutoCad 2018

Not applicable
06-19-2020
07:03 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, everyone!
I updated my AutoCad software from 2012 to 2018 and my macro just stopped working.
I use it to get some information of the draw number in my database and fill a layout block with it. I made a little research and I think it happens because of some incompatibility issues of VBA 7.1 (x64). I dont have much knowledge in programming and I really don´t know how to "convert" this code to a x64 version (if this is the cause of my issue)
When i enter the draw number (Registro) and type enter, my autocad 2018 freezes and i need to use the task manager to close it.
Can anyone help me?
This is my form:
Here is the code of the form:
Option Explicit
Private Sub btnok_Click()
On Error Resume Next
Form.Delete
AlterarDados Me.cmpregistro
Unload Me
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim oEnt As AcadEntity
Dim Pt(0 To 2) As Double
Dim oLWP As AcadLWPolyline
Dim oP As AcadPolyline
Dim oP3D As Acad3DPolyline
ThisDrawing.Utility.GetEntity oEnt, Pt, "Selecione o objeto"
If TypeOf oEnt Is AcadLWPolyline Then
Set oLWP = oEnt
' Do your thing here. The coordinates array has X value on all the even items and Y value on all the odd items in the array
ElseIf TypeOf oEnt Is AcadPolyline Then
Set oP = oEnt
' Do your thing here. The coordinates array has X value on 0, 3, 6 .... items and Y value on 1, 4, 7 .... and Z values on 2, 5, 8 .... in the array
ElseIf TypeOf oEnt Is Acad3DPolyline Then
Set oP3D = oEnt
' Do your thing here. The coordinates array has X value on 0, 3, 6 .... items and Y value on 1, 4, 7 .... and Z values on 2, 5, 8 .... in the array
Else
MsgBox "Twit. You need to select a polyline !!!", vbCritical
End If
End Sub
And the code of the module i use:
Global Form As AcadBlockReference
Global Form2 As AcadBlockReference
Sub AlterarDados(varregistro As Variant)
On Error Resume Next
Dim SQL As String
Dim insertptForm(0 To 2) As Double
Dim wsp As Workspace
Dim Banco As Database
Dim tabela As Recordset
Dim tabela2 As Recordset
Dim varAttributes As Variant
Dim contador As Integer
Dim contador2 As Integer
'DBEngine.SystemDB = "c:\cib\GROUP\Sector.MDW"
'Set wsp = CreateWorkspace("c:\CIB\GROUP\Sector.MDW", "lucas", "enak-132010")
Set Banco = OpenDatabase("\\192.168.3.254\pcp2019\dbs\colineSpartacus.mdb")
Set tabela = Banco.OpenRecordset("select * from base_codProcesso where codProcesso=" & varregistro, dbOpenDynaset)
While Not tabela.EOF
'Define o ponto de inserção
insertptForm(0) = 0
insertptForm(1) = 0
insertptForm(2) = 0
If (tabela("Unidade") = "CJ") Then
Set Form = ThisDrawing.ModelSpace.InsertBlock(insertptForm, "FORMATOCJ", 1, 1, 1, 0)
varAttributes = Form.GetAttributes
varAttributes(0).TextString = ""
Set tabela2 = Banco.OpenRecordset("select * from autocad_folha_processo_CJ where ID=" & tabela("idProcesso") & " order by t_item_PCJ", dbOpenDynaset)
varAttributes(0).TextString = tabela2("t_cliente")
varAttributes(1).TextString = tabela2("n_qtde")
varAttributes(2).TextString = tabela2("n_of")
varAttributes(3).TextString = Format(tabela2("n_pesototal"), "##0.00")
varAttributes(4).TextString = tabela2("t_desenho")
varAttributes(5).TextString = tabela2("t_posicao")
varAttributes(6).TextString = tabela2("t_revisao")
varAttributes(7).TextString = tabela2("t_clientefinal")
varAttributes(8).TextString = tabela2("d_dataatual")
varAttributes(9).TextString = tabela2("t_projeto")
varAttributes(10).TextString = tabela2("t_tipagem")
varAttributes(11).TextString = tabela2("t_codprocesso")
varAttributes(12).TextString = tabela2("t_numre")
varAttributes(13).TextString = tabela2("t_descritivo")
varAttributes(14).TextString = tabela2("t_dimensoesembarque")
varAttributes(15).TextString = tabela2("t_revisao")
varAttributes(16).TextString = tabela2("d_dataatual")
varAttributes(20).TextString = Format(tabela2("n_pesototal"), "##0.00")
varAttributes(21).TextString = ""
varAttributes(22).TextString = tabela2("t_posicao")
varAttributes(23).TextString = tabela2("n_qtde")
varAttributes(24).TextString = tabela2("t_descritivo")
varAttributes(25).TextString = tabela2("t_obs")
'INICIA UM LOOPING PARA AS PCJS
contador = 0
contador2 = 1
While Not tabela2.EOF
Set Form2 = ThisDrawing.ModelSpace.InsertBlock(insertptForm, "LINHA" & contador2, 0.0454977, 0.0454977, 0.0454977, 0)
varAttributes = Form2.GetAttributes
varAttributes(6).TextString = Format(tabela2("n_peso_PCJ"), "##0.00")
varAttributes(5).TextString = tabela2("t_composicao_PCJ")
varAttributes(4).TextString = tabela2("t_item_PCJ")
varAttributes(3).TextString = tabela2("n_qtde_PCJ")
varAttributes(2).TextString = tabela2("t_material_PCJ") & " " & tabela2("t_obs_PCJ")
varAttributes(1).TextString = tabela2("t_codprocesso_PCJ")
varAttributes(0).TextString = tabela2("t_dimensoes_PCJ")
tabela2.MoveNext
contador = contador + 7
contador2 = contador2 + 1
Wend
Else
Set Form = ThisDrawing.ModelSpace.InsertBlock(insertptForm, "FORMULÁRIO", 1, 1, 1, 0)
varAttributes = Form.GetAttributes
Set tabela2 = Banco.OpenRecordset("select * from autocad_folha_processo where ID=" & tabela("idProcesso"), dbOpenDynaset)
If (UserForm1.semdesenho.Value = True) Then
varAttributes(16).TextString = "SEM DESENHO"
SQL = "update Processos_origem set SemDesenho = true, Desenho = 'SEM DESENHO' where ID =" & tabela("idProcesso")
Banco.Execute (SQL)
Else
varAttributes(16).TextString = ""
End If
If (tabela2("Uni") = "PC") Then
varAttributes(0).TextString = ""
varAttributes(1).TextString = ""
varAttributes(2).TextString = ""
varAttributes(3).TextString = ""
varAttributes(9).TextString = ""
Else
varAttributes(0).TextString = tabela2("DesenhoCJ")
varAttributes(1).TextString = tabela2("qtdeCJ")
varAttributes(2).TextString = tabela2("RegCJ")
varAttributes(3).TextString = tabela2("Item")
varAttributes(9).TextString = tabela2("codkit")
End If
varAttributes(4).TextString = Format(tabela2("PesoTotal"), "##0.00")
varAttributes(5).TextString = tabela2("Comprimento")
varAttributes(6).TextString = tabela2("Largura")
varAttributes(7).TextString = tabela2("qtdee")
varAttributes(8).TextString = tabela2("identificacao")
varAttributes(10).TextString = tabela2("Uni")
varAttributes(11).TextString = tabela2("numOF")
varAttributes(12).TextString = tabela2("numRegistro")
varAttributes(13).TextString = tabela2("qtded")
varAttributes(14).TextString = tabela2("composicao")
varAttributes(15).TextString = tabela2("material")
End If
tabela.MoveNext
Wend
tabela.Close
tabela2.Close
Banco.Close
End Sub
Sub openForm2()
UserForm1.Show
End Sub
Thanks!!