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

pulsante per esportare tavola in dxf

  • Thread starter Thread starter Filo
  • Start date Start date

Filo

Guest
my need was to have a button to click to generate a dxf file from an idw file. I also did not want the dxf to be saved in the same folder as the idw file but in another same folder for all dxf files.
all you could do with ilogic and it would be easier, however, to date, I have not yet managed to create an external button to the ilogic browser.

doing some copy paste from the network and adding some of my I managed to do everything. I tested the code on inventor 2013
Code:
public sub pubblicadxf()
    
    ' 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
    
    
    dim odrw as drawingdocument
    set odrw = odoc
    ' get the dxf translator add-in.
    dim dxfaddin as translatoraddin
    set dxfaddin = thisapplication.applicationaddins.itembyid("{c24e3ac4-122e-11d5-8e91-0010b541cd80}")


    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

    ' check whether the translator has 'savecopyas' options
    if dxfaddin.hassavecopyasoptions(odrw, ocontext, ooptions) then

        dim strinifile as string
        strinifile = "tuofile.ini"
        ' create the name-value that specifies the ini file to use.
        ooptions.value("export_acad_inifile") = strinifile
    end if

   ' sets directory for file save
     dim dxfdirectory as string
     dxfdirectory = "percorso cartella di destinazione"

    'set the destination file name
    dim fn as string
    dim fna as string
    fna = odrw.displayname
    fna = strings.left(fna, len(fna) - 4) & ".dxf"
    fn = dxfdirectory & fna
    odatamedium.filename = fn
    
    'publish document.
    call dxfaddin.savecopyas(odrw, ocontext, ooptions, odatamedium)
end sub
to see how to copy the vb code, how to add and customize a read button this debateif your need is to save the dxf file automatically or save it in the same folder as the idw file or ask you every time in which folder you have to work on the last lines of code and on the network you can find everything

Hi.
thread
 
the script written above has a kiss to the code lines
Code:
    'set the destination file name
    dim fn as string
    dim fna as string
    fna = odrw.displayname
    fna = strings.left(fna, len(fna) - 4) & ".dxf"
    fn = dxfdirectory & fna
    odatamedium.filename = fn
because if in the file name there are special characters like "_" "-" "#" etc.. the command "strings" takes this character as reference and not the point to "extract" the file name

all the new correct code, hoping that there are no other errors, you will rub it below
Code:
public sub pubblicadxf()
    
    ' 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
    
    
    dim odrw as drawingdocument
    set odrw = odoc
    ' get the dxf translator add-in.
    dim dxfaddin as translatoraddin
    set dxfaddin = thisapplication.applicationaddins.itembyid("{c24e3ac4-122e-11d5-8e91-0010b541cd80}")


    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

    ' check whether the translator has 'savecopyas' options
    if dxfaddin.hassavecopyasoptions(odrw, ocontext, ooptions) then

        dim strinifile as string
        strinifile = "c:\users\fmantovani\documents\dxf.ini"
        ' create the name-value that specifies the ini file to use.
        ooptions.value("export_acad_inifile") = strinifile
    end if

   ' sets directory for file save
     dim dxfdirectory as string
     dxfdirectory = "c:\users\fmantovani\desktop\"

    'set the destination file name
    dim fn as string
    dim fna as string
    dim fnb as string
    
    fna = odrw.displayname
    fnb = left(fna, instr(fna, ".") - 1)
    fnb = fnb & ".dxf"
    fn = dxfdirectory & fnb
    odatamedium.filename = fn
    
    'publish document.
    call dxfaddin.savecopyas(odrw, ocontext, ooptions, odatamedium)
end sub
the same problem also occurs with the script to publish the pdf mailed by catafract qui

ciao filippo
 
the script written above has a kiss to the code lines
Code:
    'set the destination file name
    dim fn as string
    dim fna as string
    fna = odrw.displayname
    fna = strings.left(fna, len(fna) - 4) & ".dxf"
    fn = dxfdirectory & fna
    odatamedium.filename = fn
because if in the file name there are special characters like "_" "-" "#" etc.. the command "strings" takes this character as reference and not the point to "extract" the file name

all the new correct code, hoping that there are no other errors, you will rub it below

the same problem also occurs with the script to publish the pdf mailed by catafract qui

ciao filippo
:confused: it doesn't happen to me (just tried), use 2013 or are you at 2014 (I still have to start using it...)? Perhaps a difference in the vba version, my 6.3 (for example left to me does not work, only string.left)?
aside from this, your variation truncates to the first "." which finds starting from left to right: if the file name as a special character includes the ".", as in my own to understand us :tongue: the outgoing name will be truncated.
I'm curious to understand the malfunction!
Bye!
 
rightly if in the name there is a "." besides that of the extension does not work. . .

I still have 2013 and vb version is also my 6.3. for the names of the files type "ab___cde.idw" outgoing gave me "ab_.idw", or took the second "_" as reference.

Hi.
 
rightly if in the name there is a "." besides that of the extension does not work. . .

