veranco Posted January 27, 2010 Posted January 27, 2010 Hi everyone I'm trying to implement a function with VBA that prints both a pdf (PDFCreator) and then prints to the selected printer. I managed to make the function but I still have three problems: 1st This function should replace the standard print function of autocad, and I cannot seem to find a solution for that. 2nd It works terribly slow (around 120s per layout) 3rd I get two errors (one for each printer) from Windows: 'AutoCAD Application stopped working, ...', the typical windows error. This is a problem, but it is least important because Acad keeps working. Please help. Forgot to mention: AutoCAD 2007 on Windows Vista SP2 32-bit Quote
veranco Posted February 9, 2010 Author Posted February 9, 2010 This is the code I have, maybe that might help someone to help me? Option Explicit Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long) Public Sub PlotPDF() Dim Plotter As String 'Plotter = "\\printserver\HP LaserJet 2420 - Groep 2 (Lade 2)" Plotter = ThisDrawing.ActiveLayout.ConfigName Dim Layout As AcadLayout Set Layout = Nothing On Error GoTo Err_Control Set Layout = ThisDrawing.ActiveLayout Layout.ConfigName = Plotter ' CALL PLOTTER Layout.PlotType = acLayout Layout.PlotWithPlotStyles = True Layout.PlotViewportBorders = False Layout.PlotViewportsFirst = True Layout.PaperUnits = acMillimeters Layout.ShowPlotStyles = False Dim pdfjob As PDFCreator.clsPDFCreator Dim sPDFPath As String Dim sPDFName As String sPDFPath = ThisDrawing.Path + "\pdf\acad" sPDFName = ThisDrawing.ActiveLayout.Name ThisDrawing.Plot.NumberOfCopies = 1 Set pdfjob = New PDFCreator.clsPDFCreator With pdfjob If .cStart("/NoProcessingAtStartup") = False Then MsgBox "Can't initialize PDFCreator.", vbCritical + _ vbOKOnly, "PrtPDFCreator" Exit Sub End If .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveDirectory") = sPDFPath .cOption("AutosaveFilename") = sPDFName .cOption("AutosaveFormat") = 0 ' 0 = PDF .cClearCache End With 'Print the document to PDF ThisDrawing.Plot.PlotToDevice ("PDFCreator") 'Wait until the print job has entered the print queue Do Until pdfjob.cCountOfPrintjobs = 1 DoEvents Loop pdfjob.cPrinterStop = False 'Wait until PDF creator is finished then release the objects Do Until pdfjob.cCountOfPrintjobs = 0 DoEvents Loop pdfjob.cClose Set pdfjob = Nothing Sleep (20000) ' Waits for 20 seconds ThisDrawing.Plot.PlotToDevice ThisDrawing.Regen acAllViewports Set Layout = Nothing ThisDrawing.Save Exit_Here: Exit Sub Err_Control: Select Case Err.Number Case "-2145320861" MsgBox "Unable to Save Drawing- " & Err.Description Case "-2145386493" MsgBox "Drawing is setup for Named Plot Styles." & (Chr(13)) & (Chr(13)) & "Run CONVERTPSTYLES command", vbCritical, "Change Plot Style" Case Else MsgBox "Unknown Error " & Err.Number End Select End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.