Loop through material data base ?

Has anybody ever been successful to loop through a materialdatabase to see what type of materials are all in it ?

If so I could really use some pointers.

Thanks.SolidworksApi macros
Answers 9
SF
SF 2009-01-27 Best Answer
XML parsing is required. I could never be bothered to do it.Just open up the database file with notepad and have a look at thestructure. There is no direct API for this (unless its new to 2009not looked yet)
BG
BG 2009-01-27
Thanks Luke,

The reason why i need it is because I am making a small program tochange material properties for a batch of parts and I wanted todisplay the list of all available types.

I did find a couple of examples of this sort of thing that I willtry.

"I could never be bothered to do it."

You sound like it is a bad idea to do such a thing, may I ask why?
JB
JB 2009-01-27
I don't think he's saying it's a bad thing to do, he justnever needed to do it.
BG
BG 2009-01-27
Yea probably is I just misunderstood him.



I just cannot get it. This is what I found but do to myinexperience am not able to get it to work could somebody lend afew words ?

 


Public articleDoc As New DOMDocument

Private Sub cmdClose_Click()
Unload Me
End Sub

Sub Form_Load()

LoadDocument"C:\Programme\SolidWorks\SolidWorks\lang\english\sldmaterials\solidworksmaterials.sldmat"
Dim sections As IXMLDOMNodeList
Dim ss As IXMLDOMNode
Set ss = articleDoc.childNodes.Item(i)
Set sections = ss.childNodes
SectionsList.Clear
For i = 1 To sections.length - 1
C = sections.Item(i).xml
SectionsList.AddItem sections.Item(i).Attributes.Item(0).nodeValue,x = 1

Next
SectionsList.ListIndex = 0
End Sub

Function LoadDocument(url As String)
articleDoc.async = False
articleDoc.Load url
End Function

The above is the code I have and I keep getting an error on"Set sections = ss.childNodes" if I open material database. If Iopen an actual xml document then I get to "SectionsList.AddItemsections.Item(i).Attributes.Item(0).nodeValue, x = 1 and then iterrors out there.
SF
SF 2009-01-29
I have emails API for some schema and structure documentationon the databases, I will let you know when I hear back.
BG
BG 2009-01-29
Thanks Luke.
BG
BG 2009-08-11
The new LINQ is so easy for this and it works great.
DG
DG 2009-08-11

Ben,

I recently did something like this where I changed the material of couple of parts using the macro. The only thing was that I used same material for all.

BG
BG 2009-08-11
I need a list of materials for a program I am creating so I need to loop through solidworks materials and I think with LINQ it should work pretty good. I want the user to have the same list of materials as he would in solidworks.