![]() |
【转帖】renaming component in an assembly
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 |
所有的时间均为北京时间。 现在的时间是 04:24 PM. |