Hallo Zusammen,
Ich wollte mir mittels VBA einen "Batchrunner" für ACAD baun, dieser soll in allen Zeichnungen eines Ordners das selbe Kommando ausführn und dann wie in der Form eingestellt (Format und Pfad) abspeichern werden.
Leider bin ich was die Direkte Steuerung aus VBA angeht nicht wirklich fit. Deswegen folgender Ansatz:
Mit VBA ein Skript erstellen und im ACAD aufrufen
Hier mein Code:
Private Sub CommandButton3_Click()
Open "C:\batchrunner.scr" For Output As #1
z = 0
Print #1, "filedia 0"
Print #1, "cmddia 0"
verz = TextBox1.Text
verz2 = TextBox2.Text & "\"
If verz = "" Then
MsgBox ("Bitte Input-Feld Prüfen!")
End If
If OptionButton1.Value = True Then
typ = "dwg"
End If
If OptionButton2.Value = True Then
typ = "dxf"
End If
b$ = Dir(verz & "\*." & typ)
Do Until b$ = ""
z = z + 1
b$ = Dir
Loop
MsgBox (z & " Dateien gefunden." & (Chr(13) & Chr(10)) & "möchten Sie fortfahren"), 1, Abfrage
If Antwort = vbCancel Then
End
End If
'Zeichnung öffnen
a$ = Dir(verz & "\*." & typ)
x = 0
Do Until a$ = ""
x = x + 1
c = verz2 & a$
namen = Left$(a$, Len(a$) - 4)
Print #1, "_open"
Print #1, verz & "\" & a$
Print #1, "zoom"
Print #1, "g"
'Command
If TextBox3.Text <> "" Then Print #1, TextBox3.Text
'DXF speichern
If OptionButton8.Value = True Then
Print #1, "_saveas"
Print #1, "dxf"
Print #1, "v"
Print #1, "r12"
Print #1, "16"
Print #1, c
Print #1, "_close n"
End If
If OptionButton9.Value = True Then
Print #1, "_saveas"
Print #1, "dxf"
Print #1, "v"
Print #1, "2000"
Print #1, "16"
Print #1, c
Print #1, "_close n"
End If
If OptionButton10.Value = True Then
Print #1, "_saveas"
Print #1, "dxf"
Print #1, "v"
Print #1, "2004"
Print #1, "16"
Print #1, c
Print #1, "_close n"
End If
'DWG speichern
If OptionButton3.Value = True Then
Print #1, "_saveas"
Print #1, "2000"
Print #1, c
Print #1, "_close n"
End If
If OptionButton4.Value = True Then
Print #1, "_saveas"
Print #1, "2004"
Print #1, c
Print #1, "_close n"
End If
If OptionButton5.Value = True Then
Print #1, "_saveas"
Print #1, "2007"
Print #1, c
Print #1, "_close n"
End If
'Datei schließen
If x = z Then
Print #1, "filedia"
Print #1, "1"
Print #1, "cmddia"
Print #1, "1"
End If
a$ = Dir
Loop
Close 1
ThisDrawing.SendCommand NewLine("filedia~0~")
ThisDrawing.SendCommand NewLine("script~C:\batchrunner.scr~~")
Unload BatchrunnerForm1
End Sub
Function NewLine(Txt As String) As String
NewLine = Replace(Txt, "~", vbCr)
End Function
Skript erstellen klappt soweit, jedoch Hört ACAD nach dem Schließen der ersten Zeichnung auf.
Ich hab ein Bild meiner Form, sowie das auf c:\ gespeicherte Script (endung zu txt geändert) angehängt.
Ich weiß hier nicht weiter, und bitte euch um Hilfe
Gruß und Danke
Frank
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP