几何尺寸与公差论坛------致力于产品几何量公差标准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-13, 10:46 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】execute a sw macro from a macro of another software, is it possible

execute a sw macro from a macro of another software, is it possible?
good morning. i have a question for you. can i execute a solidworks macro from a macro from another program? for example, if i create a visual basic macro for word office i want that this macro open a solidowrks session and execute a sw macro. is it possible to do this?
originally posted by: loris rivelli
can i execute a solidworks macro from a macro from another program? for example, if i create a visual basic macro for word office i want that this macro open a solidowrks session and execute a sw macro. is it possible to do this?
it is possible to call a macro or an exe-file from another macro but it is also possible to add the sw specific code directly into the word macro. you don't have to have a seperate macro-file which holds the sw code. adding the code shown here below to your word macro will create a sw session (or attach to an existing session) when running the word macro.
-----------------------
public swapp as sldworks.sldworks
public part as sldworks.modeldoc2
public sub activatesolidworks()
dim boolstatus as boolean
dim returnvalue as long
on error resume next
'activate solidworks
set swapp = getobject(, "sldworks.application")
'if solidworks is not started then start it
if err.number <> 0 then
set swapp = createobject("sldworks.application")
end if
set part = swapp.activedoc
'make solidworks application visible
swapp.visible = true
swapp.usercontrol = true
end sub
-----------------------
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
many thanks for the example, but suppose that i have a word open session and a swp file (sol idworks macro), now how i can from the word macro open solidworks and execute swp file? can you make me an exaple? thanks very very much. a second problem : if i wrote public swapp as sldworks.sldworks it give me the error:user-defined type not defined
edited: 10/23/2007 at 07:28 am by loris rivelli
originally posted by: loris rivelli
many thanks for the example, but suppose that i have a word open
session and a swp file (sol idworks macro), now how i can from the
word macro open solidworks and execute swp file? can you make me an
exaple? thanks very very much. a second problem : if i wrote public
swapp as sldworks.sldworks it give me the error:user-defined type
not defined
i am a little busy today but i will see if i can have a small example ready for you tomorrow.
you second problem:
open the visual basic editor in word. goto tools/references and enable "sldworks 200x type library" and "solidworks 200x constant type library".
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
loris,
i don't think you can run a sw macro from a word macro but you can copy-paste the content of the sw macro into the word macro and run the sw-related code from within the word macro. wouldn't it also be nicer to have all the code maintained in the word document instead of having some code in a seperate macro?
i have attached a word document containing a button. when pressing the button the activatesolidworks procedure published in earlier mail is called and after that a new part document is created in sw.
the sw related code is located in the module swmacro but it doesn't have to be located in a seperate module.
i hope it helps you out.
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
jorn,
once you get the solidworks object inside the word macro you can call a solidworks macro by using call retval = sldworks.runmacro ( filepathname, modulename, procedurename )
sa
edited: 10/23/2007 at 08:52 pm by solidair
originally posted by: solidair
once you get the solidworks object inside the word macro you can call a solidworks macro by using call retval = sldworks.runmacro ( filepathname, modulename, procedurename )
all right! thank you for enlighten me. i doubt i will ever want to or need to use this call, but anyway it's good to know it can be done.
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
in the same way of thinking, is it possible to run a macro on events in solidworks?
running macros when someone attempt to print for instance??
pierre-andré mongeon
*-----------------------*
junior mech. eng.
sw2007 sp4.0
sw2008 sp3.1
kbeworks
api development
do a search in api help on "*event* then search those results with "*print*". you should see some of the printing events you can capture and then run a macro on.
sa
this is an old thread, but maybe someone could give me an opinion on this.
i am creating an addin called "engineering macros". this will contain all the macros that i created for our engineering department. currently, i have to tell everyone to manually add a new macro to their macro toolbar whenever i create a new macro. so if i create an addin, i can store the addin on the network and all users will always have an up-to-date macro list since they will be pointing to that .dll file. also, rather than put all the macro code inside of the addin, what if i just called the existing macros from the addin. the user clicks one of the addin toolbar buttons, and it calls an existing .swp file.
does this make any sense? if not, any suggestions on something better?
cswp
solidworks office professional 2008, sp 3.1
pc #1:
dell precision t3400, core2duo 2.33ghz, 4gb ram,
nvidia quadro fx 1700
pc #2:
dell precision 380, p4 3.80ghz, 2gb ram,
nvidia quadro fx 1400
edited: 05/12/2008 at 09:50 am by chris m
a couple years ago i created an addin that would start programs and it worked fine for what i was doing. the programs i was using were vb6 exe files and to update the program a person just overwrote the exe file.
right now i'm using swp files because i can change them on the fly without having to edit them then save them as exe's files. when a person starts a program from the toolbar, in most cases, the first dialog box shown has a couple buttons that if the button is pushed a different program will run. this way the programs that pertain to assemblies are on one toolbar button and part programs are on another.
dan miel
sw 2008
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
Scheme 程序语言介绍之一 huangyhg 专家系统 6 2010-02-18 01:22 PM
【转帖】custom property macro bugging ou yang686526 SolidWorks二次开发 0 2009-04-13 10:09 AM
【转帖】how to silent printing pdf from sw macro yang686526 SolidWorks二次开发 0 2009-04-12 09:24 PM
【转帖】how to silent printing pdf from sw macro yang686526 SolidWorks二次开发 0 2009-04-12 06:39 PM


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


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