Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Material Property Macro Question

Status
Not open for further replies.

ell1

Mechanical
Apr 20, 2006
4
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.

 
Replies continue below

Recommended for you

I'm not sure if I understand correctly. How is this different than what's available already? (Mtl pull down list)

Chris
Systems Analyst, I.S.
SolidWorks 06 4.1/PDMWorks 06
AutoCAD 06
ctopher's home (updated 06-21-06)
 
Chris,

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
 
I see what you're trying to do. You're looking to make one single user form that has all the custom properties you use on the same form, including the materials. We do something similar except we don't use the SW material database and we don't actually set the SW material. I can't see any way to get a list of materials from a ".sldmat" file with simple SW API calls. The .sldmat file is in XML format, and I'm afraid I'm pretty ignorant when it comes to using/parsing XML.

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.
 
You can crate your own drop down mtl list that is next to the SW mtl list. I use the SW default and my own. Cosmos uses it also.

Chris
Systems Analyst, I.S.
SolidWorks 06 4.1/PDMWorks 06
AutoCAD 06
ctopher's home (updated 06-21-06)
 
handleman, Chris,

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
 
You can really take this as far as you want if you create an Access database with common values of all your custom properties - finishes, modeler, drafter, etc. We even have a table in ours allowing each designer to enter (through the SW macro's user form) information for their current job such as part number prefix, job number, project description, etc. One button on the form fills all that information out on the part.

Running the macro on a part in an assembly should be no problem at all.
 
I used to have the list of materials hard coded, not anymore. I find it easier to have a small text file with the values for my combo boxes. Now I can quickly add or remove materials from the text file. Most of the time materials added in the list are already defined in our material database.

 
I see no real advantage to having a separate text file or database. Either you link to the existing xml file or you don't. Since this materials file is only updated each major release, I don't see a big advantage to linking to it. I bet you would spend more time coding this than just updating a manually created list once per year.

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:
Private Sub UserForm_Activate()

    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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor