Hallo Cyril,
Ik post al mijn code. Ik heb twee lussen gezet omdat als ik mijn stukken al heb hernoemd, het niet werkte, dus ik hernoem ze eerst met een teller (1,2,3,4...) en daarna hernoem ik ze met de liniaal.
Optie Expliciete
Dim swApp als SldWorks.SldWorks
Dim swModel als SldWorks.ModelDoc2
Dim swRootComp als SldWorks.Component2
Dim Kinderen Als Variant
Dim swChild As SldWorks.Component2
Dim SwSelData als SldWorks.SelectData
Dim ChildCount zo lang
Dim oldName als tekenreeks
Dim newName als tekenreeks
Zon j Zo lang
Zon h Zo lang
Dim ParentName als tekenreeks
Dim foutenHernoem zo lang
Dim status Als Booleaans
Dim waarschuwingen zo lang
Bespaar zo lang
Dim swModelDocExt als ModelDocExtension
Dim swCustProp als CustomPropertyManager
Dim bool als Booleaanse
Dim val als snaar
Dim valout als snaar
Sub hoofd()
Stel swApp = Toepassing.SldWorks in
Stel swModel = swApp.ActiveDoc in
ParentName = Links(swModel.GetTitle, 7)
Stel swRootComp in = swModel.ConfigurationManager.ActiveConfiguration.GetRootComponent3(True)
j = 1
h = 1
TraverseComponent swRootComp, 1
swModel.ForceRebuild3 Waar
status = swModel.Save3(swSaveAsOptions_SaveReferenced, foutenOpslaan, waarschuwingen)
Einde Sub
Sub TraverseComponent(swComp als SldWorks.Component2, nLevel zo lang)
Dim vChildComp als variant
Dim swChildComp als component2
Dim swModelChild As SldWorks.ModelDoc2
Dim swCustProp als CustomPropertyManager
Dim val als snaar
Dim valout als snaar
Zon i Zo lang
Dim status2 Als Booleaans
Dim val1 Als String
Dim valout1 als snaar
vChildComp = swComp.GetChildren
Voor i = 0 TB UBound(vChildComp)
Stel swChildComp in = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
swChildComp.Select4 Onwaar, SwSelData, Onwaar
Stel swModelChild in = swChildComp.GetModelDoc2
Set swCustProp = swModelChild.Extension.CustomPropertyManager("Default") ' zet de naam van de configuratie inclusief de
Zo niet, dan is swCustProp niets
status = swCustProp.Get4("SWOODCP_PanelStockLength", False, val, valout)
status2 = swCustProp.Get4("HARDWARE", Onwaar, val1, valout1)
Als valout <> "" Of valout1 <> "" Dan
newName = h
errorsRename = swModel.Extension.RenameDocument(newName)
Debug.Print swModelChild.GetTitle & " : " & h & " - " & errorsRename
h = h + 1
Einde als
Einde als
volgende i
Voor i = 0 TB UBound(vChildComp)
Stel swChildComp in = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
swChildComp.Select4 Onwaar, SwSelData, Onwaar
Stel swModelChild in = swChildComp.GetModelDoc2
Set swCustProp = swModelChild.Extension.CustomPropertyManager("Default") ' stel de naam van de configuratie in, inclusief de
Zo niet, dan is swCustProp niets
status = swCustProp.Get4("SWOODCP_PanelStockLength", False, val, valout)
status2 = swCustProp.Get4("HARDWARE", Onwaar, val1, valout1)
Als valout <> "" Of valout1 <> "" Dan
newName = Oudernaam & "-000" & j
Als Lin (newName) > 12 dan
newName = Links(nieuweNaam, 8) & Rechts(nieuweNaam, 4)
Einde als
errorsRename = swModel.Extension.RenameDocument(newName)
Debug.Print swModelChild.GetTitle & " : " & j & " - " & errorsRename
j = d + 1
Einde als
Einde als
volgende i
Einde Sub