2 Replies Latest reply on Jan 21, 2013 8:38 AM by D. L

    ReplaceReference Method (ISwDMDocument) not work correctly

    D. L

      good morning everyone,

       

      i have a problem with the replace function of the document manager api.

       

      i use the the following code for replacing references:

       

        public static void SetReferences(SWDocument document)

              {

                  _factory =

                      (SwDMClassFactory)

                      Activator.CreateInstance(Type.GetTypeFromProgID("SwDocumentMgr.SwDMClassFactory"));

       

       

                  if (_factory != null)

                      _application =

                          (ISwDMApplication3)_factory.GetApplication("42804944AF393A4E8DA9890ABBC6F7D0D74390EEE2C65689");

       

       

                  if (_factory == null || _application == null)

                      return;

       

       

                      _document = (ISwDMDocument13)_application.GetDocument(document.Destination, _type, false, out _errors);

       

       

              

                  if (_document == null)

                      return;

       

       

                  _application.GetSearchOptionObject().ClearAllSearchPaths();

                  var r = _document.GetAllExternalReferences(_application.GetSearchOptionObject());

       

       

                  if (r == null)

                  {

                      foreach (var result in document.Children)

                      {

                          _document.ReplaceReference(result.Source, result.Destination);

                      }

                  }

                  else

                  {

                      foreach (var result in (new List<string>(r)))

                      {

                          var find = document.Children.Find(x => x.Source.ToLower() == result.ToLower() || x.Destination.ToLower() == result.ToLower());

       

       

                          if (find == null)

                              continue;

       

       

                          _document.ReplaceReference(result, find.Destination);

                      }

                  }

       

                  _document.Save();

       

                  _factory = null;

                  _application = null;

                  _document = null;

              }

       

      when i tried to replace a reference on a sw part then it works correctly. but when i try to replace a din part reference it not work.

       

      ..\SolidWorks Data\browser\DIN\bolts and screws\socket set screw cone point_din.sldprt (original reference)

       

      should replace to

       

      ..\Temp\temp_socket set screw cone point_din

       

      it is the same part but with different filename.

       

      can anyone help me?

       

      thanks

       

      daniel