Hallo masterk,
hier ein Stück Programmcode zum weiterbasteln.
Ablauf ist folgender:
Die Hintergrundfarbe wird auf Weis gesetzt
Ein JPG mit dem Namen temp.jpg wird auf c:\ erstellt
Die Hintergrundfarbe wird auf Ursprung zurückgesetzt
Ein Drawing wird erstellt
Das Bild wird eingefügt
Das Drawing wird als PDF nach c:\test.pdf exportiert
Die Zeichnung wird verworfen
Vielleicht etwas umständlich aber es funktioniert.
Der folgende Code muß in ein CATIA VBA Modul kopiert werden:
C4N
Bernd
'**** CUT HERE ****
Sub CATMain()
'**************************************************************
'*
'* PDF von Produkt oder Part erstellen
'*
'**************************************************************
' PAPIERFORMAT DEFINIEREN
DrawingPaperSize = 6
'0 = catPaperLetter The US Letter format (8.5 x 11")
'1 = catPaperLegal The Legal format (8.5 x 14")
'2 = catPaperA0 The A0 ISO format (841 x 1189 mm)
'3 = catPaperA1 The A1 ISO format (594 x 841 mm)
'4 = catPaperA2 The A2 ISO format (420 x 594 mm)
'5 = catPaperA3 The A3 ISO format (297 x 420 mm)
'6 = catPaperA4 The A4 ISO format (210 x 297 mm)
'7 = catPaperA The A ANSI format (8.5 x 11")
'8 = catPaperB The B ANSI format (11 x 17")
'9 = catPaperC The C ANSI format (17 x 22")
'10 = catPaperD The D ANSI format (22 x 34")
'11 = catPaperE The E ANSI format (34 x 44")
'12 = catPaperF The F ANSI format (28 x 40")
'13 = catPaperUser The customized format
'PAPIERAUSRICHTUNG DEFINIEREN
DrawingOrientation = 1
'0 = catPaperPortrait The portrait paper orientation
'1 = catPaperLandscape The landscape paper orientation
'2 = catPaperBestFit The paper orientation, chosen among portrait and landscape when printing, to best fit the printed image into the available space in the sheet of paper.
'MAXIMALE BILDGROESSE DEFINIEREN
DrawingPictureMaxHeight = 200
DrawingPictureMaxWidth = 300
'EINFÜGEPUNKT DEFINIEREN (Position linkes unteres Eck des Bildes zu linkem unteren Eck des Blattes)
DrawingPictureX = 0
DrawingPictureY = 0
'Überschreibwarnungen aus
Dim FileAlertSave As Boolean
FileAlertSave = CATIA.DisplayFileAlerts
CATIA.DisplayFileAlerts = False
Dim AktivesDokument As Document
Set AktivesDokument = CATIA.ActiveDocument
BildSpeichernUnter = "c:\temp.jpg"
Set PictureViewer = CATIA.ActiveWindow.ActiveViewer
'Aktuelle Hintergrundfarbe auf Variable
Dim color(2)
PictureViewer.GetBackgroundColor color
'Hintergrund auf Weis
PictureViewer.PutBackgroundColor Array(1, 1, 1)
'Bild erstellen
PictureViewer.CaptureToFile catCaptureFormatJPEG, "" + BildSpeichernUnter
'Hintergrundfarbe zurückseten
PictureViewer.PutBackgroundColor Array(color(0), color(1), color(2))
'Zeichnungsdokument erstellen und Einstellungen vornehmen
Dim documents1 As Documents
Set documents1 = CATIA.Documents
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = documents1.Add("Drawing")
drawingDocument1.Standard = catISO
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets
Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Blatt .1")
drawingSheet1.PaperSize = DrawingPaperSize
'Fenster ZOOMEN
Dim specsAndGeomWindow1 As SpecsAndGeomWindow
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Dim specsViewer1 As SpecsViewer
Set specsViewer1 = specsAndGeomWindow1.ActiveViewer
specsViewer1.Reframe
' Bild einfügen
Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views
Set BauteilPicture = drawingViews1.Item(1).Pictures.Add("" & BildSpeichernUnter, DrawingPictureX, DrawingPictureY)
'Bildgroesse ermitteln
OriginalPictureHeight = BauteilPicture.GetOriginalHeight()
OriginalPictureWidth = BauteilPicture.GetOriginalWidth()
' Scalefaktor errechnen
If OriginalPictureHeight > OriginalPictureWidth Then
DrawingPictureScale = OriginalPictureHeight / DrawingPictureMaxHeight
Else
DrawingPictureScale = OriginalPictureWidth / DrawingPictureMaxWidth
End If
'Bild skalieren
BauteilPicture.Height = OriginalPictureHeight / DrawingPictureScale
BauteilPicture.Width = OriginalPictureWidth / DrawingPictureScale
drawingViews1.Item(1).Activate ' Item(1) ist das Referenzsystem vom Blatt
'Zeichnungsdokument exportieren
drawingDocument1.ExportData "c:\test.pdf", "pdf"
'Zeichnung schliessen
drawingDocument1.Close
'Überschreibwarnungen ein
CATIA.DisplayFileAlerts = True
MsgBox "MAKRO BEENDET"
End Sub
'*** CUT HERE ****
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP