Satheesh K
Satheesh K

Reputation: 108

Print NanoCAD DWG files to PDF

I want to print DWG files from Excel VBA to PDF. There is a lot of help for AutoCAD, but little or none found for NanoCAD. I tried using equivalent functions, but results in error.

A little background on what I have explored.

  1. Print configuration DWG2PDF.pc3 created in NanoCAd and the following code :

     Dim NCAD As nanocad.Application
     Dim ndg As nanocad.Document
     Dim pth As String
     Dim result As String  
     pth = ThisWorkbook.Path
     Set NCAD = GetObject("", "nanoCAD.Application")
     NCAD.Visible = True
     Set ndg = NCAD.Documents.Open(pth & "\typicals\Title-OPA01.dwg")
     ndg.ActiveLayout.ConfigName = "DWG2PDF.pc3"
     result = ndg.Plot.PlotToFile(pth & "\Output\op.pdf")
    

I used the command specified for autoCAD professional version and not LT. Is there a workaround in AutoCAD LT which I can adapt to NanoCAD?

  1. Second trial through Acrobat's print function which windows calls for printing to PDF. Got help from Internet on calling the Shell command. I used some code as below.

    call Shell ("C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe /p/h" & pth & "\typicals\Title-OPA01.dwg")

Note: I referenced the type library of NanoCAD, Acrobat into the VBA project.

Upvotes: 0

Views: 2616

Answers (1)

tracciatura.net
tracciatura.net

Reputation: 56

Use this one work to me:

Public Sub test()
Dim NCAD
Dim ndg
Dim pth As String
Dim result As String

pth = "C:\Users\Cci\Desktop\TMP\"
Set NCAD = GetObject("", "nanoCAD.Application")
NCAD.Visible = True

Set ndg = NCAD.Documents.Open(pth & "BASE CAVALLETTO.dwg")

'setup plot
    ndg.ActiveLayout.RefreshPlotDeviceInfo
    ndg.ActiveLayout.ConfigName = "doPDF 10"
    ndg.ActiveLayout.PlotRotation = ac0degrees
    ndg.ActiveLayout.StyleSheet = "monochrome.ctb"
    ndg.ActiveLayout.PlotWithPlotStyles = True
    ndg.ActiveLayout.PlotViewportBorders = False
    ndg.ActiveLayout.PlotViewportsFirst = True
    ndg.ActiveLayout.CanonicalMediaName = "A3"
    ndg.ActiveLayout.PaperUnits = acMillimeters
    ndg.ActiveLayout.StandardScale = acScaleToFit
    ndg.ActiveLayout.ShowPlotStyles = False
    ndg.ActiveLayout.CenterPlot = True
    ndg.Plot.NumberOfCopies = 1

result = ndg.Plot.PlotToDevice

End Sub

doPDF 10 is a free program who simulate a printer and make a pdf file.

try to adapt this base code for you purpose bye

Upvotes: 1

Related Questions