2 Replies Latest reply on Apr 8, 2013 4:08 AM by Simon Turner

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

    Vincent Li

      Hi Masters,

       

      My I get the file custom properties from a drawing doc without activating this doc by SW , using SW Macro(*.swp)  ??

       

      Preconditions:

       

      The full path of this SW draw doc ?

       

      Regards

      Vincent

        • Re: How to get the file custom property from a drawing doc without SW openning it ?
          Christoph Neundorf

          Vincent,

           

          you could write the properties into a database when checking it into your PDM.

          Then you are able to read the custom properties without opening SW.

           

          I think you can't even run a .swp macro without activating SolidWorks.

           

          You might look here:

          change custom properties without opening file?

          https://forum.solidworks.com/message/189706

           

           

          Regards,

          Christoph

            • Re: How to get the file custom property from a drawing doc without SW openning it ?
              Simon Turner

              Since no-one else is suggesting the obvious - here goes:

              you need to use the SWDocumentMgr API.

              It is free, but you need to obtain a license key for it. This is documented in the API help:

               

              To request a SolidWorks Document Manager API license key:

              1. Log into the SolidWorks customer portal.
              2. Click API Support in My Support.
              3. Click Document Manager key request in step 4.
              4. Follow the online instructions to request your license key.

              A SolidWorks Document Manager API license key is emailed to you upon approval of your request.

               

              Finally:

               

              Function GetProperty(myFile as string, myPropertyName as string) as string

                  Dim myType As Long

                  Dim myClassF As New SwDMClassFactory

                  Dim myApp As SwDMApplication

                  Dim myValue as string

                  Dim i as integer

                  Dim errors as long

               

                  Set myApp = myClassF.GetApplication("license key")

                 

                  myType = swDmDocumentPart

                  If InStr(Lcase(myFile), ".sldasm") > 0 Then myType = swDmDocumentAssembly

                  If InStr(Lcase(myFile), ".slddrw") > 0 Then myType = swDmDocumentDrawing

                 

                  Set myDoc = myApp.GetDocument(myFile, myType, False, errors)

                  If Not myDoc Is Nothing Then

                      myDoc.GetAllCustomPropertyNamesAndValues sa1, sa2, sa3, sa4

                      If IsEmpty(sa1) = False Then

                          For i = 0 To UBound(sa1)

                              If sa1(i) = myPropertyName Then

                                  myValue = sa4(i)

                                  Exit Function

                              End If

                          Next

                      End If

                      myDoc.CloseDoc

                  End If

              End Function