Material Property Macro Question
Material Property Macro Question
(OP)
Does anyone have a quick reference on how to extract all the materials from a .sldmat database to populate a pull-down combo-box?
I am working on a small vb program to simplify our routine of entering our usual custom properties for parts. Like most of you, we use a number of custom properties for all our parts like:
Det
Description
Quantity
Finish
Material - which is linked to "SW-Material@Part1.SLDPRT"
I have already explored this site and others looking for a way to populate a pull-down list with all the entries from the sldmaterials.sldmat (or our own database)
There are examples on how to get the path and filename for a database and how to get and set a material property, but I don't know how to get all the materials from a database into a list. There are also examples on creating your own material list, but seems like a duplication of effort.
I realize that this is already built-in functionality, but I'm looking for a one-stop-shop approach. There is probably a simple way if I only knew the key.
I am working on a small vb program to simplify our routine of entering our usual custom properties for parts. Like most of you, we use a number of custom properties for all our parts like:
Det
Description
Quantity
Finish
Material - which is linked to "SW-Material@Part1.SLDPRT"
I have already explored this site and others looking for a way to populate a pull-down list with all the entries from the sldmaterials.sldmat (or our own database)
There are examples on how to get the path and filename for a database and how to get and set a material property, but I don't know how to get all the materials from a database into a list. There are also examples on creating your own material list, but seems like a duplication of effort.
I realize that this is already built-in functionality, but I'm looking for a one-stop-shop approach. There is probably a simple way if I only knew the key.






