Adding quantity and thickness to the name while saving the file

Library for macros
User avatar
Ömür Tokman
Posts: 356
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 987
x 342
Contact:

Adding quantity and thickness to the name while saving the file

Unread post by Ömür Tokman »

Hello there,
The macro below is @artem's
This macro saves the sheet metal products in the assembly flat in a folder.
I want to add sheet thickness and quantity to the file name you saved, I've been trying for about 4 days, but I still couldn't get a result.
the quantity and thickness I want to add is in summary information/Custom.

Is there anyone who can help me with this?

For example
The result you want = Part1-1mmDKP-1 Piece
--Const OUT_NAME_TEMPLATE As String = "DXFs\<_FileName_>_<_Thickness_>_<_AutoQty_>.dxf"---
2021-07-05_13-18-07.png
https://www.codestack.net/solidworks-ap ... -patterns/
2021-07-05_12-40-59.png
2021-07-05_12-40-59.png (13.77 KiB) Viewed 5614 times
Sac-icin-montajdan-dısari-dxf-ver - AT - 003.swp
(115.5 KiB) Downloaded 202 times
by Jaylin Hochstetler » Mon Jul 05, 2021 7:49 am
You have to put "$PRP:" before a the custom property you want in the file name.
You also have to enter the address of the folder such as "C:\New folder\DXFs". You had entered "D:" but you have to enter "D:\DXFs". "DXFs" is the folder the macro creates.

Code: Select all

Const OUT_NAME_TEMPLATE As String = "C:\New folder<_FileName_>_<$PRP:AutoQty>_<$PRP:Thickness.dxf"
Attached is the macro you posted revised with the custom properties. I also attached my version of it which includes options to give the folder a different name, export with or without sketches (which would be for etching), export with or without bend lines, and enter a different location for the folder either via browsing or entering the address.
Go to full post
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
User avatar
Jaylin Hochstetler
Posts: 387
Joined: Sat Mar 13, 2021 8:47 pm
Answers: 4
Location: Michigan
x 379
x 355
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Jaylin Hochstetler »

You have to put "$PRP:" before a the custom property you want in the file name.
You also have to enter the address of the folder such as "C:\New folder\DXFs". You had entered "D:" but you have to enter "D:\DXFs". "DXFs" is the folder the macro creates.

Code: Select all

Const OUT_NAME_TEMPLATE As String = "C:\New folder<_FileName_>_<$PRP:AutoQty>_<$PRP:Thickness.dxf"
Attached is the macro you posted revised with the custom properties. I also attached my version of it which includes options to give the folder a different name, export with or without sketches (which would be for etching), export with or without bend lines, and enter a different location for the folder either via browsing or entering the address.
Attachments
Sac-icin-montajdan-dısari-dxf-ver - AT - 003.swp
(132 KiB) Downloaded 261 times
Omur DXF Export.swp
(165 KiB) Downloaded 285 times
A goal is only a wish until backed by a plan.
User avatar
Ömür Tokman
Posts: 356
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 987
x 342
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Ömür Tokman »

Jaylin Hochstetler wrote: Mon Jul 05, 2021 7:49 am You have to put "$PRP:" before a the custom property you want in the file name.
You also have to enter the address of the folder such as "C:\New folder\DXFs". You had entered "D:" but you have to enter "D:\DXFs". "DXFs" is the folder the macro creates.

Code: Select all

Const OUT_NAME_TEMPLATE As String = "C:\New folder<_FileName_>_<$PRP:AutoQty>_<$PRP:Thickness.dxf"
Attached is the macro you posted revised with the custom properties. I also attached my version of it which includes options to give the folder a different name, export with or without sketches (which would be for etching), export with or without bend lines, and enter a different location for the folder either via browsing or entering the address.
Hi Jaylin,
Thank you so so much, both work perfectly! ><
And thank you for teaching me how.
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
DLZ_SWX_User
Posts: 36
Joined: Mon Dec 20, 2021 1:40 pm
Answers: 0
Location: Thumb Area of Michigan, USA
x 148
x 14

Re: Adding quantity and thickness to the name while saving the file

Unread post by DLZ_SWX_User »

We have been using this Macro from @artem 's also. It works very well.

We have modified it to give us the quantity of parts needed of a particular DXF, if a multi bodied part has a linear pattern or a mirror image, by using the following:

