ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
CVCorey Vantilborg06/07/2011

All,

   This is something I have struggled with before and just figured out.  Maybe others always knew how to do this but I didn't.

   If you need to read the material list from a .sldmat file, the first thing to know is that is actually a .xml file. With that in mind I found the following bit of code can read the .sldmat file for a list of materials avalible.

        Try
            Dim XMLD As XmlDocument
            Dim nodelist As XmlNodeList
            Dim node As XmlNode
            XMLD = New XmlDocument
            'Add Namespace
            Dim nsmgr As New XmlNamespaceManager(XMLD.NameTable)
            nsmgr.AddNamespace("mstns", "http://www.solidworks.com/sldmaterials")
            'Load document
            XMLD.Load("tigercat materials.sldmat")
            nodelist = XMLD.SelectNodes("/mstns:materials/classification/material", nsmgr)
            For Each node In nodelist
                Dim materialname As String = node.Attributes.GetNamedItem("name").Value
                Debug.Print("Name of material :" & materialname)
            Next
        Catch ex As Exception
            Debug.Print(ex.ToString)
        End Try

  If anyone has any advice on how to simplify that or a better method please chime in.

Corey V