几何尺寸与公差论坛

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

【转帖】macro for iterating a dimension and saving as jpeg, 280 time

[复制链接]
发表于 2009-4-12 21:38:34 | 显示全部楼层 |阅读模式
macro for iterating a dimension and saving as jpeg, 280 time
hi i'm new to macros and api.
i am trying to create a marco to add .002" to a dimension of a part (in an assembly ), then save a jpeg (of the assembly). i need to repeat this step 250 times. also, it would be great if the jpegs could be saved with incrimenting file names (for example, jpeg1, jpeg2, jepg3.... jpeg250)
i tried recording a marco with in solidworks, but i'm not having much luck.
here's what i was able to record...
' ************************
' c:\docume~1\ryan\locals~1\temp\swx228\macro1.swb - macro recorded on 12/10/08 by ryan
' *************************
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
--------------
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
swapp.activedoc.activeview.framestate = 1
boolstatus = part.extension.selectbyid2("change this in .001 inc.@gel-1@medipacs assembly", "sketch", 0, 0, 0, false, 0, nothing, 0)
part.activateselectedfeature
boolstatus = part.extension.selectbyid2("d1@change this in .001 inc.@gel-1@medipacs assembly", "dimension", 0.03445823466426, 0.001334141779371, -0.004879878089606, false, 0, nothing, 0)
part.parameter("d1@change this in .001 <A href="mailto:inc.@gel.part").systemvalue">inc.@gel.part").systemvalue = 0.0030734
part.clearselection2 true
boolstatus = part.editrebuild3
part.extension.saveas "c:\documents and settings\all users\documents\medipacs animation\1.jpg", 0, 0, nothing, longstatus, longwarnings
end sub
---
can someone help?
so you are trying to create an animation? why don't you use the motion study. you can save each frame as a bmp file automatically. bmp to jpg conversion is simple. you can also save directly to an avi file.
hope this helps.
tony szuta
cswa, cswp, cswp-smtl
yes, an animation.
will a motion study allow me to change the physical geometry of the part (i.e., make the part grow)?
edited: 12/10/2008 at 04:54 pm by ryan root
the physical geometry of a part changes .002" every frame? would it be possible to get a screen shot of this part? that is a 0.5" range of travel from frame 0 to 250. i am just curious as to what the part is.
as far as i can tell, the sketch geometry of a part can not be changed within a motion study. you can manipulate the system though depending on how your part was modeled. for instance, you could have a feature extrude up to a surface. that surface (a dummy part that is hidden) could move in the assembly. the part should follow suit and update accordingly. it may take a bit more thinking, but i think it can be done.
tony szuta
cswa, cswp, cswp-smtl
i just did a test animation and the idea works. you may have to bend it a little bit to suit your needs.
tony szuta
cswa, cswp, cswp-smtl
here you go:
option explicit
dim swapp as sldworks.sldworks
dim swmodel as modeldoc2
dim selmgr as object
dim lstatus as long, lwarning as long
dim inc as double
dim par as string
dim i as integer, steps as integer
sub main()
set swapp = application.sldworks
set swmodel = swapp.activedoc
set selmgr = swmodel.selectionmanager
' set your parameter name to alter here
par = "d1@extrude1"
' set your increment amount
inc = 0.0000508
' set your loop amount
steps = 25
for i = 1 to steps
swmodel.parameter(par).systemvalue = swmodel.parameter(par).systemvalue + inc
swmodel.editrebuild3
' !! make sure folder exists first !!
swmodel.extension.saveas "c:\examplefolder\jpeg" & i & ".jpg", 0, 0, nothing, lstatus, lwarning
next
end sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-1-11 14:08 , Processed in 0.039620 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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