Const OUT_NAME_TEMPLATE As String = "<$CLPRP:Sheet Metal Thickness> <_FileName_> <$CLPRP:QUANTITY> <_FeatureName_> .dxf"

My question is can we somehow do the same from an assembly? Currently if I have a table with 4 legs, either 4 of the same inserted into the assembly or using linear pattern it will only tell me "1" in the file name not 4. If I create this same table as a multi body part it will tell me "4" in the file name not "1" which is what I would like for it to do in assemblies.

I have tried to use what was stated above could not get it to do what I wanted.
artem
Posts: 26
Joined: Thu Mar 18, 2021 1:31 pm
Answers: 3
x 9
x 74

Re: Adding quantity and thickness to the name while saving the file

Unread post by artem »

@DLZ_SWX_User, I have just published this new macro yesterday which addresses this issue:
Thanks,
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
User avatar
Jaylin Hochstetler
Posts: 387
Joined: Sat Mar 13, 2021 8:47 pm
Answers: 4
Location: Michigan
x 379
x 355
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Jaylin Hochstetler »

artem wrote: Tue Dec 21, 2021 12:44 am @DLZ_SWX_User, I have just published this new macro yesterday which addresses this issue:
Thanks, Artem!
A goal is only a wish until backed by a plan.
Koubaleite
Posts: 1
Joined: Fri Apr 26, 2024 8:29 am
Answers: 0

Re: Adding quantity and thickness to the name while saving the file

Unread post by Koubaleite »

DLZ_SWX_User wrote: Mon Dec 20, 2021 3:39 pm We have been using this Macro from @artem 's also. It works very well.

We have modified it to give us the quantity of parts needed of a particular DXF, if a multi bodied part has a linear pattern or a mirror image, by using the following:

Const OUT_NAME_TEMPLATE As String = "<$CLPRP:Sheet Metal Thickness> <_FileName_> <$CLPRP:QUANTITY> <_FeatureName_> .dxf"

My question is can we somehow do the same from an assembly? Currently if I have a table with 4 legs, either 4 of the same inserted into the assembly or using linear pattern it will only tell me "1" in the file name not 4. If I create this same table as a multi body part it will tell me "4" in the file name not "1" which is what I would like for it to do in assemblies.

I have tried to use what was stated above could not get it to do what I wanted.
Hello, I have the same problem. How did you manage to have the right quantity ?
DLZ_SWX_User
Posts: 36
Joined: Mon Dec 20, 2021 1:40 pm
Answers: 0
Location: Thumb Area of Michigan, USA
x 148
x 14

Re: Adding quantity and thickness to the name while saving the file

Unread post by DLZ_SWX_User »

Koubaleite wrote: Tue Jul 30, 2024 9:48 am Hello, I have the same problem. How did you manage to have the right quantity ?
Since we are a custom welding shop & do a lot of prototyping & building one off machines & parts it was not a big issue. For the issue with the table mentioned we changed the quantity of the part in the part file to 4 instead of 1. This worked in this case as that leg is only used on 2 tables & is always use 4 per table, never less, never more. We also build custom truck toppers with multiples of the same door on a topper & do the same for these assemblies. This also worked on other parts & we used configurations just to change quantities.

In other instances I have created a multi bodied part with multiples of the same part in the proper locations for the assembly. This works if the part does not need to move in relation to the assembly. (This would have worked for the above mentioned table leg). Sorry I don't have a better answer.

Also remember that BOM's can show incorrect quantities also using the above scenario's, if your not careful.

Hope this helps. I have not searched to see if maybe someone may have updated this macro or found another fix.
tiwari1211@gmail.com
Posts: 8
Joined: Thu Aug 22, 2024 7:33 am
Answers: 0
x 4
x 2

Re: Adding quantity and thickness to the name while saving the file

Unread post by tiwari1211@gmail.com »

The Macro "Omur DXF Export.swp" works perfectly. Is there any way to also save .Step files together while saving DXF's ?
tiwari1211@gmail.com
Posts: 8
Joined: Thu Aug 22, 2024 7:33 am
Answers: 0
x 4
x 2

Re: Adding quantity and thickness to the name while saving the file

Unread post by tiwari1211@gmail.com »

@Ömür Tokman - Thanks a lot for such awesome code.
Is it also possible to insert text inside part in DXF from custom property ? In my case i have Part engraving number in custom property which I have to manually insert as Text (yellow layer) in DXF everytime. Which later on laser marked on Part as "Part number".
This consume lot of time to open every DXF and insert text.
Can you please check if this will be possible ?
User avatar
Ömür Tokman
Posts: 356
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 987
x 342
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Ömür Tokman »

