public sub pubblicadxfdwgpdf()
' obtain reference to drawing
dim odoc as document
set odoc = thisapplication.activedocument
' destination folder
' ---------------------------------------------------
dim sexportpath as string
sexportpath = "c:\users\utente\desktop\dwg-dxf-pdf\"
' ---------------------------------------------------
if odoc.documenttype <> kdrawingdocumentobject then
msgbox ("deve essere aperta una tavola")
exit sub
end if
' get the filename with no path
dim sfilename as string
sfilename = sexportpath & isolanome(odoc.fullfilename, true)
' get the dwg translator add-in.
dim dwgaddin as translatoraddin
set dwgaddin = thisapplication.applicationaddins.itembyid("{c24e3ac2-122e-11d5-8e91-0010b541cd80}")
' get the dxf translator add-in.
dim dxfaddin as translatoraddin
set dxfaddin = thisapplication.applicationaddins.itembyid("{c24e3ac4-122e-11d5-8e91-0010b541cd80}")
' get the pdf translator add-in.
dim pdfaddin as translatoraddin
set pdfaddin = thisapplication.applicationaddins.itembyid("{0ac6fd96-2f4d-42ce-8be0-8aea580399e4}")
dim strinifile as string
' common init
' create a context object
dim ocontext as translationcontext
set ocontext = thisapplication.transientobjects.createtranslationcontext
ocontext.type = kfilebrowseiomechanism
' create a namevaluemap object
dim ooptions as namevaluemap
set ooptions = thisapplication.transientobjects.createnamevaluemap
' create a datamedium object
dim odatamedium as datamedium
set odatamedium = thisapplication.transientobjects.createdatamedium
' ---------------------------------------------------------------------------
' dwg
' -------------------------------
' check whether the translator has 'savecopyas' options
if dwgaddin.hassavecopyasoptions(odoc, ocontext, ooptions) then
' file with exportation options
strinifile = "c:\tempdwgout.ini"
' create the name-value that specifies the ini file to use.
ooptions.value("export_acad_inifile") = strinifile
end if
'set the destination file name
odatamedium.filename = sfilename & ".dwg"
'publish document.
call dwgaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
' -------------------------------
' fine dwg
' ---------------------------------------------------------------------------
' ---------------------------------------------------------------------------
' dxf
' -------------------------------
' check whether the translator has 'savecopyas' options
if dxfaddin.hassavecopyasoptions(odoc, ocontext, ooptions) then
' file with exportation options
strinifile = "c:\tempdxfout.ini"
' create the name-value that specifies the ini file to use.
ooptions.value("export_acad_inifile") = strinifile
end if
'set the destination file name
odatamedium.filename = sfilename & ".dxf"
'publish document.
call dxfaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
' -------------------------------
' fine dxf
' ---------------------------------------------------------------------------
' ---------------------------------------------------------------------------
' pdf
' -------------------------------
' check whether the translator has 'savecopyas' options
if pdfaddin.hassavecopyasoptions(odoc, ocontext, ooptions) then
' options for drawings...
ooptions.value("all_color_as_black") = 0
'ooptions.value("remove_line_weights") = 0
'ooptions.value("vector_resolution") = 400
'ooptions.value("sheet_range") = kprintallsheets
'ooptions.value("custom_begin_sheet") = 2
'ooptions.value("custom_end_sheet") = 4
end if
'set the destination file name
odatamedium.filename = sfilename & ".pdf"
'publish document.
call pdfaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
' -------------------------------
' fine pdf
' ---------------------------------------------------------------------------
end sub