12 Replies Latest reply on Nov 11, 2015 10:49 AM by Ed Cyganik

    Edit Custom Property of a Drawing without opening it

    Damien Mallard

      Hi,

       

      I See this thread

      How to get the file custom property from a drawing doc without SW openning it ?

      It is interesting but what i want is to edit with my app developed in VB.Net to Edit some Custom Property without opening it in SW to save time on Execution At this Time I Work with this

      Function EditDrawingProperties(DrawingToEdit As String)
          Dim swDocSpecification As SldWorks.DocumentSpecification = swApp.GetOpenDocSpec(DrawingToEdit)
          swDocSpecification.Silent = True : swDocSpecification.ReadOnly = False : swApp.OpenDoc7(swDocSpecification)
          Dim Drawing As DrawingDoc = swApp.ActiveDoc
          Dim swModel As ModelDoc2 = swApp.ActiveDoc
          Dim swModelDocExt As ModelDocExtension = swModel.Extension
          Dim swCustProp As CustomPropertyManager = swModelDocExt.CustomPropertyManager("")
          swCustProp.Add3("LBM_DWG", 30, Regex.Match(DrawingToEdit, "N°([0-9]+)-0.SLDDRW", RegexOptions.IgnoreCase).Groups(1).Value, 2)
          swCustProp.Add3("LBM_REV", 30, 0, 2)
          swCustProp.Add3("LBM_REV1", 30, 0, 2)
          swCustProp.Add3("LBM_DATE1", 30, Dateddmmyy, 2)
          swCustProp.Add3("LBM_MEMO1", 30, "First Issue", 2)
          swCustProp.Add3("LBM_ISSUED1", 30, User(), 2)
          swCustProp.Add3("LBM_PROJECT", 30, DrawingToEdit.Split(New Char() {"\"c})(5), 2)
          Drawing.ForceRebuild() 'Reconstruction
          Dim fileerror, filewarning As Integer
          swModel.Save3(SwConst.swSaveAsOptions_e.swSaveAsOptions_Silent, fileerror, filewarning)
          swApp.CloseDoc(DrawingToEdit)
          Return Nothing
      End Function
      

      But this take many times when i have 20 drawing and more and each one take a minute to open.

       

      If anyone have an idea

        • Re: Edit Custom Property of a Drawing without opening it
          Deepak Gupta

          You need to use SOLIDWORKS Document Manager for that. And before you can use SDM you need to obtain a key for same.

          • Re: Edit Custom Property of a Drawing without opening it
            Damien Mallard

            Hi found this way and works great

             

            Public stLicenceKey As String = "Your_licence_key"
            Public swClassFactory As SwDocumentMgr.SwDMClassFactory = CType(CreateObject("SwDocumentMgr.SwDMClassFactory"), SwDocumentMgr.SwDMClassFactory)
            Public swDataManager As SwDocumentMgr.SwDMApplication = swClassFactory.GetApplication(stLicenceKey)
            
            Function EditDrawingProperties(DrawingToEdit As String)
                Dim swDmDoc As SwDocumentMgr.ISwDMDocument18 = swDmGetDocument(DrawingToEdit, False) 'Ouverture du document
                'MAJ propriété général
                swDmSetCustomProperty(swDmDoc, "LBM_DWG", Regex.Match(DrawingToEdit, "N°([0-9]+)-0.SLDDRW", RegexOptions.IgnoreCase).Groups(1).Value, SwDocumentMgr.SwDmCustomInfoType.swDmCustomInfoText)
                swDmSetCustomProperty(swDmDoc, "LBM_REV", "0", SwDocumentMgr.SwDmCustomInfoType.swDmCustomInfoText)
                swDmSetCustomProperty(swDmDoc, "LBM_REV1", "0", SwDocumentMgr.SwDmCustomInfoType.swDmCustomInfoText)
                swDmSetCustomProperty(swDmDoc, "LBM_DATE1", Dateddmmyy, SwDocumentMgr.SwDmCustomInfoType.swDmCustomInfoText)
                swDmSetCustomProperty(swDmDoc, "LBM_MEMO1", "First Issue", SwDocumentMgr.SwDmCustomInfoType.swDmCustomInfoText)
                swDmSetCustomProperty(swDmDoc, "LBM_ISSUED1", User(), SwDocumentMgr.SwDmCustomInfoType.swDmCustomInfoText)
                swDmSetCustomProperty(swDmDoc, "LBM_PROJECT", DrawingToEdit.Split(New Char() {"\"c})(5), SwDocumentMgr.SwDmCustomInfoType.swDmCustomInfoText)
                swDmDoc.Save() : swDmDoc.CloseDoc() 'Sauvegarde du document'Fermeture du document
                Return Nothing
            End Function
            

             

            Edit I forget this

            Function swDmGetDocumentTypeByName(ByVal stPath As String) As SwDocumentMgr.SwDmDocumentType
                Try
                    If stPath = "" Then
                        Return SwDocumentMgr.SwDmDocumentType.swDmDocumentUnknown
                    End If
                    Select Case IO.Path.GetExtension(stPath).ToUpper
                        Case ".SLDPRT", ".EPRT", ".PRTDOT", ".SLDLFP", ".PRT"
                            Return SwDocumentMgr.SwDmDocumentType.swDmDocumentPart
                        Case ".SLDASM", ".EASM", ".ASMDOT", ".ASM"
                            Return SwDocumentMgr.SwDmDocumentType.swDmDocumentAssembly
                        Case ".SLDDRW", ".EDRW", ".DRWDOT", ".DRW"
                            Return SwDocumentMgr.SwDmDocumentType.swDmDocumentDrawing
                        Case Else
                            Return SwDocumentMgr.SwDmDocumentType.swDmDocumentUnknown
                    End Select
                Catch ex As Exception
                    Return SwDocumentMgr.SwDmDocumentType.swDmDocumentUnknown
                End Try
            End Function
            Function swDmGetDocument(ByVal stPath As String, Optional ByVal blReadOnly As Boolean = True) As SwDocumentMgr.ISwDMDocument18
                Try
                    Dim oTemp As SwDocumentMgr.SwDMDocument18 = Nothing
                    If Not Exists(stPath) Then 'CORRECTION
                        Throw New ApplicationException("File does not exist : " + stPath)
                    End If
                    Dim oFile As New IO.FileInfo(stPath)
                    If (oFile.Attributes And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then Return Nothing
                    Dim inTypeDoc As SwDocumentMgr.SwDmDocumentType = swDmGetDocumentTypeByName(stPath)
                    Dim inError As SwDocumentMgr.SwDmDocumentOpenError = SwDocumentMgr.SwDmDocumentOpenError.swDmDocumentOpenErrorFail
                    'Si le document existe d'un type connu
                    If inTypeDoc <> SwDocumentMgr.SwDmDocumentType.swDmDocumentUnknown Then
                        oTemp = CType(swDataManager.GetDocument(stPath, inTypeDoc, blReadOnly, inError), SwDocumentMgr.SwDMDocument18)
                    Else
                        Throw New ApplicationException("Unknown document type : " + stPath)
                    End If
                    ' Return le document
                    If inError = SwDocumentMgr.SwDmDocumentOpenError.swDmDocumentOpenErrorNone Then
                        Return oTemp
                    Else
                        Throw New ApplicationException("Error in open file : " + stPath)
                    End If
                Catch ex As Exception
                    Return Nothing
                End Try
            End Function
            Function swDmSetCustomProperty(ByRef oDocument As SwDocumentMgr.ISwDMDocument18, ByVal stName As String, ByVal stValue As String, ByVal inType As SwDocumentMgr.SwDmCustomInfoType) As Boolean
                Try
                    Dim stCustomProperties() As String = CType(oDocument.GetCustomPropertyNames, String())
                    Dim blPropertyExist As Boolean = False
            
                    If Not stCustomProperties Is Nothing Then
                        For Each stCustomProperty As String In stCustomProperties
                            If stCustomProperty = stName Then
                                blPropertyExist = True
                                Exit For
                            End If
                        Next
                    End If
                    If blPropertyExist Then
                        oDocument.SetCustomProperty(stName, stValue)
                        Return True ' Ajouter un test de verifiaction de modification
                    Else
                        Return oDocument.AddCustomProperty(stName, inType, stValue)
                    End If
                Catch ex As Exception
                    Return False
                End Try
            End Function
            
            • Re: Edit Custom Property of a Drawing without opening it
              Ed Cyganik

              Although you have an answer, I thought I'd mention the following capability that could be used as an alternate method. Also, there may be t some people out there that are unaware as well:

               

              As long as a file is not open in SolidWorks, you can access and modify its custom file properties using Windows Explorer.

              Just RMB select the file and chose "Properties", then select the "Custom" tab.

               

              ...again, just my 2¢,

                                  Eddie