gzaimovic Posted December 10, 2015 Share Posted December 10, 2015 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. Thanks Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 10, 2015 Share Posted December 10, 2015 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!! Quote Link to comment Share on other sites More sharing options...
shift1313 Posted December 11, 2015 Share Posted December 11, 2015 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.