Results 1 to 1 of 1

Thread: Print a dwg file in pdf using vba

  1. #1
    Member
    Join Date
    2018-03
    Posts
    4
    Login to Give a bone
    0

    Red face Print a dwg file in pdf using vba

    Hello,

    I am trying to print a dwg file in pdf using vba. Everything seems to work fine.
    The pdf file is even created. However, whenever i try to open it with adobe reader, it is said that adobe can't open the pdf file.
    I don't know what to do. Is there any mistake in my code ?
    I am a beginner in vba programming.

    Below is my vba code:


    Code:
    Sub Access_Autocad() 'nom de ma procédure
    Dim AutoCAD As Object 'Autocad est la variable ici
    Set AutoCAD = CreateObject("Autocad.Application") 'ouvre AutoCad
    AutoCAD.Visible = True
    
    Dim Path_File As String 'Chemin du fichier autocad
    Path_File = "P:\Plannif_VBA_AutoCAD\PLA_TEN_C18_406_RONDES.dwg"
    
    Set AutoCAD = AutoCAD.Documents.Open(Path_File) 'ouvre fichier ronde
    
    'Changement de la couleur des calques des rondes
    Dim layer_ronde As AcadLayer
    Set layer_ronde = AutoCAD.Layers.Add("99103") 'attribuer à la ronde le nom du calque correspondant
    layer_ronde.Color = acRed 'changer la couleur du calque
    Dim layer_ronde1 As AcadLayer
    Set layer_ronde1 = AutoCAD.Layers.Add("99103")
    layer_ronde1.Color = 12
    Dim layer_ronde2 As AcadLayer
    Set layer_ronde2 = AutoCAD.Layers.Add("99105")
    layer_ronde2.Color = 16
    Dim layer_ronde3 As AcadLayer
    Set layer_ronde3 = AutoCAD.Layers.Add("99106")
    layer_ronde3.Color = 5
    
    
    Dim DocToPrint As AcadPlot 'Objet à plotter (technically we plot before printing)
    
    Dim DocConfigs As AcadPlotConfigurations
    
    Dim PlotConfig As AcadPlotConfiguration
    
    Dim pdfFile As String
    pdfFile = Replace(Path_File, "dwg", "pdf")
    
    Set DocToPrint = AutoCAD.Plot
    
    Set DocConfigs = AutoCAD.PlotConfigurations
    
    Set PlotConfig = DocConfigs.Add("A2", True) 'Add a new plot configuration
    Set PlotConfig = DocConfigs.Item("A2")
    
    'LAYOUT LAYOUT LAYOUT LAYOUT
    Dim Layouts As AcadLayouts
    Dim Layout As AcadLayout
    Set Layouts = AutoCAD.Layouts
    Layouts("A2").ConfigName = "DWG To PDF.pc3" 'pour choisir le layout/présentation ou on veut imprimer A2,A3,A0 et le dwg to pc3
    
    
    AutoCAD.ActiveSpace = acPaperSpace
    
    AutoCAD.Layouts("A2").StyleSheet = "Acad.ctb"
    AutoCAD.Layouts("A2").UseStandardScale = False
    AutoCAD.Layouts("A2").StandardScale = acScaleToFit 'échelle du tracé à la taille du papier
    AutoCAD.Layouts("A2").PaperUnits = acPouces 'unités du papier
    AutoCAD.Layouts("A2").PlotRotation = ac0degrees
    AutoCAD.Layouts("A2").PlotType = acExtents
    AutoCAD.Layouts("A2").CenterPlot = True 'Centrer le tracé
    'AutoCAD.Layouts("A2").CanonicalMediaNames = "ANSI_full_bleed_A_(8.50_x_11.00_pouces) 'Format papier d'impression"
    AutoCAD.Layouts("A2").RefreshPlotDeviceInfo
    
    
    Dim Printing
    Printing = DocToPrint.PlotToFile(pdfFile, PlotConfig.ConfigName)
    'Set Printing = DocToPrint.Documents.Open(Printing)
    
    'DocToPrint = AutoCAD.Document.Plot.DisplayPlotPreview.PlotToDevice(Printer)
    
    End Sub
    Last edited by Ed Jobe; 2018-03-16 at 08:04 PM.

Similar Threads

  1. Print Spooler File Location or Printer Description File Search Path?
    By archer1684 in forum CAD Management - General
    Replies: 4
    Last Post: 2011-04-14, 07:13 PM
  2. DWF file will not print to PDF
    By Silleke in forum Revit - Plotting/Printing/Exporting
    Replies: 1
    Last Post: 2009-09-14, 07:33 AM
  3. exporting to CAD, looking for CTB file to print.
    By MedJohn in forum Revit Architecture - General
    Replies: 11
    Last Post: 2006-12-14, 03:45 PM
  4. How to print a .PLT file?
    By Kroke in forum AutoCAD Plotting
    Replies: 10
    Last Post: 2005-11-09, 11:12 PM
  5. Print from host file or from linked file?
    By overcaffeined1745 in forum Revit Architecture - General
    Replies: 2
    Last Post: 2003-07-04, 02:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •