8 Replies Latest reply on Nov 25, 2013 6:01 AM by Nazar Chaykin

    Not working swDoc.Save()

    Nazar Chaykin

      Hello! I get custom property and try to set new custom property, but when I try save the document nothing happened.


      Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


           swCfg.SetCustomProperty("Name", TextBox4.Text)



      End Sub


      But if use SwDoc.SaveAs(C:\1.sldasm) it work greatly.

        • Re: Not working swDoc.Save()
          Simon Turner

          Use Save3 and see what errors or warnings are returned:


          Dim errors as Long

          Dim warnings as Long


          swDoc.Save3 swSaveAsOptions_Silent, errors, warnings


          debug.print errors

          debug.print warnings

            • Re: Not working swDoc.Save()
              Nazar Chaykin

              Sorry, I forgot to clarify that I used Document Management API

                • Re: Not working swDoc.Save()
                  Simon Turner

                  In that case, did you ask for write access to the file when opening it? It will open it read-only by default.

                  Please specify the command you use to open the file.

                    • Re: Not working swDoc.Save()
                      Nazar Chaykin
                      Imports SolidWorks.Interop.swdocumentmgr
                      Public Class Form1
                      Dim swCfgMgr As SwDMConfigurationMgr
                      Dim vCfgNameArr As Object
                      Dim swCfg As SwDMConfiguration
                      Dim swDoc As SwDMDocument
                      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                           Dim swClassFact As SwDMClassFactory
                           Dim swDocMgr As SwDMApplication
                           Dim vCfgName As Object
                           Dim nDocType As Long
                           Dim nRetVal As Long
                              Dim sDocFileName As String = "C:\123.sldasm"
                              ' Determine type of SolidWorks file based on file extension
                              If InStr(LCase(sDocFileName), "sldprt") > 0 Then
                         nDocType = SwDmDocumentType.swDmDocumentPart
                              ElseIf InStr(LCase(sDocFileName), "sldasm") > 0 Then
                         nDocType = SwDmDocumentType.swDmDocumentAssembly
                              ElseIf InStr(LCase(sDocFileName), "slddrw") > 0 Then
                         nDocType = SwDmDocumentType.swDmDocumentDrawing
                         ' Not a SolidWorks file
                         nDocType = SwDmDocumentType.swDmDocumentUnknown
                         ' So cannot open
                         Exit Sub
                              End If
                              ' Because drawing documents do not have configurations, 
                              ' only continue running the project if the document
                              ' is a part or assembly document
                              If (nDocType <> SwDmDocumentType.swDmDocumentDrawing) Then
                         swClassFact = CreateObject("SwDocumentMgr.SwDMClassFactory")
                         swDocMgr = swClassFact.GetApplication(sLicenseKey)
                         swDoc = swDocMgr.GetDocument(sDocFileName, nDocType, True, nRetVal) : Debug.Assert(SwDmDocumentOpenError.swDmDocumentOpenErrorNone = nRetVal)
                         swCfgMgr = swDoc.ConfigurationManager
                         TextBox1.Text = swDoc.Title 'наименование
                            vCfgNameArr = swCfgMgr.GetConfigurationNames
                         For Each vCfgName In vCfgNameArr
                             swCfg = swCfgMgr.GetConfigurationByName(vCfgName)
                             TextBox2.Text = swCfg.GetCustomProperty("Name", 30)  'Сборка1_ФБ
                              End If
                      End Sub
                      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
                           swCfg.SetCustomProperty("Name", TextBox2.Text)
                      End Sub
                      End Class