Hi,
I have seen some post complaining on the impossibility to sort the material database by name.
As I'm learning the c# I've make a little code to sort the database that I want to share with you.
It seems to work correctly but the process is kind of wanky. (you have to rename files extensions )
Be sure to make a BACKUP before testing as I'm a noob developer. And to leave a feedback on what could I improve.
Tanks
Ps the code :
<p>using System.Linq;</p><p>using System.Xml.Linq;</p><p></p><p></p><p>namespace SortXlm</p><p>{</p><p>class Program</p><p>{</p><p>static void Main(string[] args)</p><p>{</p><p>//Open the xml doc</p><p>XDocument doc = XDocument.Load("C:\\\\NAME OF THE BASE.XML");</p><p>//you have to change the extention of the material batabase from .sldmat to .xml (MAKE BACKUP!)</p><p></p><p></p><p>//sort the stuff</p><p>SortByName(doc.Root);</p><p></p><p></p><p>//save xml in another file</p><p>doc.Save("C:\\\\NEW SORTED XML.xml");</p><p>//you have to change the extention of the material batabase from .xml to .sldmat and put the file in the library directory</p><p>}</p><p></p><p></p><p>static void SortByName(XContainer container)</p><p></p><p>{</p><p>container.ReplaceNodes(</p><p>from childEl in container.Elements()</p><p>orderby childEl.Attributes("name").Select(a => a.Value).FirstOrDefault()</p><p>select childEl</p><p>);</p><p></p><p></p><p>foreach (XElement childEl in container.Elements().Where(e => e.HasElements))</p><p>{</p><p>if (childEl.Name == "classification" || childEl.Name == "material")</p><p>{</p><p>SortByName(childEl);</p><p>}</p><p>}</p><p>}</p><p>}</p><p>}</p>SolidworksApi/macros