Adding quantity and thickness to the name while saving the file
- Ömür Tokman
- Posts: 359
- Joined: Sat Mar 13, 2021 3:49 am
- Location: İstanbul-Türkiye
- x 993
- x 345
- Contact:
Adding quantity and thickness to the name while saving the file
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"--- https://www.codestack.net/solidworks-ap ... -patterns/
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"--- https://www.codestack.net/solidworks-ap ... -patterns/
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.
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 postYou 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"
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
- Jaylin Hochstetler
- Posts: 387
- Joined: Sat Mar 13, 2021 8:47 pm
- Location: Michigan
- x 380
- x 355
- Contact:
Re: Adding quantity and thickness to the name while saving the file
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.
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.
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"
- Attachments
-
- Sac-icin-montajdan-dısari-dxf-ver - AT - 003.swp
- (132 KiB) Downloaded 272 times
-
- Omur DXF Export.swp
- (165 KiB) Downloaded 298 times
A goal is only a wish until backed by a plan.
- Ömür Tokman
- Posts: 359
- Joined: Sat Mar 13, 2021 3:49 am
- Location: İstanbul-Türkiye
- x 993
- x 345
- Contact:
Re: Adding quantity and thickness to the name while saving the file
Hi Jaylin,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.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.Code: Select all
Const OUT_NAME_TEMPLATE As String = "C:\New folder<_FileName_>_<$PRP:AutoQty>_<$PRP:Thickness.dxf"
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.
-
- Posts: 48
- Joined: Mon Dec 20, 2021 1:40 pm
- Location: Thumb Area of Michigan, USA
- x 174
- x 26
Re: Adding quantity and thickness to the name while saving the file
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.
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.
Re: Adding quantity and thickness to the name while saving the file
@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
Artem
xarial.com - making your CAD better
codestack.net - SOLIDWORKS API macros and tutorials
- Jaylin Hochstetler
- Posts: 387
- Joined: Sat Mar 13, 2021 8:47 pm
- Location: Michigan
- x 380
- x 355
- Contact:
Re: Adding quantity and thickness to the name while saving the file
Thanks, Artem!
A goal is only a wish until backed by a plan.
-
- Posts: 2
- Joined: Fri Apr 26, 2024 8:29 am
Re: Adding quantity and thickness to the name while saving the file
Hello, I have the same problem. How did you manage to have the right quantity ?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.
-
- Posts: 48
- Joined: Mon Dec 20, 2021 1:40 pm
- Location: Thumb Area of Michigan, USA
- x 174
- x 26
Re: Adding quantity and thickness to the name while saving the file
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.Koubaleite wrote: ↑Tue Jul 30, 2024 9:48 am Hello, I have the same problem. How did you manage to have the right quantity ?
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.
-
- Posts: 9
- Joined: Thu Aug 22, 2024 7:33 am
- x 4
- x 2
Re: Adding quantity and thickness to the name while saving the file
The Macro "Omur DXF Export.swp" works perfectly. Is there any way to also save .Step files together while saving DXF's ?
-
- Posts: 9
- Joined: Thu Aug 22, 2024 7:33 am
- x 4
- x 2
Re: Adding quantity and thickness to the name while saving the file
@Ö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 ?
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 ?
- Ömür Tokman
- Posts: 359
- Joined: Sat Mar 13, 2021 3:49 am
- Location: İstanbul-Türkiye
- x 993
- x 345
- Contact:
Re: Adding quantity and thickness to the name while saving the file
I'll try this during the week.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 ?
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
- Ömür Tokman
- Posts: 359
- Joined: Sat Mar 13, 2021 3:49 am
- Location: İstanbul-Türkiye
- x 993
- x 345
- Contact:
Re: Adding quantity and thickness to the name while saving the file
Remember that I am an amateur,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 ?
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! in the same folder creates different folders.
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
-
- Posts: 9
- Joined: Thu Aug 22, 2024 7:33 am
- x 4
- x 2
Re: Adding quantity and thickness to the name while saving the file
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.
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.
- Ömür Tokman
- Posts: 359
- Joined: Sat Mar 13, 2021 3:49 am
- Location: İstanbul-Türkiye
- x 993
- x 345
- Contact:
Re: Adding quantity and thickness to the name while saving the file
2 and 3 will be selected, if you don't want the form I will leave it to you to remove it. It will create a folder on the desktop with the first 5 characters in your project and save the files there. 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.
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
-
- Posts: 9
- Joined: Thu Aug 22, 2024 7:33 am
- x 4
- x 2
Re: Adding quantity and thickness to the name while saving the file
Thank you very much for your help. I will try to adjust the code as you suggested.
-
- Posts: 9
- Joined: Thu Aug 22, 2024 7:33 am
- x 4
- x 2
Re: Adding quantity and thickness to the name while saving the file
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
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
- Ömür Tokman
- Posts: 359
- Joined: Sat Mar 13, 2021 3:49 am
- Location: İstanbul-Türkiye
- x 993
- x 345
- Contact:
Re: Adding quantity and thickness to the name while saving the file
What do you want to do? Can you explain what you want to do with this code?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"
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.
-
- Posts: 9
- Joined: Thu Aug 22, 2024 7:33 am
- x 4
- x 2
Re: Adding quantity and thickness to the name while saving the file
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.
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.
- Ömür Tokman
- Posts: 359
- Joined: Sat Mar 13, 2021 3:49 am
- Location: İstanbul-Türkiye
- x 993
- x 345
- Contact:
Re: Adding quantity and thickness to the name while saving the file
Is this what you're talking about?
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
-
- Posts: 9
- Joined: Thu Aug 22, 2024 7:33 am
- x 4
- x 2
Re: Adding quantity and thickness to the name while saving the file
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!
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!
-
- Posts: 2
- Joined: Fri Apr 26, 2024 8:29 am
Re: Adding quantity and thickness to the name while saving the file
Does the macro actually export multi bodies ? I am having a hard time exporting as dxf multi part bodies. It only exports one body.
-
- Posts: 48
- Joined: Mon Dec 20, 2021 1:40 pm
- Location: Thumb Area of Michigan, USA
- x 174
- x 26
Re: Adding quantity and thickness to the name while saving the file
Hello,Koubaleite wrote: ↑Tue Oct 08, 2024 9:07 am Does the macro actually export multi bodies ? I am having a hard time exporting as dxf multi part bodies. It only exports one body.
I just checked the one on this thread & it only gives me 1 DXF also. The modified one that I actually use is here viewtopic.php?t=74 under post 4 by @Jaylin Hochstetler. Which is where I maybe should have directed you.
But again I had modified the one I use to do what I wanted! (I also wanted quantities which is kind of hit miss. If you have a multibody part linear patterned in an assembly it doesn't count correctly).