1 Reply Latest reply on Jan 24, 2013 5:37 PM by Artem Taturevych

    Issue with replacing references and in SW parts and assemblies ??

    John Laslavic

      I am using SolidWorks 2012 SP4.0 64bit and the API dll's that come with it.

      I have some problems regarding replacing references in SolidWorks parts and assemblies.

      I'm developing an addin whose one function is to rename and re-reference big assemblies. The first operation I do is create a local tree of current Component2 (or ModelDoc2 if the root is a drawing) objects. After that, by traversing that local tree, I do a save-as on ModelDoc2's for each Component2 and replace references to the new ones (different new reference for each current reference). In all cases the files get properly copied to the new locations and their references are properly replaced. The issue I have is that, on some occassions in some assemblies, the new copied Component2 object's getPathName() returns an empty string and it's ModelDoc2 is null (I have setSuppression to resolved added before calling getModelDoc2()). This is mostly happening when a component has instances in different subassemblies in which case everything can be good or one or more Component2 returns an empty path string. The only action that helps when I manually in SolidWorks do "Set Resolved to Lightweight" and then "Set Lightweight to Resolved".

      I have tried the following in the code:

      - setting to lightweight then resolving the component and it's parent, first the parent then the component

      - setting to lightweight then resolving the component and it's parent, first the component then the parent

      - including lightweight-resolve setting to read-only true then false (seemed to help in my other external app reference fixing exe)

      - adding saves and rebuilds to lightweights and resolves

      - traversing the whole tree and doing some or all of the above:

          -- depth first top-down

          -- depth first bottom-up

          -- breadth first top-down

          -- breadth first bottom-up

      - tried to repeat the traverse multiple times

      Nothing seems to help, it behaves differently each time, sometimes it works for all, sometimes it doesn't work for one or more, there is no pattern.

      Any help would be greatly appreciated. Thank you in advance!