Universal Document Converter
製品の概要
ダウンロード
ご購入
チュートリアル
開発者の方へ
サポートサービス
fCoder SIAについて


      サイト検索
   


      Video tutorial
Show tutorial



Main page>Developer Solutions>Examples>Visual Basic 6>AutoCAD Drawings to PDF

Converting AutoCAD Drawings to PDF


'----------------------------------------------------------------------
' 1) Autodesk AutoCAD 2000 or above should be installed and activated on your PC.
'
' 2) Universal Document Converter 5.2 or above should be installed, too.
'
' 3) Open your project in Microsoft Visual Basic 6.0.
'
' 4) In Visual Basic main menu press "Project->References".
'
' 5) In the list of references check "Universal Document Converter Type Library".
'----------------------------------------------------------------------
Private Sub PrintACADToPDF(strFilePath As String)
' Define constants
  Const acExtents = 1
  Const acScaleToFit = 0
  
  Dim nBACKGROUNDPLOT, nFILEDIA, nCMDDIA As Long
  Dim objUDC As IUDC
  Dim itfPrinter As IUDCPrinter
  Dim itfProfile As IProfile
  Dim objACADApp As Object
  Dim itfDrawing As Object
  Dim itfLayout As Object
  Dim itfActiveSpace As Object
  
  Set objUDC = New UDC.APIWrapper
  Set itfPrinter = objUDC.Printers("Universal Document Converter")
  Set itfProfile = itfPrinter.Profile
' Use Universal Document Converter API to change settings of converterd document
   
' Load profile located in folder "%APPDATA%\UDC Profiles".
' Value of %APPDATA% variable should be received using Windows API's SHGetSpecialFolderPath function.
' Or you can move default profiles into a folder you prefer.            
  itfProfile.Load("Drawing to PDF.xml")
  
  itfProfile.OutputLocation.Mode = LM_PREDEFINED
  itfProfile.OutputLocation.FolderPath = "C:\Out"
  
  itfProfile.PostProcessing.Mode = PP_OPEN_FOLDER
' Run AutoCAD as COM-server
  On Error Resume Next
  Set objACADApp = CreateObject("AutoCAD.Application")
' Open drawing from file
  Err = 0 ' Clear GetLastError() value
  Set itfDrawing = objACADApp.Documents.Open(strFilePath, False)
  If Err = 0 Then
  
  ' Change AutoCAD preferences for scaling the drawing to page
    If itfDrawing.ActiveSpace = 0 Then
      
      Set itfActiveSpace = itfDrawing.PaperSpace
      Set itfLayout = itfActiveSpace.Layout
    Else
      Set itfActiveSpace = itfDrawing.ModelSpace
      Set itfLayout = itfActiveSpace.Layout
    End If
    itfLayout.PlotType = acExtents
    itfLayout.UseStandardScale = True
    itfLayout.StandardScale = acScaleToFit
    itfLayout.CenterPlot = True
  
    nBACKGROUNDPLOT = itfDrawing.GetVariable("BACKGROUNDPLOT")
    nFILEDIA = itfDrawing.GetVariable("FILEDIA")
    nCMDDIA = itfDrawing.GetVariable("CMDDIA")
    Call itfDrawing.SetVariable("BACKGROUNDPLOT", 0)
    Call itfDrawing.SetVariable("FILEDIA", 0)
    Call itfDrawing.SetVariable("CMDDIA", 0)
    itfDrawing.Plot.QuietErrorMode = True
  ' Plot the drawing
    Call itfDrawing.Plot.PlotToDevice("Universal Document Converter")
    
  ' Restore AutoCAD default preferences
    Call itfDrawing.SetVariable("BACKGROUNDPLOT", nBACKGROUNDPLOT)
    Call itfDrawing.SetVariable("FILEDIA", nFILEDIA)
    Call itfDrawing.SetVariable("CMDDIA", nCMDDIA)
  ' Close drawing
    Call itfDrawing.Close(False)
    Set itfDrawing = Nothing
  End If
' Close Autodesk AutoCAD
  Call objACADApp.Quit
  Set objACADApp = Nothing
End Sub


© fCoder SIA fCoder SIAについて | サイトマップ