tiwari1211@gmail.com wrote: Thu Aug 22, 2024 12:39 pm @Ömür Tokman - Thanks a lot for such awesome code.
Is it also possible to insert text inside part in DXF from custom property ? In my case i have Part engraving number in custom property which I have to manually insert as Text (yellow layer) in DXF everytime. Which later on laser marked on Part as "Part number".
This consume lot of time to open every DXF and insert text.
Can you please check if this will be possible ?
I'll try this during the week.
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
User avatar
Ömür Tokman
Posts: 356
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 987
x 342
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Ömür Tokman »

tiwari1211@gmail.com wrote: Thu Aug 22, 2024 10:27 am The Macro "Omur DXF Export.swp" works perfectly. Is there any way to also save .Step files together while saving DXF's ?
Remember that I am an amateur,
you should try it before real use.
macro can extract step files to dxf or step folder. But it is related to codes. you can move this feature to the form.

It is currently set to extract to the same folder, pay attention to the codes!
2024-08-26_12-16-38.png
in the same folder
2024-08-26_12-16-16.png
creates different folders.
2024-08-26_12-15-12.png
2024-08-26_12-09-48.png
SheetMetal_to_DXF - R2.swp
(164 KiB) Downloaded 55 times
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
tiwari1211@gmail.com
Posts: 8
Joined: Thu Aug 22, 2024 7:33 am
Answers: 0
x 4
x 2

Re: Adding quantity and thickness to the name while saving the file

Unread post by tiwari1211@gmail.com »

Hi Ömür, Your code works amazing. Thank you very much!! I saw it was downloaded 25 times insingle day, so this helped many users in need.

I have few more request if you can help with your expertise -
1) In my case i do not need any userform, by default 2nd & 3rd options are applicable.
2) i want to save the exported files directly on my desktop C:\Users\Desktop\Production\Project\drawing\....
In path, Can the name of folder "Project" defined from custom properties "Projectno.".
In path Can the name of folder "drawing" be defined from custom properties "drawingno." In custom property value of this field is in format example "xxxxx-12a" but i want to have drawing folder name with left 5 characters (only "xxxxx". Is it possible ?
3) As previously requested - Is it also possible to insert text inside part in DXF from custom property (while exporting DXF) ? In my case i have Part engraving number in custom property which I have to manually insert as Text (yellow layer) in DXF everytime. Which later on laser marked on Part as "Part number". text position can be at 0,0,0 (height 10)

Once again many thanks for all the help & time you provided to resolve my problem.
User avatar
Ömür Tokman
Posts: 356
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 987
x 342
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Ömür Tokman »

tiwari1211@gmail.com wrote: Mon Aug 26, 2024 5:42 pm Hi Ömür,
2 and 3 will be selected, if you don't want the form I will leave it to you to remove it.
2024-08-27_11-02-12.png
2024-08-27_10-54-29.png
It will create a folder on the desktop with the first 5 characters in your project and save the files there.
2024-08-27_10-52-55.png
2024-08-27_10-54-52.png
2024-08-27_10-54-52.png (96.53 KiB) Viewed 713 times
2024-08-27_10-59-47.png
2024-08-27_11-01-16.png
I don't think it will work, maybe there is an autocad macro, I don't know and I can't help you with that.
SheetMetal_to_DXF - R3.swp
(307 KiB) Downloaded 40 times
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
tiwari1211@gmail.com
Posts: 8
Joined: Thu Aug 22, 2024 7:33 am
Answers: 0
x 4
x 2

Re: Adding quantity and thickness to the name while saving the file

Unread post by tiwari1211@gmail.com »

Thank you very much for your help. I will try to adjust the code as you suggested.
tiwari1211@gmail.com
Posts: 8
Joined: Thu Aug 22, 2024 7:33 am
Answers: 0
x 4
x 2

Re: Adding quantity and thickness to the name while saving the file

Unread post by tiwari1211@gmail.com »

Hi Omur, The code works fine and create folder with "firstfivechars" when I run it on single part. But when i Run it on an assembly then it miss to create folder with "firstfivechars". In my case every sheetmetal part in assembly has an engraving no. in custom property for eg. part 1 has engraving no. "12345-1a", Part 2 has engraving no. "12345-2a" etc.

Can you please check why the code does not create folder when it run on assembly.

