Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Setting material using API in SW2005

Status
Not open for further replies.

dogarila

Mechanical
Oct 28, 2001
594
0
0
CA
How do I set the material for a part in SW05 using Visual Basic? I am using:

Code:
Part.SetMaterialPropertyName "sldmaterials.sldmat ", "HRS"

but it doesn't work. I don't get any error just the part does not update.

Another question:

When I declare variables like

Code:
Dim Part as SldWorks.PartDoc

i get an error saying that user type is not defined. It works if I use Object instead of SldWorks.PartDoc.

Thanx for help

Andrew


 
Replies continue below

Recommended for you

Hey,

PartDoc.SetMaterialPropertyName(database, name) is obsolete in Sw2005 SP0.1

Use PartDoc.SetMaterialPropertyName2( configName, database, name). This might solve your 1rst problem.

I cannot reproduce the second problem on my system. Check your project's references to see if you are referencing the SW 2005's libraries ("Sldwork 2005 Type Library" and "Sldwork 2005 Constants Type Library") and not one of the previous version (2004, 2003 ...)

One test will be to see if your code compile correctly in a vba module. If not, and if the syntax is correct, you might try to uninstall and re-install sw.

Hope this help
 
Thanks jacbal,

I fixed the second part of my question by checking the SolidWorks libraries in the project's references.

The first part still doesn't work. I know
PartDoc.SetMaterialPropertyName(database, name) is obsolete in Sw2005 SP0.1. Still, it should work.

Anyway, I tried to use PartDoc.SetMaterialPropertyName2( configName, database, name) and I got the same result. The program run's smoothly with no error, does everything else of what is supposed to do just the material of the part it is not updated.

There is something I'm missing here. I hope someone can enlighten me.

 
Sounds like your VB project is missing a reference to SldWorks.tlb. Make sure you have this reference in place under "Project [→] References".

What environment are you programming in? VB6? Another macro editor?

[bat]I could be the world's greatest underachiever, if I could just learn to apply myself.[bat]
-SolidWorks API VB programming help
 
I am programming in VB6. The reference was missing but not anymore. As I said, the second part of my issue was fixed. The first one, with the material setting is the problem.
 
When I use the following it works perfectly:

Code:
Part.SetMaterialPropertyName "SolidWorks Materials.sldmat", "Alloy Steel"

Are you sure the "HRS" material really exists in your database?? And btw, I dont have the sldmaterials.sldmat on my system.

Grtz, Bouke
 
Code:
Part.SetMaterialPropertyName "sldmaterials.sldmat ", "HRS"

Is "sldmaterials.sldmat " parameter supposed to have that extra space at the end inside the quotes?

[bat]I could be the world's greatest underachiever, if I could just learn to apply myself.[bat]
-SolidWorks API VB programming help
 
Status
Not open for further replies.
Back
Top