C#ATIA

↑タイトル詐欺 主にFusion360API 偶にCATIA V5 VBA(絶賛ネタ切れ中)

DrawをPDFでエクスポート (未解決)3

こちらの続きです。
DrawをPDFでエクスポート (未解決)2 - C#ATIA

ほぼ使わないので存在すら忘れていましたが、こちらのバッチマネージャに
印刷バッチがある事に気が付きました。
f:id:kandennti:20181214153054p:plain
起動しプリンタでCubePDFを指定すると出ます。
f:id:kandennti:20181214153116p:plain
しかも良く見ると、CATScriptが作れるようです。
(後でわかりましたが、印刷バッチ時に毎回CATScriptを実行しているようです)

VBAエディタにコードを貼り付けます(一部型指定のエラーがあるのでコメント化)

'Language = "VBSCRIPT"
Dim logFile As TextStream

'------------------------------------------
'---- CATMain()
'------------------------------------------
Sub CATMain()
  CATIA.DisplayFileAlerts = False

  '------------------------------------------
  '-  open the log file : C:\Users\XXX\AppData\Local\Temp\PrintBatch.log
  '------------------------------------------
  Dim AppliFileSys 'As FileSystem
  Set AppliFileSys = CATIA.FileSystem
  Dim FileObj As File
  Set FileObj = AppliFileSys.CreateFile("C:\Users\XXX\AppData\Local\Temp\PrintBatch.log", True)
  Set logFile = FileObj.OpenAsTextStream("ForWriting")

  '------------------------------------------
  '-  open the document file : C:\temp\hoge.CATDrawing
  '------------------------------------------
  OpenDocument "C:\temp\hoge.CATDrawing"

  Dim sheet As AnyObject
  Set sheet = CATIA.ActiveDocument.Sheets.Item(1)
  sheet.Activate

  '------------------------------------------
  '-  printer -
  '------------------------------------------
  Dim thePrinter As Printer
  Set thePrinter = CATIA.Printers.Item(3) '←プリンタを指定
  CATIA.ActivePrinter = thePrinter

  '------------------------------------------
  '-  parameters -
  '------------------------------------------
  Dim PageSetUp 'As CATIADrawingPageSetup
  Set PageSetUp = sheet.PageSetUp
  PageSetUp.PaperWidth = 210
  PageSetUp.PaperHeight = 297
  PageSetUp.Orientation = 0
  PageSetUp.LeftMargin = 10
  PageSetUp.RightMargin = 10
  PageSetUp.TopMargin = 10
  PageSetUp.BottomMargin = 10
  PageSetUp.BottomMargin = 10
  PageSetUp.FitToSheetFormat = True
  PageSetUp.MaximumSize = False
  PageSetUp.Left = 0
  PageSetUp.Bottom = 0
  PageSetUp.Zoom = 1
  PageSetUp.Rotation = 0
  PageSetUp.Color = 0
  PageSetUp.Quality = 0
  PageSetUp.Dpi = 150
  PageSetUp.Banner = "xxxx"
  PageSetUp.BannerPosition = 0
  PageSetUp.TextBlanking = False
  PageSetUp.WhiteVectorsInBlack = True
  PageSetUp.LineWidthSpecification = 0
  PageSetUp.LineTypeSpecification = 0
  PageSetUp.LineCap = 0
  PageSetUp.TextScaling = True
  PageSetUp.LineTypeOverlappingCheck = False
  PageSetUp.Gamma = 1
  Dim Document 'As CATIADocument
  Set Document = CATIA.ActiveDocument
  Err.Clear
  On Error Resume Next
  sheet.PrintOut '←印刷
  If Err = 0 Then
    logFile.Write "  Printing done "
  Else
    logFile.Write "  Printing failed "
    Err.Clear
  End If

  Set thePrinter = Nothing
  Set sheet = Nothing

  '------------------------------------------
  '-  close the document file : C:\temp\hoge.CATDrawing
  '------------------------------------------
  CloseDocument

  '------------------------------------------
  '-  close the log file -
  '------------------------------------------
  Set FileObj = Nothing
  Set AppliFileSys = Nothing
  logFile.Write " End of printing   "
  logFile.Close

  MsgBox "End of printing"
End Sub

'-------------------------------------------------------
'---- OpenDocument(FileName)
'-------------------------------------------------------
Sub OpenDocument(FileName As String)
  Dim TheCATIADocument As Document
  On Error Resume Next
  Set TheCATIADocument = CATIA.Documents.Open(FileName)
  If Err = 0 Then
    logFile.Write FileName
    logFile.Write " Opened "
  Else
    logFile.Write FileName
    logFile.Write " Failed to open "
    Err.Clear
  End If
  CATIA.ActiveWindow.WindowState = 0
End Sub

'-------------------------------------------------------
'---- CloseDocument()
'-------------------------------------------------------
Sub CloseDocument()
  Dim ActiveDoc As Document
  Set ActiveDoc = CATIA.ActiveDocument
  On Error Resume Next
  ActiveDoc.Close
  If Err = 0 Then
    logFile.Write " Active document closed "
  Else
    logFile.Write " Failed to close active document "
    Err.Clear
  End If
End Sub

プリンタの指定のインデックス部分は、各々の環境で違うはずです。
印刷自体はDrawingSheetのPrintOutメソッドで行っているんですね。
気が付かなかったです。

で、実行すると・・・白紙なんです。
試しに通常のプリンタを指定して実行しても、プリンタが少しだけ
反応して結局出ないんです。何だか煮え切らないです。

バッチマネージャは何をやっているのだろうか?