×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Setting material using API in SW2005

Setting material using API in SW2005

Setting material using API in SW2005

(OP)
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


RE: Setting material using API in SW2005

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

RE: Setting material using API in SW2005

(OP)
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.

RE: Setting material using API in SW2005

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?

I could be the world's greatest underachiever, if I could just learn to apply myself.
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Setting material using API in SW2005

(OP)
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.

RE: Setting material using API in SW2005

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

RE: Setting material using API in SW2005

CODE

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

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

I could be the world's greatest underachiever, if I could just learn to apply myself.
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Setting material using API in SW2005

(OP)
It works now. I was mislead by SW2005 API help, I didn't have sldmaterials.sldmat on my system. I thought I did.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources