几何尺寸与公差论坛

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

【转帖】modifying design table values with a macro

[复制链接]
发表于 2009-4-12 21:49:24 | 显示全部楼层 |阅读模式
modifying design table values with a macro??
does anyone know of a way to use a macro to change the value of the cells in the design table?
for example... if i have a form where the user enters a value... say beam size... the macro will edit the cell of the design table that corresponds to the beam size and the design table can update the part.
my design tables are internal inside my solidworks part. what i'm having trouble with isn't the code to actually change the value of a cell, but how to access the cell that is inside the design table in the part so that i can change it.
christina,
look for 'modeldoc2::getdesigntable' in the api help. there are several examples.
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
there are several examples in there of how to access the design table... but nothing with how to get it to change the value of a cell and that's proving to be more problematic than i initially thought it would be.
any thoughts on how to get it to actually change the value of a cell and update the table??
hey christina,
modifying cells in design tables uses the same principles as doing so in excel.
i'll attach below a small code sample of how to do it and if you have more issues reply again here.
code:
'get the design table
set destable = modeldoc.getdesigntable()
'get the work sheet
set wsheet = destable.edittable2(true)
' assign values to cells
wsheet.cells(2, 2) = "a value"
wsheet.cells(2, 3) = "another value"
'close the table to update
modeldoc.closefamilytable
''''''''''''''''''
hope this helps,
cheers,
--stav.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
edited: 11/10/2008 at 04:27 am by stavros antoniou
i want to do this as well.
i have already written all the code for the forms to modify the design table.
-----
the first attempt i did this....
part.insertfamilytableedit
set exapp = getobject(, "excel.application")
set exwb = exapp.workbooks.application.activeworkbook
set exws = exwb.worksheets(1)
.
.
.run all code with exws. to access work sheet
everything works fine until i close
i used
exapp.quit
when i did the changes would not affect the part. when i tried to reopen the design table it said "file not found"
-------
per your suggestion i tried
part.insertfamilytableedit
dim destable as designtable
set destable = swmodeldoc.getdesigntable()
set exws = destable.edittable2(true)
.
.
.
do stuff
.
.
swmodeldoc.closefamilytable
again i get the same problem where file not found if i try to open again and changes are not made to the design table.
any suggestions?
edit:
strange...i wrote a macro with two lines
set part = swapp.activedoc
part.closefamilytable
when i run this macro with design table open it worked properly
edited: 02/27/2009 at 12:54 pm by kevin hardin
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 10:40 , Processed in 0.036076 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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