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

custom properties bom ---> txt
hello fella's,
i've been looking into making a macro for 1 specific task, but i'm finding myself in need of some advice.
to sketch my situation :
i've got 1 assembly, containing several (3-4) subassemblies. these subassemblies each contain vareous parts.
these parts (and only the parts) all have 1 thing in common. they all have a custom property called "bomcode" (meaning bill of material code).
what i'm trying to do is to grab the value of the custom property "bomcode" of each part (unsuppressed and visible), and write these away in an txt file , 1 line at a time.
what i mean with unsuppressed and visible :
like any other bom-table would, only list the parts that aren't suppressed.
there are no fancy configurations envolved.
here is a simplified example of my current layout :
this txt file shows what i'm trying to retrieve; (the lines in the txt file represent the custom property value)
hoping on some good advice,
yours
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
you just want to traverse the assembly tree to get all features, then for each feature check its type and its suppression and visibility, and if it is a part that is visible and unsuppressed, get its model then get its custom property.
a perfect example for you already exists in the api help for 90% of what you want to do. just type in "traverse featuremanager design tree (vb)" in the search
thanks for the quick reply there luke !
i'll give it a try, and keep you updated !
cheers,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
ok this is what i have thusfar :
i'm able to traverse the feat. tree and pick out all components (parts & assemblies) that are not suppressed, and write these (the component names) away to an external txt file.
what id still would like to add is ;
- have only parts in the list (drop assemblies)
- only parts with the custom property "bomcode" allowed on the list
- only have bomcode.value written into the textfile (instead of component names)
this is how my code looks like (snippets alert ) :
option explicit
global fs, a as object
dim traverselevel as integer
sub writecptext()
dim swapp as sldworks.sldworks
dim modeldoc2 as sldworks.modeldoc2
dim featuremgr as sldworks.featuremanager
dim rootnode as sldworks.treecontrolitem
set swapp = application.sldworks
set modeldoc2 = swapp.activedoc
set featuremgr = modeldoc2.featuremanager
set rootnode = featuremgr.getfeaturetreerootitem()
set fs = createobject("scripting.filesystemobject")
set a = fs.createtextfile("c:\" & plnr & ".txt", true)
if not rootnode is nothing then
debug.print
traverselevel = 0
traverse_node rootnode
end if
a.close
end sub
private sub traverse_node(node as sldworks.treecontrolitem)
dim childnode as sldworks.treecontrolitem
dim featurenode as sldworks.feature
dim componentnode as sldworks.component2
dim nodeobjecttype as long
dim nodeobject as object
dim restofstring as string
dim displaynodeinfo as boolean
dim compname as string
dim componentdoc as object
displaynodeinfo = false
nodeobjecttype = node.objecttype
set nodeobject = node.object
select case nodeobjecttype
case swconst.swtreecontrolitemtype_e.swfeaturemanageritem_component: 'only when nodeobjecttyp is a component (would like to have parts only, filter out assemblies)
if not nodeobject is nothing then
set componentnode = nodeobject
compname = componentnode.name2
set componentdoc = componentnode.getmodeldoc
if componentnode.getsuppression() = swconst.swcomponentsuppressionstate_e.swcomponentfullyresolved then 'is part suppressed ?
'here i'd like to see an additional filter to only let parts trough that have a custom property called "bomcode"
displaynodeinfo = true
end if
restofstring = "[component: " & compname & "]" 'this could/should be value of bombcode (custom property) of the current componetn beeing handled.
else
restofstring = "[component: object null?!]"
end if
case else:
displaynodeinfo = false
if not nodeobject is nothing then
restofstring = "[object type not handled]"
else
restofstring = "[object null?!]"
end if
end select
if (displaynodeinfo) then
a.writeline (node.text & " : " & restofstring) 'here i'd like to write away the value of bomcode (custom property)
end if
traverselevel = traverselevel + 1
set childnode = node.getfirstchild()
while not childnode is nothing
traverse_node childnode
set childnode = childnode.getnext
wend
traverselevel = traverselevel - 1
end sub
i'm sure this might be coded more compactly and efficiently but im not ace in vb .
suggestions are welcome !
so where do i still need help, you ask ?
mainly on the spots with highlighted comments.
1) how to tell the difference between an assembly and part.
2) how can i detect if the current proccesed part has the custom property "bomcode"
3) how do i capture that value of "bomcode" to write away in the textfile
thanks for reading al this and sticking with me !
hoping on some good advice,
regards,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
answer option explicit
sub main()
dim swapp as sldworks.sldworks
dim swassy as assemblydoc
dim swmod as sldworks.modeldoc2
dim swcustpropmgr as sldworks.custompropertymanager
dim comp as sldworks.component2
dim vs as variant
dim v as variant
dim valout as string
dim revalout as string
dim fs, a as object
dim plnr as string
plnr = "something"
set fs = createobject("scripting.filesystemobject")
set a = fs.createtextfile("c:\" & plnr & ".txt", true)
set swapp = application.sldworks
set swmod = swapp.activedoc
if swmod.gettype = swdocassembly then
set swassy = swmod
vs = swassy.getcomponents(false)
for each v in vs
set comp = v
if comp.getsuppression = swcomponentfullyresolved then
if comp.getmodeldoc.gettype = swdocpart then
set swcustpropmgr = comp.getmodeldoc.extension.custompropertymanager("")
swcustpropmgr.get2 "bomcode", valout, revalout
if valout <> "" then
a.writeline valout 'here i'd like to write away the value of bomcode (custom property)
else
end if
end if
end if
next v
end if
end sub
woohooow ivana !
thats some mean lean mighty code you've pumped in here !!
thanks alot ! this does all the sweetness i ished for !!
humble and kind regards !
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】api for pdmwe to get the custom properties yang686526 SolidWorks二次开发 0 2009-04-12 08:12 PM
【转帖】setting custom properties yang686526 SolidWorks二次开发 0 2009-04-12 07:36 PM
【转帖】how to make a tool which checks that all the views are linked to bom are no yang686526 SolidWorks二次开发 0 2009-04-12 06:37 PM
Unicode、UCS、UTF、BMP、BOM huangyhg vc编程 2 2007-01-22 05:43 PM


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


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