几何尺寸与公差论坛------致力于产品几何量公差标准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, 06:38 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how to save to dxf in active drawing file location

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


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】how to save a proe file from solidworks yang686526 SolidWorks二次开发 0 2009-04-12 06:38 PM
如何得到MessageBox窗口里的提示文本? huangyhg vc编程 1 2008-07-24 01:07 AM
【转帖】续实例解析socket编程模型之异步通信篇 yogy C# 1 2007-08-01 03:01 PM


所有的时间均为北京时间。 现在的时间是 03:33 AM.


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