Code:
Language="VBSCRIPT"
'Create by Sergej Hempel 14-12-2012
'Contact: sergej.hempel@de.araymond.com
'Contact2: +49 7621 668 4511
Version 2.1
'---------------------------------------
'Macro erstellt ein PDF vom ersten Zeichnungsblatt
'und öffnet es in Acrobat Reader
'----------------------------------------
Sub CATMain()
Dim fso
Dim oPDF
Dim PDFName As String
Dim oDocument As Document
Dim FoldObj As Folder
Dim Path As String
Dim TMPDIR As String
Dim TRGDIR As String
Dim NAMETMP As String
Dim NAMEPKT
Dim objIntExplorer As Object
'PfadKonfiguration
Path ="\\de.ray.group\catiav5$\"
TMPDIR = Path +CATIA.SystemService.Environ("USERNAME") &"\temp_pdf"
TRGDIR = Path +CATIA.SystemService.Environ("USERNAME") &"\export"
'File System
Set fso = CreateObject("Scripting.FileSystemObject")
'Dokument geoeffnet?
If CATIA.Documents.Count = 0 Then
Box = MsgBox("Es wurde kein aktives Dokument identifiziert" + Chr(10) + "Bitte oeffnen Sie zuerst ein Dokument und starten Sie dann das Makro erneut", vbInformation, "HINWEIS")
Exit Sub
End If
Set oDocument = CATIA.ActiveDocument
'Drawing geoeffnet?
If TypeName(oDocument) <> "DrawingDocument" Then
Box = MsgBox("Dokument ist keine Drawing!" + Chr(10) + "Macro wurde abgebrochen", vbInformation, "ERROR")
Exit Sub
End If
'nur ein Blatt
Set oSheets = oDocument.Sheets
If oSheets.Count < 2 then
Box = MsgBox("Zeichnung hat nur ein Blatt, benutzen Sie die SPEICHERN ALS-Funktion" + Chr(10) + "Macro wird abgebrochen", vbInformation, "ERROR")
Exit Sub
End If
'Blattname prüfen
Set oSheets = oDocument.Sheets
Set Sheet = oSheets.Item(1)
Blattnamealt=Sheet.Name
Blattname = Sheet.Name
If Blattname <>"Blatt.001" then
MsgBox "Blattname wird temporär geändert!"
Sheet.Name="Blatt.001"
End If
'Arbeitsverzeichnise anlegen
Set FoldObj =CATIA.FileSystem.CreateFolder(TMPDIR)
'PDF ausschreiben
NAMETMP = Left(oDocument.Name, 11)
NAMEPKT = InStr (NAMETMP, ".")
If NAMEPKT <>0 Then
MsgBox "Zeichnungsname hat weniger als 11 Zeichen: Die Namenskonvetion ist nicht eingehalten!" + Chr(10) + "Macro wird abgebrochen", vbInformation, "ERROR"
Exit Sub
End If
oDocument.ExportData TMPDIR+"\"+NAMETMP, "pdf"
'Bereits vorhandene suchen
IF fso.FileExists(TRGDIR+"\"+NAMETMP+".pdf") = TRUE then
fso.CopyFile TRGDIR+"\"+NAMETMP+".pdf",TRGDIR+"\"+NAMETMP+"_alt.pdf", TRUE
Box = MsgBox("Dokument mit gleichen Namen war bereits vorhanden!" + Chr(10) + "Vorhandene Datei wurde umbenannt in "+NAMETMP+"_alt.pdf" , vbInformation, "Hinweis")
fso.DeleteFile TRGDIR+"\"+NAMETMP+".pdf"
End if
'PDFumbenennen
Set oPDF = fso.GetFile(TMPDIR+"\"+NAMETMP+"_Blatt_001.pdf")
oPDF.name = NAMETMP+".pdf"
'PDF verschieben
fso.CopyFile oPDF, TRGDIR+"\"+NAMETMP+".pdf", True
fso.DeleteFolder(TMPDIR)
Sheet.Name=Blattnamealt
msgbox "PDF-File von"+NAMETMP+" wurde in "+TRGDIR+" gespeichert!"+ Chr(10) + "und wird jetzt geöffnet" , vbInformation, "Hinweis"
'PDF öffnen
Set objIntExplorer = CreateObject("InternetExplorer.Application")
objIntExplorer.Visible = True
objIntExplorer.Navigate TRGDIR+"\"+NAMETMP+".pdf"
End Sub