I used below code

Sub main()

Set swApp = Application.SldWorks
try_:
On Error GoTo hata:
'Get the folder name from custom properties.
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
bool = swCustProp.Get4("Engraving", False, val, valout)
firstFiveChars = Left(val, 5) 'get first 5 characters

PROJECT_NAME = "<$PRP:ProjectNo>_<$PRP:ProjectName>"
FLAT_PATTERN_OPTIONS = SheetMetalOptions_e.ExportFlatPatternGeometry + ExportFormingTools
OUT_NAME_TEMPLATE = "Temp\DXF" & "\" & PROJECT_NAME & "\" & firstFiveChars & "\DXFs\<_FileName_>.dxf"
OUT_NAME_TEMPLATE = "Temp\DXF" & "\" & PROJECT_NAME & "\" & firstFiveChars & "\STEPs\<_FileName_>.STEP"


If CheckBox3.Value = True Then
OUT_NAME_TEMPLATE = "Temp\DXF\" & PROJECT_NAME & "\" & firstFiveChars & "\DXFs\<$PRP:Engraving>_<$PRP:MOC>_<$PRP:Thickness>mm_Qty-<$PRP:Required>x.dxf"
OUT_NAME_TEMPLATE1 = "Temp\DXF\" & PROJECT_NAME & "\" & firstFiveChars & "\STEPs\<$PRP:Engraving>_<$PRP:MOC>_<$PRP:Thickness>mm_Qty-<$PRP:Required>x.STEP" 'extracted to the same folder.

End If

------------------------------------------------------------------------

ALso if I run with only option 2 selected i get msg "Some sheet metal drawings have multibody or extruded bodies".
image.png
whereas when i select option 2 & 3 the program run fine.

Thank you
User avatar
Ömür Tokman
Posts: 356
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 987
x 342
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Ömür Tokman »

tiwari1211@gmail.com wrote: Tue Sep 03, 2024 7:13 pm
OUT_NAME_TEMPLATE = "Temp\DXF\" & PROJECT_NAME & "\" & firstFiveChars & "\DXFs\<$PRP:Engraving>_<$PRP:MOC>_<$PRP:Thickness>mm_Qty-<$PRP:Required>x.dxf"
What do you want to do? Can you explain what you want to do with this code?

You create a DXF folder in temp, inside that you create a folder called project name, 5 characters, and DXFs, inside that you create the DXF file.

Am I understanding correctly?
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
tiwari1211@gmail.com
Posts: 8
Joined: Thu Aug 22, 2024 7:33 am
Answers: 0
x 4
x 2

Re: Adding quantity and thickness to the name while saving the file

Unread post by tiwari1211@gmail.com »

Hi Omur,
With this code i am trying to separate items in project folder. the "Fistfivechars" is actually the item number. So,
I already have a folder "DXF" inside "Desktop/temp" defined ..I want when i run the code, the code should check & if not existing then create New folder "Project_Name". Inside this folder there should be a new folder with "FirstfiveChars" of custom property "Engraving" (This folder is for item number). & then inside this folder there will be DXF & Step files for this model.
Next when i will run the code on the next item from same project, then this will create a new folder inside same project with new Item no. ("FirstfiveChars") & all the DXF & step files will be saved in this.
Also see attachment. let me know if above explaination is clear.
trail.jpg
User avatar
Ömür Tokman
Posts: 356
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 987
x 342
Contact:

Re: Adding quantity and thickness to the name while saving the file

Unread post by Ömür Tokman »

tiwari1211@gmail.com wrote: Thu Sep 05, 2024 8:15 am Hi Omur,
trail.jpg
Is this what you're talking about?
2024-09-16_09-02-58.png
2024-09-16_09-07-18.png
SheetMetal_to_DXF - R4.swp
(307 KiB) Downloaded 24 times
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
tiwari1211@gmail.com
Posts: 8
Joined: Thu Aug 22, 2024 7:33 am
Answers: 0
x 4
x 2

Re: Adding quantity and thickness to the name while saving the file

Unread post by tiwari1211@gmail.com »

Hi Omur,

I tried implementing this, but it doesn’t seem to work with my assembly the way it does with yours. I’m not sure what the issue is. In my case, the assembly itself doesn’t have a custom property for engraving—only the individual parts within the assembly do. This might be the reason, but I can’t say for certain.

Regardless, your help has been invaluable, and I really appreciate your support.

Thank you again!
Post Reply