I still have 2013 and vb version is also my 6.3. for the names of the files type "ab___cde.idw" outgoing gave me "ab_.idw", or took the second "_" as reference.

Hi.
I repeat, it works well as I posted... boh! by curiosity, is there a "third part" that makes a test for us?
Thank you!
Hello, everyone!
 
I've been dealing with everything today.
Now it works properly to me too, I can't understand why, maybe I had made some other mess without realizing it.

Hi.
 
I've been dealing with everything today.
Now it works properly to me too, I can't understand why, maybe I had made some other mess without realizing it.

Hi.
in doubt, reboot... windows is always windows:biggrin:
 
your phrase
Windows è sempre windows
He put the flea in my ear, in fact some evidence I did with seven and others with a view...

I still have to go deeper, but for now I realized that "odrw.displayname" in seven returns "file.idw" while in view "filename". . .

What makes me turn and not little boxes!

if I have news I keep you updated

Hi.
 
what has been done is very interesting, since I had repeatedly felt the need during work. Unfortunately I do not know so much about vba so I will remain with the desire for automatic dxf export. but I would like to suggest, if you thought it interesting (I use it very thick at work), to integrate automatic export not only to the idw file, but also somehow to the plant view of the flat model of the sheet development in a series of ipt files.
congratulations again on the work done.

m.
 
Your sentence

He put the flea in my ear, in fact some evidence I did with seven and others with a view...

I still have to go deeper, but for now I realized that "odrw.displayname" in seven returns "file.idw" while in view "filename". . .

What makes me turn and not little boxes!

if I have news I keep you updated

Hi.
check that the winzozz option "hide extension for known file types" is disabled, if I don't remember badly creates these problems.. .
However eye that the .displayname is what appears in the browser: if you want to be sure to recover the file name use odrw.fullfilename and then separate path and filename.
Bye!
 
what has been done is very interesting, since I had repeatedly felt the need during work. Unfortunately I do not know so much about vba so I will remain with the desire for automatic dxf export. but I would like to suggest, if you thought it interesting (I use it very thick at work), to integrate automatic export not only to the idw file, but also somehow to the plant view of the flat model of the sheet development in a series of ipt files.
congratulations again on the work done.

m.
Unfortunately they are always things related to the business cycle, to do almost "tailored": For example what you ask for me would be absolutely useless, however I always put on the table the quoted flat model (you can't do it?) also because I have to control the verse (use a lot of foil) and therefore the export is "composed in the price"... creating these macros is a little like being tailors, I have done many but if things are not organized exactly as I want just don't go.
when I have a little more time place the most universal ones. . .
Hello, everyone!
 
check that the winzozz option "hide extension for known file types" is disabled, if I don't remember badly creates these problems.. .
I checked and the problem is right here, it's not about seven or seen.. .
However eye that the .displayname is what appears in the browser: if you want to be sure to recover the file name use odrw.fullfilename and then separate path and filename.
Bye!
in fact even before I wrote I had already changed the code with fullfilename. . .

here is the definitive code
public sub pubblicadxf()

' 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


dim odrw as drawingdocument
set odrw = odoc
' get the dxf translator add-in.
dim dxfaddin as translatoraddin
set dxfaddin = thisapplication.applicationaddins.itembyid("{c24e3ac4-122e-11d5-8e91-0010b541cd80}")


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

' check whether the translator has 'savecopyas' options
if dxfaddin.hassavecopyasoptions(odrw, ocontext, ooptions) then

dim strinifile as string
strinifile = "percorso tuo_file.ini"
' create the name-value that specifies the ini file to use.
ooptions.value("export_acad_inifile") = strinifile
end if

' sets directory for file save
dim dxfdirectory as string
'la riga sottostante salva il file sul desktop se vuoi cambiare cartella cancella la riga sottostante e incolla dxfdirectory = "percorso cartella"
dxfdirectory = environ("allusersprofile") & "\desktop\"

'set the destination file name
dim fn as string
dim fna as string
dim fnb as string

fna = odrw.fullfilename
fna = strings.right(fna, len(fna) - instrrev(fna, "\"))
fnb = strings.left(fna, len(fna) - 4) & ".dxf"
fn = dxfdirectory & fnb
odatamedium.filename = fn

'publish document.
call dxfaddin.savecopyas(odrw, ocontext, ooptions, odatamedium)
end sub
for now I have not found any bachi but if you want to test it you do me a favor.. .
 
I don't know how much I'm going to do, so I'll stay with the desire for automatic dxf export.
If I can do it... dxf in the same folder as the file or in a folder you choose? However I recommend you spend an hour and try to do it with ilogic, it is not very difficult to do and learn something that will be useful to you again

but I would like to suggest, if you thought it interesting (I use it very thick at work), to integrate automatic export not only to the idw file, but also somehow to the plant view of the flat model of the sheet development in a series of ipt files...
as it has told you catafract these scripts work as much better as they are sewn on their own needs and one thing of this kind also for me would be useless because every ipt has its idw with its flat model

Hi.
thread
 

Forum statistics

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

Members online

No members online now.
Back
Top