Automatic Part Code Using Custom Property Tab Builder

call
Samarsinh Khanvilkar, Application Engineer Jan 8th, 2024

The problem statement emphasizes the requirement for user-created parts to be saved using organization-generated predefined naming conventions. These naming conventions result from a combination of inputs, originating from either user-defined values or pre-established defaults. Now, let’s delve into how this can be achieved using SOLIDWORKS.

Setting up the predefined structure of code

To embark on our journey, the initial phase involves establishing a standardized structure for the code or formula that will underpin the entire process. The specifics of this structure may vary depending on the organization and the intricacy of the code. Within this procedural framework, we’ll employ a logic that comprehensively encompasses various scenarios, leaving no space unexplored. This strategic approach ensures thorough coverage throughout the process.

The part number schema will look something like this: XXX.XX.XX.X.XX

  • XXX: First 3 letters are for Assembly type (Alphabets)
  • XX: 4th and 5th letters are for Sub Type number (Numbers)
  • XX: 6th and 7th letters are for Department (Alphabets)
  • X: 8th number is for Capacity (Number)
  • XX: 9th and 10th are for Revision (Number)

The first 3 sections are dependent on each other. Like every assembly type has already assigned to a particular department and the depending on subtypes are also assigned.

Creating the Excel sheet for the dependable

As per the data gathered from the organizational structure, we can proceed with the making of the excel sheet. We have the data in the following format.


The data can be huge but let’s use this for the first 3 parts. Save the data in the excel file. And head towards the Custom Property Tab Builder.

Creating the tabs in property tab builder

In the Custom Property Tab Builder, Let’s build the tabs and the associated values.
First open the custom property tab builder.

Assigning the Excel Data in the list Format:

Make your SolidWorks design work easier by adding a “List Group” above the “Groupbox.” This helps make things look better and keeps your project organized. First, change the properties to fit your project. Then, add your Excel file data and make sure to start from the second row, with the headers in the first row (like A2:D9). Since you have four columns of data, drag, and drop new lists into the “List Group” to match. Set up the columns in order, from the first to the last. Keep everything consistent across all configurations, so your design works well. (Click on this Icon to apply it to all configurations)

Adding remaining file properties:

The capacity can be added by simply inserting the list and filling it up with the needed capacity values, such as 1, 2, 3, or 4. Next, include a Textbox in the same group. This allows users to manually input revisions, providing flexibility and customization options for your project. With this straightforward approach, you enhance the capacity of your project and empower users to easily manage, and update revisions as needed.

After making all the changes your tab will look like the following.

Now save it to the custom property template location and open a new part.

Assigning Custom Properties Through Tab Builder

After opening of the part, Now we can open the custom properties in the task pane by selecting this icon . Now press F5 in the window and select the template we just saved.

You will see a form we just created which can be filled as per the requirements of the part file. After clicking apply, the custom properties will be applied to the file which can be viewed in the file properties. If we do all the above steps correctly. Our file properties should look something like this:

Creating the code in custom property.

Add the new property by typing “Formula” as name in the latest row. And use the expression ($PRP:”property name”) to link the custom property to the formula.

Now use the same expression again and again to link all the properties in correct order. So that the evaluated value of the property will look like the code we want. If we take look at the formula which evaluates the code we are generating will look something like this: ($PRP:”Abbrevation”$PRP:”SubType”$PRP:”Department”$PRP:”Capacity”$PRP:”Revisions”).

And the Code will be evaluated to: SHT01LR101
This is how we can generate the code we required.

Assigning the code to the file name

After successfully creating the code, add the another property which will only reflect the same code by using the expression $PRP:”Formula” and rename the property to Part Number.

Save the current opened part file to rename the file. Then run the following macro file which will rename the part file with the custom property “Part Number”

Option Explicit

Sub RenamePartBasedOnCustomProperty()
‘ Declare variables
Dim swApp As Object
Dim swModel As Object
Dim swCustPropMgr As Object
Dim swNewModel As Object
Dim propName As String
Dim propValue As String
Dim propEvaluatedValue As String
Dim newPartName As String

‘ Initialize SolidWorks
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

‘ Check if a document is open
If swModel Is Nothing Then
MsgBox “Please open a SolidWorks part document first.”, vbExclamation
Exit Sub
End If

‘ Specify the custom property to use for renaming
propName = “Part Number”

‘ Get the custom property manager
Set swCustPropMgr = swModel.Extension.CustomPropertyManager(“”)

‘ Check if the custom property exists
If Not swCustPropMgr Is Nothing Then
‘ Get the custom property value
propValue = swCustPropMgr.Get(propName)

If Not IsEmpty(propValue) Then
‘ Validate and clean the custom property value for use in a file name
propValue = CleanFileName(propValue)

