• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

export "automatic" idw to pdf-dxf

  • Thread starter Thread starter lollo76
  • Start date Start date
I think it works.
Code:
    ' obtain reference to drawing
    dim odoc as document
    set odoc = thisapplication.activedocument
    
    if odoc.documenttype <> kdrawingdocumentobject then
        msgbox ("deve essere aperta una tavola")
        exit sub
    end if
    
    ' save the file with dependants
    odoc.save2
    
    dim fn as string
    dim dwgfn as string
    dim pdffn as string
    
    ' generate the file names
    fn = odoc.fullfilename
    dwgfn = strings.left(fn, len(fn) - 4) & ".dwg"
    pdffn = strings.left(fn, len(fn) - 4) & ".pdf"
    
    
    ' 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 = dwgfn


    'publish document.
    call dwgaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
    
    ' -------------------------------
    ' fine dwg
    ' ---------------------------------------------------------------------------
  
    
    ' ---------------------------------------------------------------------------
    ' 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 = pdffn


    'publish document.
    call pdfaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
    ' -------------------------------
    ' fine pdf
    ' ---------------------------------------------------------------------------
end sub
Thank you so much! I'll try it tomorrow and tell you! Very kind.
 
I can't make it work. I couldn't understand why. on module 1 I have already uploaded the previous macro, I tried to paste the text placed under the macro and it does not work, in the sense that no other words appear in the window of programmable buttons from macro. I tried to remove the existing macro and do the same procedure, but with the same unhappy result...where wrong?

then I looked at the alternative solution and it is actually very simple to implement, but here too maybe I mistake something, in fact it creates the pdf and dwg only to the first save in the successive saves does not overwrite the files created previously.

I'm sorry for the humour...:confused:
 
I can't make it work. I couldn't understand why. on module 1 I have already uploaded the previous macro, I tried to paste the text placed under the macro and it does not work, in the sense that no other words appear in the window of programmable buttons from macro. I tried to remove the existing macro and do the same procedure, but with the same unhappy result...where wrong?
...
Not wrong, I'm yawned, and I lost the beginning of the macro in the copy/paste:redface:
- - - updated - - - -... and sends an answer before I have finished the answer:redface::redface:
Code:
public sub save_idwgwgpdf
    
    ' obtain reference to drawing
    dim odoc as document
    set odoc = thisapplication.activedocument
    
    if odoc.documenttype <> kdrawingdocumentobject then
        msgbox ("deve essere aperta una tavola")
        exit sub
    end if
    
    ' save the file with dependants
    odoc.save2
    
    dim fn as string
    dim dwgfn as string
    dim pdffn as string
    
    ' generate the file names
    fn = odoc.fullfilename
    dwgfn = strings.left(fn, len(fn) - 4) & ".dwg"
    pdffn = strings.left(fn, len(fn) - 4) & ".pdf"
    
    
    ' 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 = dwgfn


    'publish document.
    call dwgaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
    
    ' -------------------------------
    ' fine dwg
    ' ---------------------------------------------------------------------------
  
    
    ' ---------------------------------------------------------------------------
    ' 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 = pdffn


    'publish document.
    call pdfaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
    ' -------------------------------
    ' fine pdf
    ' ---------------------------------------------------------------------------
end sub
... very strange, the first row of the macro does not copy/paste... I had to write it by hand. Boh!
I do not know why.

overwrite the old macro
 
Hello, everyone, I've had a question for a while.
the buttons connected to the macros, all appear to me with the same iconCattura.webpIs there any way to change them?
Thank you.
 
Sorry, but in the end someone managed to pdf export an entire existing idw folder? ?
try this: you get an input line, enter the folder path where you want to do the job, open and export all the idw that contains: as I threw down things quickly made of evidence on copied folders before, that you never know :biggrin:! the numerous (= 1) evidence that I did worked. do not add the backslash at the end of the path at the time of the input otherwise it does not go.

the macro to launch is diridw

Let me know.

