高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】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
|