几何尺寸与公差论坛------致力于产品几何量公差标准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, 12:03 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how to speed up code execution

how to speed up code execution
i have some solidworks api code that takes about 5 hours to run. i think the main reason for the slowdown is the user interface has to keep updating. is there a way to run code without screen updating or any of the user interface overhead? if i could run the code in memory in the background, it could potentially save hours of time. thanks.
i am wondering the same thing, i basically draw a bunch of sketches and label them by the time its on its 6th or 7th hundred 3dsketch sw starts to slow down.. even with a dual quad core 3.2ghz xeon machine with 3gb of ram...
if i could disable the screen updating it would speed it up tons...
guys,
look at sldworks::visible...
sldworks::usercontrol and sldworks::usercontrolbackground could also be useful to you.
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
another thing which will also have some effect if you don't want to run in hidden mode is to reduce the sw windows size when running your macro.
another great advantage of running in hidden mode is that the system uses much less ram.
i have seen examples of 50-60% speed improvement and a 50% decrease in ram usage when running in hidden mode. the downside is that you wont see any errors and messages from the system while it runs.
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
edited: 10/21/2008 at 02:05 pm by jorn bjarning
you should be able to see errors still as long as you use errorhandling in your app/macro.
edit: note though that if you do error out and your macro stops running before invoking the sldwrks.visible = true command, then the program will likely still be running but remain invisible.
edited: 10/21/2008 at 02:07 pm by blake dahle
if you are sketching a lot of geometry, look at sketchmanager.addtodb and sketchmanager:isplaywhenadded. these will seed up execution.
wayne matus
texas engineering systems
i am basically passing a list of 150 3d points to sw then connecting certain ones with a 3d sketch to make a wireframe model of some structures. if there is an easier / faster way to import these into sw instead of the code i have listed here
do while i < finalgrid
part.createpoint2 worksheets("grid points").cells(i, 3).value, worksheets("grid points").cells(i, 4).value, worksheets("grid points").cells(i, 5).value
boolstatus = part.extension.selectbyid2("point" & i - 1, "sketchpoint", worksheets("grid points").cells(i, 3).value, worksheets("grid points").cells(i, 4).value, worksheets("grid points").cells(i, 5).value, false, 0, nothing, 0)
set note = part.insertnote("" & worksheets("grid points").cells(i, 2).value)
if not note is nothing then
note.angle = 0
boolstatus = note.setballoon(0, 0)
set annotation = note.getannotation()
if not annotation is nothing then
longstatus = annotation.setleader2(true, 0, false, false, false, false)
longstatus = annotation.setarrowheadstyleatindex(0, 10)
boolstatus = annotation.setposition(worksheets("grid points").cells(i, 7).value, worksheets("grid points").cells(i, 8).value, worksheets("grid points").cells(i, 9).value)
end if
end if
part.clearselection2 true
part.windowredraw
i = i + 1
loop
(runs from microsoft excel...)
then it would be awesome since on the larger model (200 points, 600 members) it takes about 20 minutes to execue the program (adds notes at all the points labeling the point, and member gets an annotation also saying what it is)
you can speed this loop up quite a bit by doing the following:
first create a new variable of the worksheet you are after like so:
dim worksheet as worksheet
set worksheet = worksheets("grid points")
now reference this variable instead of writing worksheets("grid points") every time, as all this will do is constantly create new instances of the worksheet pointer every time you call it (which is a lot). by creating a variable once this is avoided.
and move part.windowredraw to outside of the loop to only update once the entire loop is complete.
doing that you will see minor improvements over say 50 files, but once you are into the hundreds the speed difference should show.
this was good timing as i was wondering the same thing.
i've got a vba routine that takes points from excel and modifies existing 3d sketch points for approximately 10 part files. using the "visible" property i decreased the runtime from 42 seconds to 20 seconds.
my syntax was:
(before the code runs)
swapp.usercontrol = false
swapp.visible = false
(after the code runs)
swapp.usercontrol = true
swapp.visible = true
changed the thing that luke said and it dropped from 25 minutes to build a model to 11 minutes, so that is very nice, thats with 242 points and then 620 3d sketches between them.
tried to get the background part to work, but it still shows it for me, and doesn't run the background. as for addtodb, i cannot find that in the solidworks api help to see how to work it...
edit -
the visible only works if there is nothing in solidworks open, or the application is closed itself. is there a way to hide the application if something is open already? but running it with the visible off made a smaller model that was taking 4 min to run to complete in around 2....
edited: 10/22/2008 at 11:10 am by adam hodge
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】dialog box sample code yang686526 SolidWorks二次开发 0 2009-04-13 10:20 AM
【转帖】code for a trial yang686526 SolidWorks二次开发 0 2009-04-13 09:45 AM
【转帖】api code speed and sw menu activation yang686526 SolidWorks二次开发 0 2009-04-13 08:56 AM


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


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