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

new to api & need help
i try to make a macro that saves the active document to edrawing file in the same original drawing path and with the same name. so i started recording it and click on file-> save as -> choose edrawings extension and press enter but after that when i used this macro i found that it saves the active document in the same folder as the file i used to create the macro with and with the same name. the code below is the result.
could any one help me with that and tell me what i have to relplace with what to make createthe edrawing file from the active sheet in the path of the drawing file.
thanks in advanced.
' ******************************************************************************
' c:\docume~1\mc1c6~1.abd\locals~1\temp\swx3912\macro1.swb - macro recorded on 12/21/08 by m. abdel moniem
' ******************************************************************************
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
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
part.extension.saveas "d:\cad-cam-cae\solidworks\work\test\test file.edrw", 0, 0, nothing, longstatus, longwarnings
end sub
mohamed abdel moniem | mechanical engineer
cswp, cswa, cswp core, cswp-smtl
solidworks 2009 sp3.0
vista x64 sp1.0
intel q6600, 8gb ram
ati hd 4850
3dconnexions spacenavigator
try this.
option explicit
sub main()
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
dim longstatus as long, longwarnings as long
dim filename as string
set swapp = application.sldworks
set part = swapp.activedoc
filename = part.getpathname
filename = left(filename, len(filename) - 6)
select case part.gettype
case swdocdrawing
filename = filename & "edrw"
case swdocassembly
filename = filename & "easm"
case swdocpart
filename = filename & "eprt"
end select
swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall
part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings
end sub
mahir abrahim, cswp/core. cswp/smtl
mechanical design engineer
sw 2009 sp2.1
proe wf3/4
i tried to do it but i think i did it in a wrong way. i copied the code you sent to me and replace it with mine as follows but it doesn't work.
' ******************************************************************************
' c:\docume~1\mc1c6~1.abd\locals~1\temp\swx3912\macro1.swb - macro recorded on 12/21/08 by m. abdel moniem
' ******************************************************************************
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
option explicit
sub main()
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
dim longstatus as long, longwarnings as long
dim filename as string
set swapp = application.sldworks
set part = swapp.activedoc
filename = part.getpathname
filename = left(filename, len(filename) - 6)
select case part.gettype
case swdocdrawing
filename = filename & "edrw"
case swdocassembly
filename = filename & "easm"
case swdocpart
filename = filename & "eprt"
end select
swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall
part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings
end sub
swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall
part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings
end sub
mohamed abdel moniem | mechanical engineer
cswp, cswa, cswp core, cswp-smtl
solidworks 2009 sp3.0
vista x64 sp1.0
intel q6600, 8gb ram
ati hd 4850
3dconnexions spacenavigator
you have multiple object declarations, e.g. swapp is declared twice. don't just replace the code between "sub main()" and "end". replace all the code with what i listed in my last post.
mahir abrahim, cswp/core. cswp/smtl
mechanical design engineer
sw 2009 sp2.1
proe wf3/4
mahir,
thank you finally it works, in the beginning it wasn't working because there was a problem in the line ( filename = left(filename, len(filename) - 6) )
i opened a macro for save as pdf i already have searched for a line with the same syntax and i found it but as follows:
filename = strings.left(filename, len(filename) - 6)
so i edit the macro with as that one and it works.
thanks so much for your help
the final macro is the following, also the macro is attached below.
' ******************************************************************************
' c:\docume~1\mc1c6~1.abd\locals~1\temp\swx3912\macro1.swb - macro recorded on 12/21/08 by m. abdel moniem
' ******************************************************************************
option explicit
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
sub main()
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
dim longstatus as long, longwarnings as long
dim filename as string
set swapp = application.sldworks
set part = swapp.activedoc
filename = part.getpathname
filename = strings.left(filename, len(filename) - 6)
select case part.gettype
case swdocdrawing
filename = filename & "edrw"
case swdocassembly
filename = filename & "easm"
case swdocpart
filename = filename & "eprt"
end select
swapp.setuserpreferenceintegervalue swedrawingssaveasselectionoption, swedrawingsaveall
part.extension.saveas filename, 0, 0, nothing, longstatus, longwarnings
end sub
mohamed abdel moniem | mechanical engineer
cswp, cswa, cswp core, cswp-smtl
solidworks 2009 sp3.0
vista x64 sp1.0
intel q6600, 8gb ram
ati hd 4850
3dconnexions spacenavigator
i'm glad it's working. sounds like you're using vsta instead of just vba. i've never used it, but i hear it's supposed to be a more .net implementation of vba, which explains why you had to use strings.left. also, i would still get rid of everything before "sub main()" except for "option explicit". those lines are redundant and might cause problems later.
mahir abrahim, cswp/core. cswp/smtl
mechanical design engineer
sw 2009 sp2.1
proe wf3/4
actually i don't know what is the difference between vsta & vba. but at the end it works fine till now if i got any problem i'll remove the lines before "sub main()". i think i have to join a course for vba asap. and then go in to the world of api. i think i found how mach it's useful very late.
thank you again mahir.
mohamed abdel moniem | mechanical engineer
cswp, cswa, cswp core, cswp-smtl
solidworks 2009 sp3.0
vista x64 sp1.0
intel q6600, 8gb ram
ati hd 4850
3dconnexions spacenavigator
thanks,i am study.
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】doc manager api requires presence of solidworks explorer yang686526 SolidWorks二次开发 0 2009-04-12 08:41 PM
【转帖】solidworks 2008 api book - released yang686526 SolidWorks二次开发 0 2009-04-12 07:38 PM
【转帖】doc manager api requires presence of solidworks explorer yang686526 SolidWorks二次开发 0 2009-04-12 06:00 PM
【转帖】外挂开发中的封包技术 huangyhg vc编程 0 2007-12-03 04:41 PM
【转帖】对于hook函数的一点认识 huangyhg vc编程 0 2007-03-27 11:53 AM


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


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