Code:
public sub diridw()

    dim mydir as string
    dim myname as string
    
    ' richiede il percorso della cartella
    mydir = inputbox("inserisci il percorso dei disegni (termina senza \)", "richiesta percorso files")
    

    ' visualizza i nomi in c:\ che rappresentano directory.
    myname = dir(mydir & "\*.idw", vbnormal)   ' recupera la prima voce.
    debug.print "inizio ciclo"
    dim i as integer
    do while myname <> ""    ' avvia il ciclo.
        debug.print i, mydir & "\" & myname
        exportdirtodwg_pdf (mydir & "\" & myname)
        myname = dir    ' legge la voce successiva.
        i = i + 1
    loop

end sub


public sub exportdirtodwg_pdf(drawing as string)
    
    ' obtain reference to drawing
    dim odoc as document
    set odoc = thisapplication.documents.open(drawing)
    
    
    dim fn as string
    dim dwgfn as string
    dim pdffn as string
    
    ' generate the file names
    fn = odoc.fullfilename
    dwgfn = strings.left(fn, len(fn) - 4) & ".dwg"
    pdffn = strings.left(fn, len(fn) - 4) & ".pdf"
    
    
    ' 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 = dwgfn


    'publish document.
    call dwgaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
    
    ' -------------------------------
    ' fine dwg
    ' ---------------------------------------------------------------------------
  
    
    ' ---------------------------------------------------------------------------
    ' 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 = pdffn


    'publish document.
    call pdfaddin.savecopyas(odoc, ocontext, ooptions, odatamedium)
    ' -------------------------------
    ' fine pdf
    ' ---------------------------------------------------------------------------
    
    odoc.close (true)
end sub
 
tried and worked.
But if I try to save the default.ivb (in which I glued the diridw ) it tells me :
msg.webpWhat can that be?

Thank you very much.
 
tried and worked.
But if I try to save the default.ivb (in which I glued the diridw ) it tells me :
View attachment 39358What can that be?

Thank you very much.
I have no idea... random shot:
are you in multiple people in the office and share the default.ivb file? only the first to have opened an inventor session can save it
Did you use the inventor vba editor to do the thing?
are there passwords/administrator/eccs on the disk where you work?
It gives you the same mistake even if you try to write something and save, like
"public sub pippo()
end sub

and above all, did you restart the computer and try again?
 
Unfortunately it does not go...:confused:
at the first start of the macro converts all .idw in .dwg and all .idw in .pdf Except 2to the second attempt .dwg always ok and .pdf all except 4to the third attempt .dwg always ok and .pdf all Except 6and so on..
it seems that there is some counter that at every launch of the macro tolga 2 files to be converted
note that .idw opens automaously all during the macro, but some are not converted to .pdf
Boh? ? ?
Unfortunately I don't understand a bunch of vb.. I see if some colleagues.. .
 
Unfortunately it does not go...:confused:
at the first start of the macro converts all .idw in .dwg and all .idw in .pdf Except 2to the second attempt .dwg always ok and .pdf all except 4to the third attempt .dwg always ok and .pdf all Except 6and so on..
it seems that there is some counter that at every launch of the macro tolga 2 files to be converted
note that .idw opens automaously all during the macro, but some are not converted to .pdf
Boh? ? ?
Unfortunately I don't understand a bunch of vb.. I see if some colleagues.. .
- Have you tried to open the drawings that give problems and use the "manual" version of the macro to see what happens? I can't think of anything. .
- Did someone else try and have such problems?

- You restarted everything? It's a tried-and-tested sack, it's always worth trying:biggrin:
 
I still have to try to restart the pc, inventor obviously restarted it several times
the strange fact is that at the first round it is okay and converts all .idw, then every time you try again you lose the first 2 files of the list
example: 21 files ok on the first round, then 19, 17, 15, 13...... .
if I try again on another folder, then again the same error
It is true that it would be enough for me to work well the first time x to convert all drawings into block, then any changes/addition should handle them individually.
I'll try again, thank you anyway
 
I tried to restart the pc... miracle!!!! (x now.... :rolleyes: )
I also divided the macro: a x i pdf and a x i dwg

Thank you very much!
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top