几何尺寸与公差论坛------致力于产品几何量公差标准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-12, 09:38 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】macro for iterating a dimension and saving as jpeg, 280 time

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


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

高级搜索
显示模式

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

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



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


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