几何尺寸与公差论坛

 找回密码
 注册
查看: 1461|回复: 0

【转帖】batch printing as pdfs from a list bo

[复制链接]
发表于 2009-4-12 20:16:41 | 显示全部楼层 |阅读模式
batch printing as pdf's from a list box
i have created a program that when you enter a part number, hit enter, it will search the pdmworks vault, if found it will store it in a list box. users can continue entering part numbers and again, if found, the numbers will continue to be added to the list box. now, i want to be able to batch print all those part numbers using adobe. anyone can help, i would greatly appercaite it.
thanks in advance
rodney michels
cad administrator
cswp;pdmworks wg cert
solidworks tech support cert
cert solidworks instructor
batchprocess will soon have pdm integration and can do this for you, until then have you looked at the pdm api at all or got anywhere with any coding yet?
are you ok just using the solidworks save as pdf? if so, use the document.save method from pdmworks to put a copy of the file somewhere you can open it from. then open it in solidworks and use modeldoc2.saveas4 (or modeldoc2.extension.saveas if you want to be current). simply change the extension of the file to pdf instead of slddrw. you will need to make sure you get copies of all references for the drawing so that it resolves completely when you open it.
my new book, automating solidworks 2009 using macros goes over both parts - getting the files out of pdmworks, then saving as pdf. it is available on schroff.com.
mike spens
"automating solidworks using macros"
leap frog leap pad x64
here is my code for a batch macro, here's how it works:
1. the user puts all of the files in a folder
2. the user runs macro and pastes the folder location into a dialog box
3. the macro creates multipage 'line art' pdf's and saves them off one at a time
other than templates referenced you should be able to hack/modify this macro, specifically when you are saving as pdf, to get the desired effect.
note: this macro also has a cleanup pass for extra folders created and also counts all files processed.
i'm a novice programmer so bear with me.
dim swapp as object
dim part as object
dim selmgr as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim feature as object
dim prepath as string
dim mypath as string
dim mythatx as string
dim myfile as string
dim myfilep as string
dim filenlong as string
dim filenold as string
dim myppathx as string
dim mypfile as string
dim exists as boolean
dim viewcorners as variant
dim finalcounter as single
dim swmodeldoc as sldworks.modeldoc2
dim swdrawing as sldworks.drawingdoc
dim swselmgr as sldworks.selectionmgr
dim swview as sldworks.view
dim swnote as sldworks.note
dim swannotation as sldworks.annotation
dim swselection() as object
dim scaleratio as variant
dim selectionindex as long
dim viewish as string
dim a as string
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
prepath = inputbox("accept this location or paste file location here:", "solidworks lineart", "c:\pdm_working\lineart")
if prepath = "" then goto 999
mypath = prepath & "\"
mypathx = mypath & "*.sldasm"
mypathp = mypath & "*.sldprt"
mypathd = mypath & "lineart intermediate files\"
mypathzz = mypath & "lineart saved as pdf\"
mypathnew = mypath & "lineart parts from assemblies\"
mypathnews = mypathnew & "*.sldprt"
finalcounter = 0
'processing assemblies, placing in temp folder '...\temp saved as parts\' and saving as parts (exterior faces only)
'on error resume next
if dir(mypathnew & "*.*") = "" then mkdir (mypathnew)
myfile = dir(mypathx)
let t = 0
while not myfile = ""
mytes = mypathzz & replace(myfile, ".sldasm", ".*", 1, 1, vbtextcompare)
if not dir(mytes) = "" then goto 5
mytesu = mypathnew & replace(myfile, ".sldasm", ".*", 1, 1, vbtextcompare)
if not dir(mytesu) = "" then goto 5
set part = swapp.opendoc6(mypath & myfile, 2, 0, "", longstatus, longwarnings)
filenlong = replace(part.gettitle, ".sldasm", ".sldprt", 1, 1, vbtextcompare)
filenold = part.gettitle
set swmodel = swapp.activedoc
bret = swmodel.forcerebuild3(false)
part.shownamedview2 "*isometric", 7
part.viewzoomtofit2
swapp.setuserpreferenceintegervalue swsaveassemblyaspartoptions, _
swsaveasmaspart_exteriorfaces
'swapp.setuserpreferenceintegervalue swsaveassemblyaspartoptions, _
'swsaveasmaspart_allcomponents
part.saveas2 mypathnew & filenlong, 0, false, false
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
swapp.closedoc filenold
set swmodel = swapp.activedoc
5 'see if statement above
myfile = dir(mypathx)
for q = 0 to t
myfile = dir
next q
let t = t + 1
wend
'***********************************************************************
'***********************************************************************
'***********************************************************************
'***********************************************************************
'***********************************************************************
'***********************************************************************
'***********************************************************************
'processing part files, saving as assemblies, placing in temp folder '...\temp assembly files\'
'then saving pdf's '...\lineart saved as pdf\'
let t = 0
if dir(mypathd & "*.*") = "" then mkdir (mypathd)
if dir(mypathzz & "*.*") = "" then mkdir (mypathzz)
dim tagg as single
tagg = 0
'loading first part name
do
myfilep = dir(mypathp)
if tagg = 1 then myfilep = dir(mypathnews)
if tagg = 1 then mypath = mypathnew
dim viewtyp as string
'change first 4 view types here
viewtyp = "dimetric"
'exit this stage when there are no more parts to process
while not myfilep = ""
mytes = mypathzz & replace(myfilep, ".sldprt", ".*", 1, 1, vbtextcompare)
if not dir(mytes) = "" then goto 50
'open first part file
set part = swapp.opendoc6(mypath & myfilep, 1, 0, "", longstatus, longwarnings)
set part = swapp.newdocument("\\venus\production_dwg\format\lineart.asmdot", 0, 0#, 0#)
part.addcomponent myfilep, 0, 0, 0
set swmodel = swapp.activedoc
bret = swmodel.forcerebuild3(false)
myfilea = replace(myfilep, ".sldprt", ".sldasm", 1, 1, vbtextcompare)
'save part file as assembly file
part.saveas2 mypathd & myfilea, 0, false, false
set part = swapp.activatedoc2(myfilea, false, longstatus)
'create new drawing file of assembly
set part = swapp.newdocument("\\venus\production_dwg\format\blank_a.slddrt", 12, 0.2159, 0.2794)
set drawview = part.createdrawviewfrommodelview2(mypathd & myfilea, "*" & viewtyp, 0.14, 0.107, 0)
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
boolstatus = part.setuserpreferencetoggle(6, false)
dim voutline as variant
'scale first drawing view
voutline = swview.getoutline
dim factorofsize as double
if voutline(2) - voutline(0) > voutline(3) - voutline(1) then factorofsize = 200 / ((voutline(2) - voutline(0)) * 1000) else factorofsize = 140 / ((voutline(3) - voutline(1)) * 1000)
vscaleratio = swview.scaleratio
swview.scaledecimal = swview.scaledecimal * factorofsize
bret = swmodel.editrebuild3
part.viewzoomtofit2
part.clearselection2 true
'add next 3 drawing views for each specified ex:"diametric3"
for m = 2 to 4
part.newsheet3 "sheet" & m, 12, 12, 1, 12, false, "blank_a.slddrt", 0.2794, 0.2159, "default"
set drawview = part.createdrawviewfrommodelview2(myfilea, viewtyp & m, 0.14, 0.107, 0)
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
voutline = swview.getoutline
if voutline(2) - voutline(0) > voutline(3) - voutline(1) then factorofsize = 200 / ((voutline(2) - voutline(0)) * 1000) else factorofsize = 140 / ((voutline(3) - voutline(1)) * 1000)
vscaleratio = swview.scaleratio
swview.scaledecimal = swview.scaledecimal * factorofsize
bret = swmodel.editrebuild3
part.viewzoomtofit2
part.clearselection2 true
next m
'add 4 basic views (front)...
part.newsheet3 "sheet5", 12, 12, 1, 12, false, "blank_a.slddrt", 0.2794, 0.2159, "default"
set drawview = part.createdrawviewfrommodelview2(myfilea, "*front", 0.14, 0.107, 0)
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
voutline = swview.getoutline
if voutline(2) - voutline(0) > voutline(3) - voutline(1) then factorofsize = 200 / ((voutline(2) - voutline(0)) * 1000) else factorofsize = 140 / ((voutline(3) - voutline(1)) * 1000)
vscaleratio = swview.scaleratio
swview.scaledecimal = swview.scaledecimal * factorofsize
bret = swmodel.editrebuild3
part.viewzoomtofit2
part.clearselection2 true
'(left) next sheet, next view
part.newsheet3 "sheet6", 12, 12, 1, 12, false, "blank_a.slddrt", 0.2794, 0.2159, "default"
set drawview = part.createdrawviewfrommodelview2(myfilea, "*left", 0.14, 0.107, 0)
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
voutline = swview.getoutline
if voutline(2) - voutline(0) > voutline(3) - voutline(1) then factorofsize = 200 / ((voutline(2) - voutline(0)) * 1000) else factorofsize = 140 / ((voutline(3) - voutline(1)) * 1000)
vscaleratio = swview.scaleratio
swview.scaledecimal = swview.scaledecimal * factorofsize
bret = swmodel.editrebuild3
part.viewzoomtofit2
part.clearselection2 true
'(back) next sheet, next view
part.newsheet3 "sheet7", 12, 12, 1, 12, false, "blank_a.slddrt", 0.2794, 0.2159, "default"
set drawview = part.createdrawviewfrommodelview2(myfilea, "*back", 0.14, 0.107, 0)
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
voutline = swview.getoutline
if voutline(2) - voutline(0) > voutline(3) - voutline(1) then factorofsize = 200 / ((voutline(2) - voutline(0)) * 1000) else factorofsize = 140 / ((voutline(3) - voutline(1)) * 1000)
vscaleratio = swview.scaleratio
swview.scaledecimal = swview.scaledecimal * factorofsize
bret = swmodel.editrebuild3
part.viewzoomtofit2
part.clearselection2 true
'(right) next sheet, next view
part.newsheet3 "sheet8", 12, 12, 1, 12, false, "blank_a.slddrt", 0.2794, 0.2159, "default"
set drawview = part.createdrawviewfrommodelview2(myfilea, "*right", 0.14, 0.107, 0)
set swmodel = swapp.activedoc
set swdraw = swmodel
set swselmgr = swmodel.selectionmanager
set swview = swselmgr.getselectedobject5(1)
voutline = swview.getoutline
if voutline(2) - voutline(0) > voutline(3) - voutline(1) then factorofsize = 200 / ((voutline(2) - voutline(0)) * 1000) else factorofsize = 140 / ((voutline(3) - voutline(1)) * 1000)
vscaleratio = swview.scaleratio
swview.scaledecimal = swview.scaledecimal * factorofsize
bret = swmodel.editrebuild3
part.viewzoomtofit2
part.clearselection2 true
'(top) next sheet, next view
part.newsheet3 "sheet9", 12, 12, 1, 12, false, "blank_a.slddrt", 0.2794, 0.2159, "default"
set drawview = part.createdrawviewfrommodelview2(myfilea, "*
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 01:14 , Processed in 0.039498 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表