‘ Get the evaluated value of the custom property
propEvaluatedValue = swModel.GetCustomInfoValue(“”, propName)

‘ Get the full path of the part using a workaround
Dim modelPath As String
modelPath = swModel.GetPathName
If modelPath = “” Then
‘ If the part is not saved, prompt user to save
MsgBox “Please save the part before renaming.”, vbExclamation
Exit Sub
End If

‘ Generate the new part name using the evaluated custom property value
newPartName = Left(modelPath, InStrRev(modelPath, “\”)) & propEvaluatedValue & “.SLDPRT” ‘ You can adjust the file extension if needed

‘ Save the part with the new name using SaveAs3
swModel.SaveAs3 newPartName, 0, 0

‘ Close the original part without saving changes
swApp.CloseDoc modelPath

‘ Open the new part to refresh the SolidWorks model
Set swNewModel = swApp.OpenDoc(newPartName, swDocPART)

‘ Set the custom property in the new part
Dim swNewCustPropMgr As Object
Set swNewCustPropMgr = swNewModel.Extension.CustomPropertyManager(“”)
swNewCustPropMgr.Set propName, propEvaluatedValue

‘ Save the new part to retain the custom property
swNewModel.Save

MsgBox “Part successfully renamed to: ” & propEvaluatedValue, vbInformation
Else
MsgBox “Custom property ‘Description’ is empty.”, vbExclamation
End If

Else
MsgBox “Custom property manager not found.”, vbExclamation
End If
End Sub

Function CleanFileName(value As String) As String
‘ Replace invalid characters in a file name with underscores
Dim invalidChars As String
Dim i As Integer
invalidChars = “\/:*?””<>|”
For i = 1 To Len(invalidChars)
value = Replace(value, Mid(invalidChars, i, 1), “_”)
Next i
CleanFileName = value
End Function

And with this your File will be renamed with the part code successfully.

Tip: You can save the part as template to save the formula in the template. Just make sure you delete the values in the custom properties and then save it as a template.

We Urge You To Call Us For Any Doubts & Clarifications That You May Have. We Are Eager to Talk To You

Call Us: +91 7406663589

Karnataka & Goa

Chennai

Mumbai

Pune

Gujarat

Hyderabad

For SOLIDWORKS Product Enquiry Contact:

AUTHOR: Samarsinh Khanvilkar, Application Engineer

How useful was this?

Click on a star below to rate us out of 5 stars

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

