Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Custom Propery Name 3

Status
Not open for further replies.

lucason

Mechanical
Apr 24, 2002
18
0
0
GB
I have hundreds of SolidWorks parts that require approximately 40 identical custom properties adding to each of them. I intend to write the values of these custom properties via a design table.
Does anybody know of an easier way to create the custom properties than to open each part and painstakingly type in each one on each part.
P.S. i have very little API experience but would be glad of a little nudge into it.

Thanking you in anticipation.

Lucas
ON engineering.
 
Replies continue below

Recommended for you

Check out Under SolidWorks API Tutorials click Macros/Examples then see Example 7. Then write yourself a Visual Basic 6 program to link the data you type in and SolidWorks.
Also check out this is another good source for Custom Properties Tutorial.
There are several sites on the Internet. Whatever you learn about Visual Basic 6, you will use for other ideas.
 
There is a program out on the SW website for download.

Custom File Properties - This VB 5.0 program simplifies the task of entering a standard set of custom properties for your models. It will allow you to create or modify a standard set custom properties for a the active SolidWorks document. This program is easily customizable to a users specific needs using VB5.0 or VB 6.0. WE ahve used to with success.

This is found under subscription support, model library, API, general utilities. If you do not have subscription support I could send it to you.
BBJT CSWP
 
To make it a little easier, you could modify this code to automatically create the tag names for the part. If the properties are configuration specific, you will need to define the variable sConfig with the name of the configuration. When using non-configuration specific properties, just use an empty string. The last value in each call of AddCustomInfo3 is the default that gets stored with the property. Use the types as required.

To use this, just record a new macro, do nothing and stop recording. Save the macro then edit it and replace with this code. Then, just run the macro when you have a file opened and run it.
Code:
Option Explicit

Dim swApp As Object
Dim Part As Object

Const swCustomInfoUnknown = 0
Const swCustomInfoText = 30
Const swCustomInfoDate = 64
Const swCustomInfoNumber = 3
Const swCustomInfoYesOrNo = 11

Sub main()
    Dim sConfig As String
    
    Set swApp = CreateObject("SldWorks.Application")
    Set Part = swApp.ActiveDoc
    
    sConfig = ""    'not config specific
    
    Part.AddCustomInfo3 sConfig, "description", swCustomInfoText, ""
    Part.AddCustomInfo3 sConfig, "material", swCustomInfoText, ""
    Part.AddCustomInfo3 sConfig, "spec1", swCustomInfoText, ""
    Part.AddCustomInfo3 sConfig, "spec2", swCustomInfoText, ""
    Part.AddCustomInfo3 sConfig, "weight", swCustomInfoNumber, 0
    
    Set Part = Nothing
    Set swApp = Nothing
End Sub
Hope this helps... DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Oh, and to avoid this problem in the future, create template parts with the properties defined and filled in before you start more parts.

Crashj Johnson
 
Hey DSI,

Thanks for the code. I'm a rookie to VB and this worked great. I edited the code to our custom pros and it works great.

One question: I had someone at a Solidworks reseller (in the past) write a VB program that was like an editor. I hit the .exe and an editor comes up on the screen. It is set up with all the custom props I want to add to the open file. It has an area next to each one to fill in the "values" of the custom props. Then I just hit APPLY and the props AND their values get added to the open Solidworks file.

How is this set up? I think the code you attached just adds the prop names, but w/o the values, right?

I'm reading up and learning VB as we speak. It's all new to me so bear with any stupid questions.

Thx

Stormrider

 
stormrider:

Yes, that code just added the names. Those commands can also add the value, using the last parameter. If you are just learning VB, you should check out the sample that Bradley pointed out. With a little practice with VB, you can create a form to your liking. Then, simply use the SW API above to populate the custom properties. You will also have to include a call to Part.CustomInfo2 to get any information that may already be there. You will also have to take into account different configurations, if that is something you use.

I think that I may be making it sound harder than it is. Again, check out the nhcad link for a good sample.
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Status
Not open for further replies.
Back
Top