7 Replies Latest reply on Aug 9, 2018 12:03 PM by Danniel Sims

    Find broken file references

    Patrick Reinke

      Hi community,

       

      I wanna fix broken file references in SolidWorks and I allready found a solution, but unfortunately my solution is highly unperformant.

      The Problem is, I need to activate every SW-Configuration and check if there are supressed components. If there are, I need to de a second check if these supressed components exists like this: File.Exists(filePath). Then I can be sure, that this file reference is broken or not.

      See for my solution in the following screenshot:

      unloadedComponents.JPG

       

      I allready tryed ListExternalFileReferences, but this method didnt find the references I am looking for. Beside GetUnloadedComponentNames, isnt there another solution to find broken references over the hole document as a list or something like that, without switching every configuration?

       

      Greeting Patrick

        • Re: Find broken file references
          Danniel Sims

          Try GetDependencies2 Method

          You can apply your FileExists method to all the files to return bad filepaths or write false returns to a list.

          I'm not sure how this works with configurations though.

           

          value = instance.GetDependencies2(Traverseflag, Searchflag, AddReadOnlyInfo)

           

          Parameters

          Traverseflag

          True to traverse down into all dependent files, false for only the highest level within the dependencies

          Searchflag

          True to use the search rules to find dependencies, false to look where the documents were last saved

          AddReadOnlyInfo

          True  to show read-only information in the returned strings, false to not

           

           

          Calling this method on a drawing document returns a list of all the parts and assemblies used in the drawing. If you set Traverseflag to True, then each of the parts within the assembly file is also returned in this array of strings.

          Because a derived mirror part is generated from another part, the list of model dependencies returned by this method would include the original part used to generate the derived mirror part.

          Library features are completely unassociated. They do not require the library nor do they update when changes are made to the library feature. Therefore, this method does not return library features.

          If you use this method with an assembly that contains two documents, Part1 and SubAssem1, an example of what might be returned is:

          [ "Part1", "C:\temp\Part1.SLDPRT", "SubAssem1", "c:\temp\SubAssem1.SLDASM" ]

          If Traverseflag is set to True, then all the documents contained in SubAssem1.ASM are returned. Also, suppressed components are recognized and returned by this method as a dependent file.

          If AddReadOnlyInfo is set to True, then a string of True or false is added to the list of strings. If Part1 is read-only, then the resulting set of strings would be:

          [ "Part1", "C:\temp\Part1.SLDPRT", "True", "SubAssem1", "c:\temp\SubAssem1.SLDASM", "" ]

           

          NOTE: For assemblies containing suppressed or lightweight components, file references (return value from this method) point to the as-saved component reference because the actual component has not been loaded into memory. Because the suppressed and lightweight components have not actually been loaded, the current search criteria has not been applied to update the file references. Setting Searchflag to True vs. false, causes this method to apply the current search criteria rules to locate the particular reference and may result in a different return value. Likewise, unsuppressing or resolving these components causes the current search criteria to be applied and updates the assembly's component references in memory, if necessary.

           

          When calling this method with Seachflag set to True, you can explicitly set the search folders first. This is important because this method uses the current SOLIDWORKS directory as its second search criteria. Because the user may have interactively opened files from some random directory, you cannot be certain the current SOLIDWORKS directory is pointing to the desired location. You may want to consider setting the search folders to that of the document being used in this method.

          • Re: Find broken file references
            Victor Frauenfeld

            Hello guys, I am wondering if you would be willing to share your method (macro) of finding broken file references. I have been wanting to do this to our SolidWorks files for a little while now and I am not familiar with programming / api stuff. When I look at your conversation here, it looks like a foreign language to me.

             

            I would greatly appreciate any assistance you would be willing to share. Thank you. 

             

            On a similar note, I am thinking about learning how to do the programming / api stuff, but do not know where to start. would you be willing to give pointers on how you guys learned this stuff? Did you go to school for it? Did you just take some classes? Etc.