几何尺寸与公差论坛

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

【转帖】need help with addin presentation from sw world 2007

[复制链接]
发表于 2009-4-13 13:02:00 | 显示全部楼层 |阅读模式
need help with addin presentation from sw world 2007
i'm reviewing a sw world 2007 presentation i attended titled "solidworks addins using .net".
the steps are:
1. record a simple macro in solidworks using vba.
2. verify the macro.
3. start visual studio.
4. create a new sw addin using swvbaddin template.
5. open swaddin.vb
6. expand the code region.
7. select all of the code in 'sub createcube ()'
8. use ctrl+k c to comment out the code
9. swith back to vba and select all the code in 'sub main ()'
10. copy and paste back to visual studio.
11. add 'dim' statements for each object.
12. replace 'applications.sldworks' with 'getobject (,"sldworks.application")'
13. build the addin and run using f5 to debug solidworks.
i followed all of the steps, but nothing happens in solidworks. the macro works fine if i run it thru vba.
any ideas?
below is the code under 'ui callbacks'
#region "ui callbacks"
sub main()
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
swapp = getobject(, "sldworks.application")
part = swapp.activedoc
selmgr = part.selectionmanager
boolstatus = part.setuserpreferencetoggle(196, true)
boolstatus = part.extension.selectbyid2("unknown", "browseritem", 0, 0, 0, false, 0, nothing, 0)
boolstatus = part.extension.selectbyid2("front", "plane", 0, 0, 0, false, 0, nothing, 0)
part.sketchmanager.insertsketch(true)
part.clearselection2(true)
part.sketchrectangle(-0.08407285067873, 0.06711078431373, 0, 0.06953393665158, -0.05404683257919, 0, 1)
part.setlinewidth(4)
part.setlinewidth(4)
part.setlinewidth(4)
part.setlinewidth(4)
part.setpickmode()
part.clearselection2(true)
part.sketchmanager.insertsketch(true)
part.clearselection2(true)
end sub
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
chris,
change your line sub main() to sub createcube().
when the user clicks on the create cube command it runs the subroutine createcube and you do not have one, you have a main subroutine.
this will get it to work, but in real life you will want to modify the line
cmdgroup.addcommanditem("createcube", -1, "create a cube", "create cube", 0, "createcube", "", 0)
the 6th parameter is the name of the sub to run. look at the api help file to see what the other parameters are.
wayne matus
texas engineering systems
originally posted by: wayne matus
chris,
change your line sub main() to sub createcube().
when the user clicks on the create cube command it runs the subroutine createcube and you do not have one, you have a main subroutine.
this will get it to work, but in real life you will want to modify the line
cmdgroup.addcommanditem("createcube", -1, "create a cube", "create cube", 0, "createcube", "", 0)
the 6th parameter is the name of the sub to run. look at the api help file to see what the other parameters are.
thanks wayne. the second line above is where i had the problem.
is there any way to test the addin from visual studio? it seems like i have to install it to test it, otherwise visual studio keeps launching solidworks.
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
chris, what version of visual studio are you running.? it was a while ago, but when i was using 2003 version, when i was in debug mode vs would launch solidworks but i had to manually turn on the add-in i was debugging. i now have 2005 version of vs and it seams to turn on the add-in when it launches solidworks when i am in debug mode. vs will have to launch solidworks to be able to test you code.
wayne matus
texas engineering systems
originally posted by: wayne matus
chris, what version of visual studio are you running.? it was a while ago, but when i was using 2003 version, when i was in debug mode vs would launch solidworks but i had to manually turn on the add-in i was debugging. i now have 2005 version of vs and it seams to turn on the add-in when it launches solidworks when i am in debug mode. vs will have to launch solidworks to be able to test you code.
i'm running visual studio 2005. when i press f5 (start debugging), solidworks will launch (even if its already open) and do nothing. if i press f5 again, solidworks will launch again and the journal file already in use message will popup.
any ideas?
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
chris,
close all of your solidworks sessions before you press f5. when you press f5 it will launch solidworks. your solidworks should now have the "vb addin" pulldown menu. if you click on the "create cube" menu item, it will run your code in your "sub createcube ()". if you have breakpoints in your code, it will run to the breakpoint and you can then step through your code and watch what it is doing in solidworks.
wayne matus
texas engineering systems
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 14:35 , Processed in 0.035772 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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