几何尺寸与公差论坛

 找回密码
 注册
查看: 1062|回复: 0

【转帖】execute a sw macro from a macro of another software, is it possible

[复制链接]
发表于 2009-4-13 10:46:59 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 22:37 , Processed in 0.036689 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表