59 responses to “Automatic Part Code Using Custom Property Tab Builder”

  1. AlbertForgo says:

    pin up giris https://azerbaijancuisine.com/# pin up 360
    pin up

  2. RichardArili says:

    mexican drugstore online purple pharmacy mexico price list mexican rx online

  3. RichardArili says:

    medicine in mexico pharmacies mexican pharmacy northern doctors medicine in mexico pharmacies

  4. RichardArili says:

    buying from online mexican pharmacy mexican pharmacy northern doctors best online pharmacies in mexico

  5. RichardArili says:

    mexican online pharmacies prescription drugs mexican pharmacy northern doctors mexican pharmaceuticals online

  6. WilliamFum says:

    reputable mexican pharmacies online: mexican pharmacy northern doctors – mexican drugstore online

  7. Jeffreyrup says:

    https://northern-doctors.org/# п»їbest mexican online pharmacies

  8. WilliamFum says:

    medicine in mexico pharmacies: mexican northern doctors – mexican border pharmacies shipping to usa

  9. Jeffreyrup says:

    https://northern-doctors.org/# mexico drug stores pharmacies

  10. WilliamFum says:

    mexico drug stores pharmacies: mexican pharmacy online – best online pharmacies in mexico

  11. Jeffreyrup says:

    http://northern-doctors.org/# mexican pharmaceuticals online

  12. WilliamFum says:

    reputable mexican pharmacies online: mexican pharmacy – mexican border pharmacies shipping to usa

  13. RichardArili says:

    mexico drug stores pharmacies mexican northern doctors buying prescription drugs in mexico

  14. WilliamFum says:

    buying prescription drugs in mexico online: mexican pharmacy online – mexico pharmacies prescription drugs

  15. Jeffreyrup says:

    https://northern-doctors.org/# mexican online pharmacies prescription drugs

  16. WilliamFum says:

    buying from online mexican pharmacy: northern doctors pharmacy – mexico pharmacies prescription drugs

  17. WilliamFum says:

    mexico pharmacy: best online pharmacies in mexico – buying from online mexican pharmacy

  18. Jeffreyrup says:

    http://northern-doctors.org/# medication from mexico pharmacy

  19. WilliamFum says:

    mexico drug stores pharmacies: Mexico pharmacy that ship to usa – mexican online pharmacies prescription drugs

  20. Jeffreyrup says:

    http://northern-doctors.org/# mexico pharmacies prescription drugs

  21. WilliamFum says:

    buying prescription drugs in mexico online: mexican northern doctors – mexico drug stores pharmacies

  22. WilliamFum says:

    mexican rx online: northern doctors – mexican border pharmacies shipping to usa

  23. RichardArili says:

    mexican rx online mexican pharmacy online mexican mail order pharmacies

  24. Jeffreyrup says:

    https://northern-doctors.org/# pharmacies in mexico that ship to usa

  25. WilliamFum says:

    mexico pharmacies prescription drugs: northern doctors – purple pharmacy mexico price list

  26. WilliamFum says:

    mexican pharmacy: mexican pharmacy – mexican border pharmacies shipping to usa

  27. Jeffreyrup says:

    https://northern-doctors.org/# mexican mail order pharmacies

  28. WilliamFum says:

    mexico pharmacies prescription drugs: mexican pharmacy northern doctors – medicine in mexico pharmacies

  29. Jeffreyrup says:

    https://northern-doctors.org/# buying from online mexican pharmacy

  30. WilliamFum says:

    mexican pharmacy: northern doctors – pharmacies in mexico that ship to usa

  31. WilliamFum says:

    mexican mail order pharmacies: Mexico pharmacy that ship to usa – mexican pharmacy

  32. Jeffreyrup says:

    https://northern-doctors.org/# п»їbest mexican online pharmacies

  33. RichardArili says:

    mexican mail order pharmacies Mexico pharmacy that ship to usa mexico pharmacies prescription drugs

  34. WilliamFum says:

    mexican rx online: northern doctors – mexican mail order pharmacies

  35. Jeffreyher says:

    http://cmqpharma.com/# mexican mail order pharmacies
    buying prescription drugs in mexico online

  36. RonnieKax says:

    mexican pharmacy online mexican pharmacy buying prescription drugs in mexico online

  37. RonnieKax says:

    mexican mail order pharmacies cmq mexican pharmacy online medicine in mexico pharmacies

  38. RonnieKax says:

    mexican pharmaceuticals online mexican online pharmacy medicine in mexico pharmacies

  39. StephenVab says:

    mexico pharmacies prescription drugs: cmq pharma mexican pharmacy – mexican mail order pharmacies

  40. RonnieKax says:

    mexican rx online cmq pharma mexican pharmacy purple pharmacy mexico price list

  41. RonnieKax says:

    buying from online mexican pharmacy mexican online pharmacy mexican pharmacy

  42. DonaldGem says:

    mexico pharmacies prescription drugs
    https://cmqpharma.online/# medicine in mexico pharmacies
    mexican border pharmacies shipping to usa

  43. RonnieKax says:

    mexican border pharmacies shipping to usa mexico pharmacy mexican online pharmacies prescription drugs

  44. RonnieKax says:

    mexican pharmacy mexican online pharmacy mexican border pharmacies shipping to usa

  45. RonnieKax says:

    medicine in mexico pharmacies buying prescription drugs in mexico online medication from mexico pharmacy

  46. RonnieKax says:

    pharmacies in mexico that ship to usa cmqpharma.com п»їbest mexican online pharmacies

  47. Charlesbioke says:

    mexico drug stores pharmacies mexican pharmaceuticals online mexican online pharmacies prescription drugs

  48. EdwardVof says:

    http://foruspharma.com/# mexican online pharmacies prescription drugs

  49. EdwardVof says:

    http://foruspharma.com/# buying from online mexican pharmacy

  50. Charlesbioke says:

    reputable mexican pharmacies online buying prescription drugs in mexico mexican border pharmacies shipping to usa

  51. EdwardVof says:

    https://foruspharma.com/# buying prescription drugs in mexico online

  52. JamesAtods says:

    can i get generic clomid pills: cost cheap clomid now – can i order cheap clomid without a prescription

  53. JamesAtods says:

    doxyhexal: doxycycline antibiotics – doxycycline uk cost

  54. JamesAtods says:

    amoxicillin canada price: amoxicillin 500mg buy online uk – amoxicillin 500

  55. JamesAtods says:

    purchase amoxicillin online without prescription: how to get amoxicillin over the counter – amoxicillin 500 mg brand name

  56. JamesAtods says:

    paxlovid india: paxlovid india – paxlovid cost without insurance

  57. JamesAtods says:

    cost cheap clomid price: get generic clomid no prescription – can i purchase cheap clomid no prescription

  58. JamesAtods says:

    п»їpaxlovid: Paxlovid over the counter – paxlovid for sale

Leave a Reply

Your email address will not be published.

NEWSLETTER SIGN-UP