Hello everyone,
This post to share some macros made with the help of this forum and to ask for your advice.
For context: we are currently looking to automate some of our export procedures with Solidworks (2017) to simplify subcontracting.
We work on projects that are frequently edited and subcontracted regularly by people who are not necessarily the cartoonists, hence the need to have reliable files.
We are "lucky", we can outsource using volume files (sldpart and step), which greatly simplifies the work.
Our solidworks files are multibody models (mostly simple mechanically welded assemblies).
Each multibody part is designated by a letter in each project. (A.sldpart, B.sldpart, etc.)
Each body of each part is designated by a name of type A1, A2, etc. in the welded parts list properties.
We also use the list of welded parts to store other information for each body (number and diameter of holes, subcontracted or not, designation for bills of materials, etc.).
For subcontracting we need to extract volume files corresponding to the fields A1, A2, ..., named such as: A1.sldpart. (note: the management of order quantities is done via our ERP and the bill of materials).
Unable to find an easy way to invoke the "save bodies" function in solidworks by automatically naming based on properties of the welded parts list, we decided to develop a macro for this purpose. (allowing you to filter the exports according to other parameters).
In the attachment of this post you will find 2 macros that allow:
- The first one exports all bodies based on properties of the welded parts list:
- In a part file, scan all top-level elements in the list of welded parts (+/= all different bodies)
- For each element of the welded part list: create an entry in 2 different tables: in the first one write the custom properties of the body (in our case ID, laser, P, ...) AND write in a second table the corresponding body.
- At the end of this loop, the bodies can be filtered, and are then saved in C:Temp as A1.sldprt A2.sldpart etc.
- The second, write the number and diameter of each hole in a property of each body:
- In a part file, scan all top-level elements in the list of welded parts (+/= all different bodies)
- For each item in the welded part list, run a drill search macro on the body concerned (from: https://forum.solidworks.com/thread/201408)
- Write the result in the "p" property.
After spending a lot of time snooping around on different forums, I haven't found such macros, so I hope they can be useful to some people.
Several remarks:
- - First "experience" in macro solidworks for me so it's coded with the feet. These macros usually come from an assembly of pieces of code gleaned from the net, so it's neither optimized nor reliable I think, but it works.
- - It works for me and on 3 other workstations in 2017 with the following precautions: launch from the macro editor by placing yourself in the main (i.e. click on main), have an existing C:/temp directory.
If some of you have a little time to give me, I'm interested in helping on 3 points:
- I'm interested in the automatic generation of dxf (for flat sheets and for unfolded sheets), in the same case as before (naming etc.). I did find the swPart.ExportToDWG2 method, but I can't apply it to a body (ibody2), but only to a complete part. I see only one option (not very aesthetic: delete all bodies except one, export the "part that contains only one body", move on to the next body, etc). Take advice if you have any.
- From a broader point of view: I have the impression that my logic is not so bad for the first 2 macros: do you see another (simpler) method to achieve this goal?
- If some people feel like cleaning up the code so that it can (better) be used by others, don't hesitate!
Thank you for your feedback,
Q
qc-save_bodies_according_to_id-v0.1.swp