3 Replies Latest reply on Jan 15, 2016 4:10 AM by Simon Turner

    Third Party Storage : Persistent ID storage

    Pankaj Bir

      Hi Everyone,

      Any ideas on third party storage.



      Ideally if some one has the experience with storing Persistent IDs using this api functionality.


      I was wanting to save the persistent Ids of faces and edges into the third party storage to simplify the retrieval of  entities.

      However I am unable to access the stream object  through the



      This works only when a particular notification fires "SaveToStorageNotify"


      Also is it necessary to convert the Persistent Id to a string to save it or is there any other simpler way of writing and reading into the storage.

      I do not want to use an external file. Can an XML format work.

      The sample Code for Third Party Storage :

      The sample code does not build with the latest 4.5 Net Framework . The code works with the 2.0 Net Framework.


      When using the working code I am unable to hit the breakpoints during the debug session.


      Also when compiling with the latest  refrences and .Net framework I get the errors listed below :

      Error 2 The command ""%Windir%\Microsoft.NET\Framework64\v2.0.50727\regasm" /codebase "C:\Users\Pankaj.Bir\Desktop\THIRDPARTY\swThirdPartyStorage\ThirdPartyStorage_dotNet\ThirdPartyStorageExample\bin\ThirdPartyStorageExample.dll"" exited with code 100. ThirdPartyStorageExample


      Error 1 Failed to load 'C:\Users\Pankaj.Bir\Desktop\THIRDPARTY\swThirdPartyStorage\ThirdPartyStorage_dotNet\ThirdPartyStorageExample\bin\ThirdPartyStorageExample.dll' because it is not a valid .NET assembly C:\Users\Pankaj.Bir\Desktop\THIRDPARTY\swThirdPartyStorage\ThirdPartyStorage_dotNet\ThirdPartyStorageExample\RegAsm ThirdPartyStorageExample


      If anybody has an updated version of this sample code that runs and debugs without any problems that would be a real help. Or any pointers or tips to make it work.

      Any help will be much appreciated




      Pankaj Bir


      I am working on Solidworks 2016  SP 0.0

      Windows 10  64 bit

        • Re: Third Party Storage : Persistent ID storage
          Simon Turner

          A few things:


          IGet3rdPartyStorage: This works only when a particular notification fires "SaveToStorageNotify"

          True. But you can also use the SWDocumentMgr API, and in particular ISwDMDocument19.Get3rdPartyStorage.


          Since the PersistentID is essentially a list of bytes, you can just store those bytes directly into the Stream. The example given in the API help for the ISwDMDocument19.Get3rdPartyStorage method is very close to what you want:

          Public Sub Write3rdPartyStorageData()


                      Dim pIStream As IStream = Nothing

                      pIStream = swDoc19.Get3rdPartyStorage(txtStorageName.Text, True)

                      If pIStream Is Nothing Then

                          rtbStorage.Text = "Error: " + "Storage " + txtStorageName.Text + " not found"


                      End If

                      Dim strStream As Byte() = Nothing

                      strStream = Encoding.UTF8.GetBytes(rtbStorage.Text)

                      Dim outlength As UInteger = 0

                      pIStream.Write(strStream, CUInt(strStream.Length), outlength)








                  Catch ex As Exception

                      rtbStorage.Text = "Error: " + ex.Message

                  End Try

              End Sub


          Finally, for the .Net 4 bit, it looks like you are trying to register the dll with the .Net 2 regasm tool.

          Try using the one in the C:\Windows\Microsoft.NET\Framework64\v4.0.30319 folder



            • Re: Third Party Storage : Persistent ID storage
              Pankaj Bir

              Hi Simon,

              Thanks for the tips.

              A few questions remain.


              1. Is it possible to programmatically fire the FiletoStorageNotify . ?

              2. Can the DocumentManagerApi be used in  and active session to write to the 3rd party storage of an open

                  Solidworks document.

              3.Does the FileStream object write directly to the third party storage without the need for the streamwriter or streamreader.

                 I presume if either is used then a string conversion becomes necessary.


              I was able to resolve most of the other issues of saving and retrieving using the streamreader and streamwriter.

              The only issue remaining is to write to the storage without having to wait for the user to save the file.


              Thanks for the reply. Appreciate the help and insights.


              Pankaj Bir

                • Re: Third Party Storage : Persistent ID storage
                  Simon Turner

                  1. Looking at the documentation for IGet3rdPartyStorage: "When a file is fully loaded, you can call this method for reading your data at any time"

                  So you don't need to wait for LoadFromStorageNotify. Just don't use it during FileSaveNotify or FileOpenNotify2.


                  2. If the file is open, use IGet3rdPartyStorage as above.


                  3. Anything that inherits from Stream can be used. However, I would personally convert the persistent ID to a string and use StreamWriter.


                  Hope that helps.