8 Replies Latest reply on Aug 28, 2018 2:10 PM by Tracy Bai

    API, VBA, material category

    Tracy Bai

      Hello All,

      I am new to SWX API. Here is my question:

      Is it possible to get the name of "Category" , see highlighted in YELLOW, the result should be "PE"?

      I have gone through all similar posts here, however, none of them could pull the name of "Category".

       

      PS I am using SWX 2015.

       

      Thank you so much in advance.

      Best regards,

      Tracy

        • Re: API, VBA, material category
          Alex Burnett

          Hello, I had to dig back a bit because I remember this getting asked previously. The short answer is that it's not directly accessible with the API as it sits. However, you can access it if you don't mind writing extra code to do so. See the linked thread for more detail.

           

          Getting material category

          • Re: API, VBA, material category
            Tracy Bai

            Thank you, Alex, for your reply.

            I did read the post and relevant posts too. Your code, I would assume, was written in C. Unfortunately, my company's machine can not run C. Therefore, I did not try  your code.

             

            Best regards,

            Tracy

            • Re: API, VBA, material category
              Jim Sculley

              Use GetMaterialPropertyName() to get the name of the material and the database where it is located.  Once you have the database path, you can open the database directly (it is an XML file) and then get the category from there.

                • Re: API, VBA, material category
                  Tracy Bai

                  Thank you so much Jim for your suggestion. I got what I need now base on Joe's code posted on How to read items from a material database?

                  but I have some questions

                  1, do I have to deal with an XML file when tracing back to the category?

                  2. is the xxx.sldmat file an XML file? how to open it to verify (could not open through SWX) ?

                  3. Joe's code directly open a database in .sldmat format, although he suggested to save .sldmat as .xml.  I did load the database as a sldmat file, and it worked. Not sure if an XML file is necessary? Perhaps, our database file was written as an XML.

                   

                  Best regards,

                  Tracy

                    • Re: API, VBA, material category
                      Jim Sculley

                      Tracy Bai wrote:

                       

                      Thank you so much Jim for your suggestion. I got what I need now base on Joe's code posted on How to read items from a material database?

                      but I have some questions

                      1, do I have to deal with an XML file when tracing back to the category?

                      Yes.  The category (which is called 'classification' in the database file) is only accessible by reading the XML file.  The best way to access this information is to use the XML related functions as Joe's code does.

                       

                      2. is the xxx.sldmat file an XML file? how to open it to verify (could not open through SWX) ?

                       

                      Yes, the material database file is an XML file.  It just doesn't have the '.xml' file extension.  If you want to look at it, you can open it with any text editor.  There is also a XML Schema Definition file (.xsd) that describes what a properly structured SOLIDWORKS material database file should look like.  You can find that in the data/xmlschema folder under your SOLIDWORKS installation.

                       

                       

                      3. Joe's code directly open a database in .sldmat format, although he suggested to save .sldmat as .xml. I did load the database as a sldmat file, and it worked. Not sure if an XML file is necessary? Perhaps, our database file was written as an XML.

                       

                      The file extension (.sldmat or .xml) is not relevant.  The posted code uses the Load function of the MSXML2.DomDocument object which will load the file as XML, regardless of what the file extension is.  If the file isn't valid XML, the call to Load will most likely fail.