2 Replies Latest reply on Jul 30, 2018 7:10 AM by Deepak Gupta

    VBA - Update Custom Property Template

    Josh Kimberlin

      Long time reader, first time poster.

       

      Is it possible to use VBA to select the custom property template for a part or assembly? I have a macro that opens all the parts in a folder, uses information from a userform and dissects the "Save As" name to automatically fill out 80% of our custom properties, rebuilds, and then closes the file. If we ever "steal" a design from another job we have done, there is a chance that the custom property template might not be correct for the current job. I want to keep our guys from having to change each individual template from the drop down for each part.

       

      Thanks.

      Untitled.png

        • Re: VBA - Update Custom Property Template
          Derek Harrington

          Josh,

           

          I understand your question and have faced the same challenge.  To my knowledge,  you could not access the custom property template through the API until 2018.  I have actually implemented a macro just recently that solves this issue. I had some API support that helped me find this new command. I was searching in 2017, but I could not find.

           

          Solution:

          1. Make sure you have the 2018 SOLIDWORKS object libraries referenced.

          2. Dim and Set objects etc as follows (object names are arbitrary)

          3. Implement the 2018 command to change the template file

          -------------------

          Dim swApp As SldWorks.SldWorks

          Dim swModel As ModelDoc2

          Dim swModelExtension As ModelDocExtension

          --------------------------

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc (or other technique to access the part or assy doc)

          Set swModelExtenstion = swModel.Extension

           

          Now you can access  and change the custom property template file.  I found it necessary to set the template to "-None-" and then re-select the desired template. This new selection can be done via custom drop down userform. I created one that loads all our custom property templates in to a drop down for the user to select. The routine then drills through the open assembly via recursion and forces the new template to parts and assemblies per the drop down selection.

           

          The ( ) parameter is to be (True) for weldment parts, and (False) if not.

           

          swModelExtension.CustomPropertyBuilderTemplate(False) = "-None-"

          swModelExtension.CustomPropertyBuilderTemplate(False) = "template.prtprp" (your template file name here for parts)

          swModelExtension.CustomPropertyBuilderTemplate(False) = "template.asmprp" (your template file name here for assemblies)

           

          Capture.JPG

           

          Hope this helps. It has been a great solution for us.

           

           

          Thanks,