RE: Material Property Macro Question
Chris
Systems Analyst, I.S.
SolidWorks 06 4.1/PDMWorks 06
AutoCAD 06
ctopher's home (updated 06-21-06)
RE: Material Property Macro Question
Thanks. You're right - no difference except that I'm trying to simplify the process so that we enter all part data in one place.
Maybe my quest is frivolous and the answer is to use just what's stock. I'm obviously not looking for a major performance gain here, just had a few minutes today to look at some of those "Wouldn't it be nice..." things.
My ultimate goal would be to be able to run this macro on a part from inside an assembly, but baby steps...
Elliott Stowe
Mechanical Engineer
Edgewater Automation
RE: Material Property Macro Question
Also, the material dropdown in SW has sub-categories in it, which you can't do with a standard dropdown text box. If you wanted to have all the materials from the standard database you would have to do a lot of scrolling to find your desired material.
One possible solution would be to create a short text file list of your commonly used materials selected from the .sldmat file. You could then load your dropdown box with those values. Even easier, although less preferred, would be to hard-code those string values into the macro. You could still use the SolidWorks API SetMaterialPropertyName2 function to set the selected material to the part. Any uncommon materials not in the dropdown would still have to be set the manual way.
RE: Material Property Macro Question
Chris
Systems Analyst, I.S.
SolidWorks 06 4.1/PDMWorks 06
AutoCAD 06
ctopher's home (updated 06-21-06)
RE: Material Property Macro Question
Thanks for the help. For now, I like handleman's idea for the combobox containing the names of materials we commonly use. As long as the material names match the database file, it should work fine. The only downside is that when adding a material, you'd have to add it two places. Not too bad.
If I get something put together maybe I'll post the results.
Elliott
RE: Material Property Macro Question
Running the macro on a part in an assembly should be no problem at all.
RE: Material Property Macro Question
RE: Material Property Macro Question
You can easily bring the existing materials file into excel and manipulate it to get the text you will need to populate a VB combobox. It took less than 10 minutes for me to get this going. Even though the list is long, I think that rather than restrict yourself to only using some of the materials in your list, you should simply sort them to have the most commonly used ones at the top.
CODE
ComboBox.AddItem "AISI 304"
ComboBox.AddItem "AISI 1020"
ComboBox.AddItem "Alloy Steel"
ComboBox.AddItem "Cast Alloy Steel"
ComboBox.AddItem "Cast Carbon Steel"
ComboBox.AddItem "Cast Stainless Steel"
ComboBox.AddItem "Chrome Stainless Steel"
ComboBox.AddItem "Galvanized Steel"
ComboBox.AddItem "Plain Carbon Steel"
ComboBox.AddItem "Wrought Stainless Steel"
ComboBox.AddItem "Ductile Iron"
ComboBox.AddItem "Gray Cast Iron"
ComboBox.AddItem "Malleable Cast Iron"
ComboBox.AddItem "1060 Alloy"
ComboBox.AddItem "1345 Alloy"
ComboBox.AddItem "1350 Alloy"
ComboBox.AddItem "2014 Alloy"
ComboBox.AddItem "2018 Alloy"
ComboBox.AddItem "2024 Alloy"
ComboBox.AddItem "3003 Alloy"
ComboBox.AddItem "6061 Alloy"
ComboBox.AddItem "7079 Alloy"
ComboBox.AddItem "Duranickel(R) 301"
ComboBox.AddItem "Magnesium Alloy"
ComboBox.AddItem "Monel(R) 400"
ComboBox.AddItem "Aluminum Bronze"
ComboBox.AddItem "Brass"
ComboBox.AddItem "Copper"
ComboBox.AddItem "Leaded Commercial Bronze"
ComboBox.AddItem "Manganese Bronze"
ComboBox.AddItem "Tin Bearing Bronze"
ComboBox.AddItem "Wrought Copper"
ComboBox.AddItem "ABS"
ComboBox.AddItem "ABS PC"
ComboBox.AddItem "Acrylic (Medium-high impact)"
ComboBox.AddItem "Nylon 6/10"
ComboBox.AddItem "PA Type 6"
ComboBox.AddItem "PBT General Purpose"
ComboBox.AddItem "PC High Viscosity"
ComboBox.AddItem "PE High Density"
ComboBox.AddItem "PE Low/Medium Density"
ComboBox.AddItem "POM Acetal Copolymer"
ComboBox.AddItem "PP Copolymer"
ComboBox.AddItem "PS Medium/High Flow"
ComboBox.AddItem "PVC 0.007 Plasticized"
ComboBox.AddItem "PVC Rigid"
ComboBox.AddItem "Perspex (TM) GS Acrylic Cast Sheet"
ComboBox.AddItem "PTFE (general)"
ComboBox.AddItem "Cobalt"
ComboBox.AddItem "Molybdenum"
ComboBox.AddItem "Nickel"
ComboBox.AddItem "Pure Gold"
ComboBox.AddItem "Pure Lead"
ComboBox.AddItem "Pure Silver"
ComboBox.AddItem "Titanium"
ComboBox.AddItem "Tungsten"
ComboBox.AddItem "Vanadium"
ComboBox.AddItem "Zirconium"
ComboBox.AddItem "A-Glass Fiber"
ComboBox.AddItem "C-Glass Fiber"
ComboBox.AddItem "E-Glass Fiber"
ComboBox.AddItem "S-Glass Fiber"
ComboBox.AddItem "Zoltek Panex 33"
ComboBox.AddItem "Hexcel AS4C (3000 Filaments)"
ComboBox.AddItem "Thornel Mat VMA"
ComboBox.AddItem "Thornel VCB-20 Carbon Cloth"
ComboBox.AddItem "Silicon"
ComboBox.AddItem "Silicon Dioxide"
ComboBox.AddItem "Beech"
ComboBox.AddItem "Cedar"
ComboBox.AddItem "Maple"
ComboBox.AddItem "Oak"
ComboBox.AddItem "Pine"
ComboBox.AddItem "Teak"
ComboBox.AddItem "Mahogany"
ComboBox.AddItem "Air"
ComboBox.AddItem "Ceramic Porcelain"
ComboBox.AddItem "Glass"
ComboBox.AddItem "Rubber"
ComboBox.AddItem "Water"
End Sub
Private Sub cmdOK_Click()
Dim swApp As SldWorks.SldWorks
Dim Doc As SldWorks.ModelDoc2
Set swApp = CreateObject("SldWorks.Application")
Set Doc = swApp.ActiveDoc
If ComboBox.Text <> "" Then
Doc.SetMaterialPropertyName2 "", "solidworks materials.sldmat", ComboBox.Text
End If
End Sub