几何尺寸与公差论坛

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

【转帖】renaming component in an assembly

[复制链接]
发表于 2009-4-12 22:13:50 | 显示全部楼层 |阅读模式
renaming component in an assembly
i downloaded the code below from the solidworks site.is it possible to add a form to prompt user for the "new name" ? also, this code renames all the components in the assembly.is it possible to rename only the selected component?
option explicit
const swextrefupdatecompnames as long = 18
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc
dim swassy as sldworks.assemblydoc
dim swconfig as sldworks.configuration
dim swrootcomp as sldworks.component
dim children as variant
dim swchild as sldworks.component
dim childcount as integer
dim oldname as string
dim newname as string
dim boldsetting as boolean
dim bret as boolean
dim i as long
set swapp = createobject("sldworks.application")
set swassy = swapp.activedoc
set swconfig = swassy.getactiveconfiguration
set swrootcomp = swconfig.getrootcomponent
boldsetting = swapp.getuserpreferencetoggle(swextrefupdatecompnames)
swapp.setuserpreferencetoggle swextrefupdatecompnames, false
children = swrootcomp.getchildren
childcount = ubound(children)
for i = 0 to childcount
set swchild = children(i)
' changing component name requires component to be selected
bret = swchild.select(false)
oldname = swchild.name2
newname = " ph08000"
debug.print "oldname = " + oldname
debug.print "newname = " + newname
debug.print ""
swchild.name2 = newname
next i
swapp.setuserpreferencetoggle swextrefupdatecompnames, boldsetting
end sub
feroz mahomed
windows xp professional sp2
sworks 2009 sp2
nvidia quadro fx1500
to rename a single component, just right-click on it in the feature tree and choose "properties". you can enter a new name there.
to allow the user to enter a name, you can add an inputbox.
oldname = swchild.name2
newname = inputbox("please enter a name for " & oldname, "component name", oldname)
debug.print "oldname = " + oldname
debug.print "newname = " + newname
debug.print ""
i'll get you eh steve, if it's the last thing i dooooo!
josh,
thank you. this works just fine.
feroz mahomed
windows xp professional sp2
sworks 2009 sp2
nvidia quadro fx1500
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 14:45 , Processed in 0.038300 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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