2 Replies Latest reply on Feb 16, 2018 3:41 PM by Jacob Corder

    Get current file path from old file path

    Jana Fischer

      I have an assembly with some subcomponents. The assembly was created locally on another computer, and now I have that assembly on my computer (where the file/folder structure is different). One of the subcomponents is suppressed. If I right-click on that subcomponent and choose "component properties", in the field "model document path" there is the old path from the computer where the component was originally created. That path does not exist on my computer. But if I unsuppress the component, SolidWorks still find the file (in a different path, of course). It also stores the new file path in the component properties.

       

      So in order to find the file, SolidWorks must have done a search.

       

      Is there an API method that does this search? A method that takes a string (old file path) as argument* and returns a string (new file path)?

       

      *and possibly some more arguments

        • Re: Get current file path from old file path
          Jonathan Westcott

          Jana,

           

          I think that the reason the file was found was because after SolidWorks looked in the original location and didn't find the file, it then looked in the directory of the assembly, and failing that looked in your search paths specified in System Options>File Locations>Search Paths.

           

          If it didn't find the file then I think it would have then asked you to either manually find or suppress the item again.

           

          You may not need the API hear as you could just specify search paths, depending on how complex your directory structures are.

          The easiest way is to make directory structures consistent across machines.

           

          Not sure if this helps.

            • Re: Get current file path from old file path
              Jacob Corder

              you have to write your own, but you can execute a find file when solidworks fires a notification of

              AddHandler ISwApp.ReferenceNotFoundNotify, AddressOf Me.SldWorks_ReferenceNotFoundNotify

               

               

               

               

                  Function SldWorks_ReferenceNotFoundNotify(ByVal CurrentPath As String) As Integer

                      Try

                          Dim InvalidChars() As Char = Path.GetInvalidPathChars

                          If IsNothing(InvalidChars) = False Then

                              For i = 0 To UBound(InvalidChars)

                                  If CurrentPath.Contains(InvalidChars(i).ToString) Then

                                      Return 0

                                  End If

                              Next

                          End If

                          Dim InvalidFileChars() As Char = Path.GetInvalidFileNameChars

                          Dim FName As String = Path.GetFileName(CurrentPath)

                          For i = 0 To UBound(InvalidFileChars)

                              If FName.Contains(InvalidFileChars(i).ToString) Then

                                  Return 0

                              End If

                          Next

                          Dim FileNameOut As String = 'Execute some way of finding the file, My addin uses enterprise pdm searching to locate the files

                          If Len(Trim(FileNameOut)) > 0 Then

                              ISwApp.SetMissingReferencePathName(FileNameOut)

                              Return -1

                          End If

                      Catch ex As Exception

                          ISwApp.SendMsgToUser2("Error Happened at 'Sldworks_ReferenceFoundNotNotify', Notify Administrator. Error = " & ex.Message, swMessageBoxIcon_e.swMbWarning, swMessageBoxBtn_e.swMbOk)

                      End Try

                      Return DocumentEventHandler.SOK

                  End Function