|
how to save to dxf in active drawing file location?
can someone post the code to save a file in dxf format to the location where the active drawing is stored? if you could also comment the code it would be great.
i've gone thru 11 pages of the api forum and haven't found it yet and my advanced search doesn't seem to work correctly, it returns results from all forums not the just the ones i select.
much appreciated
-jody
*edit: i figured out how to jump to the last page using this...
dim swapp as object
dim shtcnt as integer
sub main()
set swapp = application.sldworks
set model = swapp.activedoc
set selmgr = model.selectionmanager
shtcnt = model.getsheetcount
for i = 0 to shtcnt
model.sheetnext
next i
end sub
mechanical engineer
temptronic corp
.temptronic.com
edited: 09/08/2008 at 09:27 am by jody stiles
not a real macro, but it might help you get yours going.
lastsheet = drawingdoc.getsheetcount -1
get the last sheet number
sheetname = drawing doc.getsheetnames
get the names of the sheets
drawingdoc.activatesheet(sheetnames(lastsheet))
activate the last sheet
modeldocextension.saveas(sheetname(lastsheet) & ".dxf", swsaveascurrentversion, swsaveasoptions_silent, nothing, nerrors, nwarnings)
save last sheet as name of last sheet.
you still would need to put a file path in the name though(i think)
drc inc.
minneapolis, mn
.designreadycontrols.com
sw2007 sp5.0
core2 quad
3gb ram
xp pro sp2
ati firegl v3600
answer well i got it to work! it may not be the most elegant but it works exactly as i want it to.
-jody
*************************************************************
dim swapp as object
dim part as object
dim longstatus as long, longwarnings as long
dim shtcnt as integer
dim drwpth as string
dim drwedrw as string
dim drwpdf as string
dim drwdxf as string
dim i as long
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
' the following gets the location of the active drawing
drwpth = part.getpathname
' the following removes the solidworks file extension (sldxxx) from the file name
drwpth = left(drwpth, len(drwpth) - 6)
' the following adds the pdf extension to the file and then saves it in the same folder as the active drawing
drwpdf = drwpth + "pdf"
part.extension.saveas drwpdf, 0, 0, nothing, longstatus, longwarnings
' the following adds the edrw extension to the file and then saves it in the same folder as the active drawing
drwedrw = drwpth + "edrw"
part.extension.saveas drwedrw, 0, 0, nothing, longstatus, longwarnings
' the following gets the numbers of sheets in the active drawing and then jumps to the last sheet by iteration
' the dxf view must be kept on the last page of the active drawing (per company policy)
shtcnt = part.getsheetcount
for i = 0 to shtcnt
part.sheetnext
next i
' the following adds the dxf extension to the file and then saves it in the same folder as the active drawing
drwdxf = drwpth + "dxf"
part.extension.saveas drwdxf, 0, 0, nothing, longstatus, longwarnings
'the following jumps back to the first sheet of the drawing (just for esthetics)
for i = 0 to shtcnt
part.sheetprevious
next i
end sub
mechanical engineer
temptronic corp
.temptronic.com
hi,
how i loop this code. i mean that if i have two or more drawing open and i want to run this code in that way: first drw is active, then save and close, then other drawing is active, save and cose etc., etc.... after that all open drw's are saving and closed.
thanks
batchprocess will do all this for you. for the macro, just have to enumerate the open documents using sldworks::enumdocuments2 which gives you modeldoc2 objects for all documents loaded (check visible state as to whether they are opened or just loaded in background). |
|