Jump to content

Building a macro for assigning part numbers using some rules - help!!! (SW 2015)


gzaimovic

Recommended Posts

Hi,

 

I am new with macros and I need help about writing a macro for adding part numbers (custom property name: "Poz.") to each part in assembly

 

according to a few rules.

 

In the first picture, you can see the unsorted BOM of the assembly (list of all parts without part numbers)

In the second picture there is a sorted BOM. (I added the part numbers (red) manualy for this example)

 

Part number adding rules:

 

1. Part numbers starting from no.1 should be assigned to parts with visible "Materijal" column (orange). The numbering order of this parts is not important.

 

2. When there is no more parts with "Materijal" column, next part numbers should be assigned to parts that have the "Norma/Oznaka crteža" column (custom config. property) starting with "FESTO". (pink)

 

3. Next are parts with the same custom property starting with "SMC" (blue)

 

4. Next are parts with the same custom property starting with "HYPEX" (grey)

 

5. Next are parts with the same custom property starting with all other (brown)

 

6. Part numbers SHOULD NOT be assigned to parts with the custom property starting with "HRN" (green) because these numbers are already

assigned in the toolbox.

 

BOM unsorted-sorted.jpg

 

Thanks

Link to comment
Share on other sites

From my experience, (I'm just getting into macro writing myself)

People are more willing to help you fix your code rather than writing for you.

I've had many posts on the Solidworks forums ignored because I didn't

show that I was at least trying to write the code myself.

 

What you are after is a substantial feat.

You might consider paying someone to code something for you

(on the Solidworks forums)

 

https://forum.solidworks.com/community/api

 

Good luck!!

Link to comment
Share on other sites

Thats a pretty complicated task for a beginner. Have you done any coding before?

 

There are several important things you need to know to do this. i dont have any macros that come close but i can give you some code to get you started. You will need to figure out how to work in an assembly grabbing each part. You will need to know about configurations of each part. The little bit of code ill put below gets the active document which i made for a part but will alter the custom property of an assembly as well. For an assembly you will actually have to open each part, rebuild and save/close it then go back to the assembly.

 

Anyways the code i have below adds a custom property to either the assembly or part file that is active.

 

 

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim config As SldWorks.Configuration

Dim cusPropMgr As SldWorks.CustomPropertyManager

Dim lRetVal As Long

 

Sub main()

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set config = swModel.GetActiveConfiguration

 

 

Set cusPropMgr = config.CustomPropertyManager

 

 

lRetVal = cusPropMgr.Add3("NewConfig", swCustomInfoDate, "12-10-15", swCustomPropertyDeleteAndAdd)

 

End Sub

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...