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

multiple macros in one vsta project
i am just starting to fool around with using vsta macros instead vba. with vba i was able to have multiple subs in one file. in solidworks i could then reference whichever sub i wanted to as a separate macro. this allowed me to keep similar macros grouped together into a single easy to maintain file. it also let me use subfunctions in order to avoid repeating code between macros.
when i try to do this with vsta i get an error because solidworksmacro_startup always tries to run main(). is there a way around this, or will i need separate projects for each of my macros, with shared code saved as a separate .vb file?
mahir abrahim, cswp/core. cswp/smtl
mechanical design engineer
sw 2009 sp2.1
proe wf3/4
in solidworksmacro_startup you can change main() in enything you want.
and in solidworks macro button you can choose module and sub which you want.
and if you call macro from another you can also specify which file, module and sub you want.
function runmacro2( _
byval filepathname as string, _
byval modulename as string, _
byval procedurename as string, _
byval options as integer, _
byref error as integer _
) as boolean
thanks, ivana. i already figured that you could change the name of the startup sub, but the problem is that there is still a startup sub. let's say you have 3 macros that do almost the same thing. with vba i could simply write a main routine accompanied by three small subs (see below). i don't see how to do this using vsta without creating multiple project folders.
sub runmacro(i as integer)
'some function relying on the integer i
end sub
sub macro1()
runmacro(1)
end sub
sub macro2()
runmacro(2)
end sub
sub macro3()
runmacro(3)
end sub
mahir abrahim, cswp/core. cswp/smtl
mechanical design engineer
sw 2009 sp2.1
proe wf3/4
i have 2009 only one day. so i don't know if this is right way
imports solidworks.interop.sldworks
imports solidworks.interop.swconst
imports system
partial class solidworksmacro
sub subrunmacro(byval i as integer)
'some function relying on the integer i
msgbox(i)
end sub
public sub macro1()
subrunmacro(1)
end sub
public sub macro2()
subrunmacro(2)
end sub
public sub macro3()
macro4() ' is sub in module1
end sub
'''
''' the sldworks swapp variable is pre-assigned for you.
'''
public swapp as sldworks
end class
edited: 01/25/2009 at 08:50 am by ivana kolin
thanks again, but i tried that already with no success. vsta will try to run whatever your startup routine is (runmacro) and ignore the calling functions you actually want to run first (macro1/2/3). go ahead and give it a try. maybe you can find out something i couldn't.
mahir abrahim, cswp/core. cswp/smtl
mechanical design engineer
sw 2009 sp2.1
proe wf3/4
i've never worked with vsta before, but i created this macro by recording a macro and then adding a subroutine manually:
imports solidworks.interop.sldworks
imports solidworks.interop.swconst
imports system
partial class solidworksmacro
public sub main()
dim swdoc as modeldoc2 = nothing
dim swpart as partdoc = nothing
dim swdrawing as drawingdoc = nothing
dim swassembly as assemblydoc = nothing
dim boolstatus as boolean = false
dim longstatus as integer = 0
dim longwarnings as integer = 0
swdoc = ctype(swapp.opendoc6("m:\7201df.sldprt", 1, 0, "", longstatus, longwarnings),modeldoc2)
swapp.activatedoc2("7201df.sldprt", false, longstatus)
swdoc = ctype(swapp.activedoc,modeldoc2)
dim mymodelview as modelview = nothing
mymodelview = ctype(swdoc.activeview,modelview)
mymodelview.framewidth = 2866
mymodelview.frameheight = 952
end sub
public sub macro2()
msgbox("hello world!")
end sub
'''
''' the sldworks swapp variable is pre-assigned for you.
'''
public swapp as sldworks
end class
then i created a macro button and pointed it to the macro. in the dropdown box labeled "method" i chose "macro2". when i click the button, macro2 runs but main() does not. this is the same functionality as working with vba. how exactly are you trying to run your macros?
i'll get you eh steve, if it's the last thing i dooooo!
edited: 01/26/2009 at 09:00 am by josh brady
john, that's exactly what i'd like to do. i'll give it another go. i've only tried running from within the programming environment, and it wouldn't work. in vba you simply go to the sub you want to run and click f8 to start executing from there. vsta kept running whatever sub was specified in solidworksmacro_startup (main by default). it's possible actually attaching a button to the alternate subs works even though the ide doesn't run the macro as expected.
mahir abrahim, cswp/core. cswp/smtl
mechanical design engineer
sw 2009 sp2.1
proe wf3/4
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】best way to release macros yang686526 SolidWorks二次开发 0 2009-04-12 08:18 PM
【转帖】backwards compatible macros yang686526 SolidWorks二次开发 0 2009-04-12 08:16 PM
【转帖】solidworks macros capabilities yang686526 SolidWorks二次开发 0 2009-04-12 07:40 PM
【转帖】how to use and setup macros yang686526 SolidWorks二次开发 0 2009-04-12 06:40 PM


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


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