几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-12, 08:16 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】batch printing as pdfs from a list bo

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, "*
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】图基本操作的实现 huangyhg 数学基础库 0 2008-10-27 11:46 AM
【原创】我自己编写的一段程序大家看看 hanweisheng 标准件库 0 2006-05-08 09:27 PM


所有的时间均为北京时间。 现在的时间是 09:52 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多