几何尺寸与公差论坛------致力于产品几何量公差标准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, 10:09 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】custom properties on several files

custom properties on several files
hey, here i am with another stupid question
i have an array which hold 2 things: a list of the full paths of a part and the quantity of the part.
eg: customprop(0)= "c:\test.sldprt" and customprop(1)="1"
what i want is a macro who does the following:
open the first part in the list
add or change the custom property "quantity" of the part to the value from the array
close the first part
open the second part
add or change ....
i've been trying all day now, but i just can't get it to work. could someone plz help me...
tnx a lot guys
steven,
here's some code posted below. might need some error handling to make it more robust... could also handle any open/save errors or warnings that get loaded into the long variables to increase robustness.
change out the array ary() with your own array. it's working here, but with sw you never know. let me know how it goes.
dim swapp as object
dim part as object
sub main()
set swapp = application.sldworks
'build test array
dim ary(5) as string
ary(0) = "c:\documents and settings\master bennett\my documents\part1.sldprt"
ary(1) = "11"
ary(2) = "c:\documents and settings\master bennett\my documents\part2.sldprt"
ary(3) = "111"
ary(4) = "c:\documents and settings\master bennett\my documents\part4.sldprt"
ary(5) = "11111"
dim i as integer
dim s as string
dim swopenerrors as long
dim swopenwarnings as long
'loop thru array
for i = lbound(ary) to ubound(ary) step 2
'determine doc type of filename from array
dim swdoctype as swconst.swdocumenttypes_e
dim extension as string
extension = ucase(strings.right(ary(i), strings.len(ary(i)) - strings.instrrev(ary(i), ".")))
select case extension
case "sldasm"
swdoctype = swdocumenttypes_e.swdocassembly
case "sldprt"
swdoctype = swdocumenttypes_e.swdocpart
case "slddrw"
swdoctype = swdocumenttypes_e.swdocdrawing
end select
'open document
set part = swapp.opendoc6(ary(i), swdoctype, swopendocoptions_silent, "", swopenerrors, swopenwarnings)
set swmodeldoc = swapp.activedoc
dim custompropmgr as sldworks.custompropertymanager
set custompropmgr = part.extension.custompropertymanager("")
dim custompropnames as variant
dim propalreadyexists as boolean
'see if custom property quantity already exists in the file
custompropnames = custompropmgr.getnames
if isempty(custompropnames) = false then
for j = lbound(custompropnames) to ubound(custompropnames)
if custompropnames(j) = "quantity" then
propalreadyexists = true
exit for
end if
next
end if
s = s + "quantity of " + ary(i) + " set to '" + ary(i + 1) + "'....."
'set custom property 'quantity'... 2 different methods depending on whether it already exists or not
dim retval as long
if propalreadyexists = true then
retval = custompropmgr.set("quantity", ary(i + 1))
if retval = 0 then
s = s + "success!"
else
s = s + "failed!"
end if
else
retval = custompropmgr.add2("quantity", swcustominfotext, ary(i + 1))
if retval = 1 then
s = s + "success!"
else
s = s + "failed!"
end if
end if
'save and close
dim retbool as boolean
retbool = part.save3(swsaveasoptions_silent, swopenerrors, swopenwarnings)
swapp.closealldocuments (false)
set part = nothing
set swmodeldoc = nothing
set custompropmgr = nothing
s = s + vbcrlf
next
'display results
msgbox s
end sub
kevin bennett
kevinsbennett@navitech.us
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】custom properties for multiple part configurations yang686526 SolidWorks二次开发 0 2009-04-13 10:08 AM
【转帖】bulk change descriptions for files in the vaul yang686526 SolidWorks二次开发 0 2009-04-13 09:23 AM
【转帖】add custom properties yang686526 SolidWorks二次开发 0 2009-04-13 08:41 AM
【转帖】macro for adding customconfiguration properties yang686526 SolidWorks二次开发 0 2009-04-12 09:37 PM


所有的时间均为北京时间。 现在的时间是 10:55 PM.


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