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

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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】addin application9.dll0 yang686526 SolidWorks二次开发 0 2009-04-13 08:44 AM
【转帖】calling a sw addin from exe-file yang686526 SolidWorks二次开发 0 2009-04-12 05:42 PM
How to start SW 2007 or SW 20006 via SW API? If I have two different versions of SW yogy SolidWorks二次开发 1 2007-05-21 09:19 AM


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


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