AnsweredAssumed Answered

find replace feature name macro

Question asked by Erik Rotolo on Feb 16, 2020
Latest reply on Mar 13, 2020 by Erik Rotolo

MembersDeepak Gupta Alex Burnett Josh Brady that helped from one of my previous posts https://forum.solidworks.com/message/835939?commentID=835939#comment-835939 )

 

Kowshik Islam / Kowshik Islam Eit Cswp maybe you can help?

 

How do I change that macro (also below)  from find replace config names to find replace feature names?

Thanks

 

 

Dim swApp As SldWorks.SldWorks
Sub main()

 

    Set swApp = Application.SldWorks
    Dim swModel As SldWorks.ModelDoc2

 

    Set swModel = swApp.ActiveDoc

 

    Dim CurrentName As String
    Dim ModifiedName As String
    
    Dim vRet As Variant
    vRet = swModel.GetConfigurationNames
    
    
    Dim SearchStr As String
    Dim ReplaceStr As String
    
    SearchStr = InputBox("Find string in config name:", "Find string", "")
        If SearchStr = "" Then MsgBox "String cannot be blank": Exit Sub
    ReplaceStr = InputBox("Replace with:", "Replace string", "")
        If ReplaceStr = "" Then MsgBox "String cannot be blank": Exit Sub
    
    If MsgBox("Replace: '" & SearchStr & "' with: '" & ReplaceStr & "' ?", vbYesNo + vbQuestion) <> vbYes Then Exit Sub
    
    Dim strBld As String
    strBld = ""
    
    Dim swCfg As Configuration
    
    Dim renameCount As Integer
    Dim failCount As Integer
    Dim totalCount As Integer
    
    For i = 0 To UBound(vRet)
        totalCount = totalCount + 1
        
        ModifiedName = Replace(vRet(i), SearchStr, ReplaceStr, 1, -1, vbTextCompare)
        
        If ModifiedName <> vRet(i) Then
            Set swCfg = swModel.GetConfigurationByName(vRet(i))
            swCfg.Name = ModifiedName
        
            If swCfg.Name <> ModifiedName Then
                failCount = failCount + 1
                strBld = strBld & swCfg.Name & vbNewLine
            Else
                renameCount = renameCount + 1
            End If
        End If
    Next i
    
    If failCount > 0 Then
        MsgBox (failCount & "/" & totalCount & " failed to rename:" & vbNewLine & strBld)
    End If
    
    
    MsgBox (renameCount & "/" & totalCount & " configurations renamed")
        
    

 

End Sub

Outcomes