AnsweredAssumed Answered

swModel.Extension.RenameDocument not working properly

Question asked by Michael Chamerski on May 29, 2017
Latest reply on Jun 20, 2017 by Michael Chamerski

Hi all -

 

I'm in a dilemma here. I ran a piece of code that worked flawlessly and renamed components and configurations in assemblies. As soon as I added another segment to unsuppress all features, the entire thing stopped working. I removed the portion I added, and to my surprise (or the lack thereof), the script still wasn't working properly. I'm not receiving any errors, and the Replace function seems to be working just fine (swModel.GetTitle properly obtains document title, but swModel.Extension.RenameDocument fails to do anything). Would greatly appreciate some guidance!

 

Function configRename(swModel As SldWorks.ModelDoc2) As Boolean

 

  ' Declare variables path, FileName, and Description to default state String

    Dim path As String, FileName As String, FileOld As String, Description As String

 

    Dim ConfigName As String

    Dim ConfigOld As String

 

    FileOld = swModel.GetTitle

    ' swApp.SendMsgToUser(FileOld)

 

    FileName = Replace(FileOld, "@", "(a)")

    FileName = Replace(FileName, "<", "(")

    FileName = Replace(FileName, ">", ")")

    FileName = Replace(FileName, "$", "(S)")

    FileName = Replace(FileName, "%", "_")

    FileName = Replace(FileName, "\", "_")

    FileName = Replace(FileName, "*", "_")

    FileName = Replace(FileName, ":", "_")

    FileName = Replace(FileName, Chr(34), Chr(34) + " (2x ')")

    FileName = Replace(FileName, "?", "_")

    FileName = Replace(FileName, "|", "_")

    FileName = Replace(FileName, ",", "_")

    FileName = Replace(FileName, "{", "(")

    FileName = Replace(FileName, "}", ")")

    FileName = Replace(FileName, "#", "(_)")

    FileName = Replace(FileName, "&", "_")

 

        ' swApp.SendMsgToUser (FileName)

    swModel.Extension.RenameDocument FileName

    

    If FileName = FileOld Then

        'Do nothing.

    Else

        ModCount = ModCount + 1

    End If

 

swModel.ForceRebuild3 True

 

You can see I commented out some debugging lines. When running these, I get the following:

swApp.SendMsgToUser (FileOld) ---> "MT1_Test_{1}"

swApp.SendMsgToUser (FileName) ---> "MT1_Test_(1)"

 

As you can see, FileName is the proper result I'm looking for, but after running the entire macro I'm still left with "{1}" rather than "(1)". For whatever reason this worked  a couple hours ago. Now I can't wrap my head around it anymore. I've attached the entire script I have (yes it's a mess at the moment).

 

Thanks in advance

 

Michael

Attachments

Outcomes