4 Replies Latest reply on Jun 6, 2017 2:06 AM by Deepak Gupta

    GetCustomProperties Silently

    Darren Smith

      Can anybody help????

       

      I have the following macro:

       

      Public Function GetCustomProperties()
          Dim FileError As Long

          Dim FileWarning As Long

          Set swApp = Application.SldWorks

          swApp.DocumentVisible False, swDocumentTypes_e.swDocPART

          Set oDoc = swApp.OpenDoc6("C:\Test.sldprt", swDocPART, swOpenDocOptions_Silent, "", FileError, FileWarning)

          PartType = oDoc.GetCustomInfoValue("", "Part: Type")

          PartMaterial = oDoc.GetCustomInfoValue("", "Part: Material")

          Description = oDoc.GetCustomInfoValue("", "Part: Description")

          swApp.DocumentVisible True, swDocumentTypes_e.swDocPART
      End Function

       

      I need to open the part "Silently" and get the part Type, Material & Description. I have attached a sample part.

       

      However the macro does not work. Has anybody got any idea what I am doing wrong?

       

      Many thanks in advance!!!!

      Darren

        • Re:  GetCustomProperties Silently
          Peter Kennedy

          Why are you trying to get the custom properties, I guess how will the macro to know what file to open?

           

          I run a macro that will transfer the properties from the model into the drawing file, using the following:

           

                      propName = vName

           

                      swCustProp.Get5 propName, False, ValOut, ResolvedValOut, wasResolved

           

                      swCustPropMgr.Add3 propName, swCustomInfoText, ResolvedValOut, swCustomPropertyReplaceValue

          • Re:  GetCustomProperties Silently
            Solid Air

            I ran your code without issue.  How do you know the code is not working?  I see no output.  To access the variables PartType, PartMaterial and Description, they need to be declared in the declarations area of the macro; not inside the function. 

            Have you tried stepping through you code one line at time using F8?

             

            Here is your code with a couple of debug.print statements in it so I can see what is being returned in the immediate window (press ctrl+g to turn on the immediate window if you do not have it active already).

             

            As Peter pointed out, the statement GetCustomInfoValues is obsolete (see SW API help for replacement).

             

            Public Function GetCustomProperties()

             

                Dim FileError As Long

                Dim FileWarning As Long

                Set swApp = Application.SldWorks

                swApp.DocumentVisible False, swDocumentTypes_e.swDocPART

                Set oDoc = swApp.OpenDoc6("C:\Test.sldprt", swDocPART, swOpenDocOptions_Silent, "", FileError, FileWarning)

             

               Debug.Print oDoc.GetTitle

             

                PartType = oDoc.GetCustomInfoValue("", "Part: Type")

                PartMaterial = oDoc.GetCustomInfoValue("", "Part: Material")

                Description = oDoc.GetCustomInfoValue("", "Part: Description")

               

                Debug.Print PartType, PartMaterial, Description

             

                swApp.DocumentVisible True, swDocumentTypes_e.swDocPART

             

            End Function

            • Re:  GetCustomProperties Silently
              VIGNESH NAGARAJAN

              Hi Darren ,

               

              You can make use of this API which will load the model only in the  memory and access all informations.Refer the link for further details.

               

              2015 SOLIDWORKS API Help - GetCustomProperty2 Method (ISwDMDocument17)

              Regards,

              Vignesh

              • Re:  GetCustomProperties Silently
                Deepak Gupta

                If you're on subscription then request for your SW Document Manager key and use the Document Manager API to get the custom properties of the files even without opening them.