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

controlling sw with excel?
i am fairly new to the solidworks api and have been working alot with excel and the vba editor there to create different workbooks and what not, but now i am trying to do some very basic stuff in solidworks with data created in excel. the basic project i am trying to do is;
1) a series of points in 3d (have the xyz corrdinates of the points) to create a sketch, add annotations to the points. (basically a 3d scatter plot)
2) create 3d line sketches between these points (has point 1 and point 2 , using a sketch between 2 points that i figured out the code from backwards engineering a recorded macro)
3) adding annotations to those lines
4) renaming the sketches that were made to following a naming convention for the sketch as it was created, ie 3dsketch2 -> "1" and so forth through around 300 sketches
i have backwards engineered most of the code for this with recording macros and pulling out the code and then using a mail merge in word to formulate the code. the only problem is that i get vba code that is a few thousand lines long and it will not compile it, so it has to be broken up and entered in peices which takes way to long. i know i can do this with a loop, but i don't know how to access excel from sw or what would be even better is if i could use excel api to access sw and create the model from there. its seems very basic but not sure how to start it. i am going to pick up the 2008 api book that luke malpass wrote as it seems like it would help alot in basic understanding of the api structure. but some input on this matter would be very helpful.
thanks for the help in advance,
adam
answer if i understand you correctly you have more or less mastered the create sketches from points part. that you need help with is how to access sw from excel. here is an example on how to do that:
'this code is inserted in the vba module in excel
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
'this code starts sw from excel
set swapp = createobject("sldworks.application")
swapp.visible = true 'makes sw visible
[insert the rest of your code here]
hope this will help. can also recommend a good book that has helped me a lot. namely "automating solidworks 2006 using macros", by mike spens. isbn 1-58503-263-8
joel andersson
development engineer hägglunds drives
solidworks 2007 sp5.0
edited: 07/15/2008 at 02:21 am by joel andersson
that helps alot actually, thank you very much!
as for that book, does it help with basic stuff like this? i am trying to control some more sw stuff from excel and would like to learn as much as i can of the api since it seems to be one of the best ways to work with sw.
yes, the book give you a help with this kind of basic things.
joel andersson
development engineer hägglunds drives
solidworks 2007 sp5.0
cool, i guess i shall pick that up. got a few more questions though,
i am creating a new sketch each time i run my macro, which yeilds a part1, part2, part3... and so on for the new window before it saves. my code calls this out for the part. command, is there a way to make it so it always selects the new window?
-> code in question
set part = swapp.activatedoc2("part14", false, longstatus)
with the "part14" needed to be varible....
also, is there a way to disable the screen refresh on solidworks. in excel you can change the application.screenupdate = false so it won't display what is going on until the job is finished, and it is alot faster. i am hoping there is a way to do this in solidworks too because watching it make 300 points, add annotations and a bunch of other fun stuff takes way longer then it should since it shows the screen making the point, going to edit the point location, and so on.
thanks for the help
maybe a for-loop could work?
[example]
dim countpart as integer 'rename countpart to a variable that suits you
for countpart = 1 to 300
set part = swapp.activatedoc2("part"&countpart, false, longstatus)
[the rest of the code]
next countpart
on your last question, try to set swapp.visible=false to see if this makes any different
joel andersson
development engineer hägglunds drives
solidworks 2007 sp5.0
for the for loop, i normally close the window when it doesn't work, or done checking something, so counting open parts wouldn't work (same goes for it i have other parts open at the same time). it is the internal sw default new part name that pops up and resets to 1 when you close sw and reopen it.
for the second question, i tried that and it still shows it, which baffles me....
set modeldoc = swapp.activedoc
name = modeldoc.gettitle
that right there gives me the name and everything so i plugged that into the set part command and it works perfect for the new doc created and always updates for the newest part the macro opens.
now to see if i can turn off the screen refresh while making parts...
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】open sw part using excel vba yang686526 SolidWorks二次开发 0 2009-04-12 09:57 PM
【转帖】excel question yang686526 SolidWorks二次开发 0 2009-04-12 08:52 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


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


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