2 Replies Latest reply on Apr 24, 2015 8:38 AM by Michael Garvelink

    How do I get the 'Category' that my selected material is part of?

    Michael Garvelink

      Along with SolidWorks, we use CAMWorks. I am trying to automate the material selection used in CAMWorks, which is really more of a grouping of different speeds, feeds and tool choices which will be applied to the cutter path.

       

      The idea is to make sort of an Alias list, driven by the Category that is shown on a material form, which also the 'folder' that the material is in (theoretically anyway). Anyway, if I could somehow get either the Category or the 'folder name' that my already selected material is in, would be enough to get me started, but I cannot seem to find API tools that extract anything other that the name of the material database and the material itself, with the exception of parsing an XML file, similar to what was done here - Re: How to get Custom Material Properties?

       

      Now, I can still do an 'Alias List' based on the material name, but it seems more manageable to look at 12-14 Categories than to look at 100's of materials, but if that is the best option, then so be it.

      But I am wondering, is there a simpler way?

       

       

      I have included a screen shot of the specific piece I am looking for -

        • Re: How do I get the 'Category' that my selected material is part of?
          Keith Rice

          You have to use an XML parser on the .sldmat file that contains your materials database.

           

          Specifically, that value is stated in the "name" attribute of the "classification" element. For example, below is a very truncated version of the default .sldmat file. You can see starting element for steel materials on line 9.

           

          <?xml version="1.0" encoding="utf-16"?>
          <mstns:materials xmlns:mstns="http://www.solidworks.com/sldmaterials" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.solidworks.com/sldmaterials E:\Temp\sldmaterials.xsd" xmlns:sldcolorswatch="http://www.solidworks.com/sldcolorswatch" version="2008.03">
            <curves id="curve0">
              <point x="1.0" y="1.0" />
              <point x="2.0" y="1.0" />
              <point x="3.0" y="1.0" />
            </curves>
            <classification name="Steel">
              <material name="1023 Carbon Steel Sheet (SS)" matid="82" envdata="1" appdata="Material Financial Impact data is based on bulk raw material price computed from 1. MetalPrices.com (2012). Accessed May 15th, 2012, from http://www.metalprices.com/">
                <physicalproperties>
                  <EX displayname="Elastic modulus" value="204999998381.838750" />
                  <NUXY displayname="Poisson's ratio" value="0.290000" />
                  <GXY displayname="Shear modulus" value="79999999873.016876" />
                  <ALPX displayname="Thermal expansion coefficient" value="0.000012" />
                  <DENS displayname="Mass density" value="7858.000032" />
                  <KX displayname="Thermal conductivity" value="52.000000" />
                  <C displayname="Specific heat" value="486.000000" />
                  <SIGXT displayname="Tensile strength" value="425000003.203703" />
                  <SIGYLD displayname="Yield strength" value="282685049.019888" />
                  <RK displayname="Hardening factor (0.0-1.0; 0.0=isotropic; 1.0=kinematic)" value="0.850000" />
                  <materialmodel name="Material Model Name" type="4" />
                  <materialcurve id="1000" name="Stress Strain curve" type="100">
                    <data points="0.0014 2.8268505e+008" />
                    <data points="0.004 2.9992194e+008" />
                    <data points="0.005 3.0336932e+008" />
                    <data points="0.006 3.1371146e+008" />
                    <data points="0.007 3.2060621e+008" />
                    <data points="0.008 3.2405359e+008" />
                    <data points="0.009 3.3094835e+008" />
                    <data points="0.01 3.3439573e+008" />
                    <data points="0.012 3.3784311e+008" />
                    <data points="0.016 3.5852738e+008" />
                    <data points="0.02 3.7231689e+008" />
                  </materialcurve>
                </physicalproperties>
                <shaders>
                  <pwshader2 path="\metal\steel\matte steel.p2m" name="matte steel" isNewShader="1" />
                  <cgshader2 name="defaultplastic" />
                </shaders>
                <xhatch name="ANSI32 (Steel)" angle="0.0" scale="1.0" />
                <custom>
                  <prop name="Financial Impact" description="" value="0.436" units="USD/kg" />
                </custom>
              </material>
              <material name="201 Annealed Stainless Steel (SS)" matid="83" envdata="1" appdata="Material Financial Impact data is based on bulk raw material price computed from 1. MetalPrices.com (2012). Accessed May 15th, 2012, from http://www.metalprices.com/">
                <physicalproperties>
                  <EX displayname="Elastic modulus" value="207000000000.000000" />
                  <NUXY displayname="Poisson's ratio" value="0.270000" />
                  <ALPX displayname="Thermal expansion coefficient" value="0.000017" />
                  <DENS displayname="Mass density" value="7859.999900" />
                  <KX displayname="Thermal conductivity" value="16.300000" />
                  <C displayname="Specific heat" value="501.999980" />
                  <SIGXT displayname="Tensile strength" value="685000000.000000" />
                  <SIGYLD displayname="Yield strength" value="292000000.000000" />
                  <RK displayname="Hardening factor (0.0-1.0; 0.0=isotropic; 1.0=kinematic)" value="0.850000" />
                  <materialmodel name="Material Model Name" type="4" />
                  <materialcurve id="1000" name="Stress Strain curve" type="100">
                    <data points="0.0014 2.8957981e+008" />
                    <data points="0.003 3.1715884e+008" />
                    <data points="0.004 3.4473786e+008" />
                    <data points="0.005 3.5852738e+008" />
                    <data points="0.006 3.5862738e+008" />
                    <data points="0.007 3.6542214e+008" />
                    <data points="0.008 3.6572214e+008" />
                    <data points="0.009 3.6886952e+008" />
                    <data points="0.01 3.7231689e+008" />
                    <data points="0.012 3.8610641e+008" />
                    <data points="0.013 3.9989592e+008" />
                  </materialcurve>
                </physicalproperties>
                <shaders>
                  <pwshader2 path="\metal\steel\satin finish stainless steel.p2m" name="satin finish stainless steel" isNewShader="1" />
                  <cgshader2 name="defaultplastic" />
                </shaders>
                <xhatch name="ANSI32 (Steel)" angle="0.0" scale="1.0" />
                <custom>
                  <prop name="Financial Impact" description="" value="3.815" units="USD/kg" />
                </custom>
              </material>
            </classification>
          </mstns:materials>
          

           

          Since you're a premium member at my web site, just email me and I will send you a VBA macro that can help you get started. If you're using .NET then you can use the XMLReader class.

           

          Keith

          SolidWorks API Training

          • Re: How do I get the 'Category' that my selected material is part of?
            Michael Garvelink

            Awesome!

             

            I'll put together an email later today with some more details.

             

            Thanks Keith