Export Solidworks model views to dxf file layers instead of sheets

es2058
Posts: 6
Joined: Sun May 07, 2023 7:15 am
Answers: 0
x 1

Export Solidworks model views to dxf file layers instead of sheets

Unread post by es2058 »

Anyone know of a way to export Solidworks model views into a single dxf file with each view into different layers? The default is exported into different sheets but I need them into layers.

Or something like a macro to convert the dxf sheets into layers after it is exported.
User avatar
gupta9665
Posts: 420
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 438
x 459

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by gupta9665 »

Never tried it but here is a thought.

Create a drawing template with all the desired views (pre defined views). Put them each on their individual layer. Now create the drawing for the model using that template and export as DXF. If this works then it can be easily automated using a macro in case you have to do it repeatedly.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
DanPihlaja
Posts: 862
Joined: Thu Mar 11, 2021 9:33 am
Answers: 25
Location: Traverse City, MI
x 815
x 993

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by DanPihlaja »

es2058 wrote: Thu May 25, 2023 7:21 am Anyone know of a way to export Solidworks model views into a single dxf file with each view into different layers? The default is exported into different sheets but I need them into layers.

Or something like a macro to convert the dxf sheets into layers after it is exported.
I am not sure that it is even possible from the part/assembly level, even with a macro (because in the custom map file, there is no option for view (even at the drawing level)

I played around with it, but I couldn't figure out how to map each view....

You might be able to add each view to a drawing, change the line type or color of each drawing view, then map the different line types/colors to layers in the map file. But I am not sure if this will be less work that the following option.

You might have to use a 3rd party software to do it. Or open the DXF inside Solidworks and then add each view to layers, then resave the DXF file.
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
es2058
Posts: 6
Joined: Sun May 07, 2023 7:15 am
Answers: 0
x 1

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by es2058 »

Thanks, will try the drawing template and play around.
User avatar
gupta9665
Posts: 420
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 438
x 459

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by gupta9665 »

I just tested the template method and it works.
Views on Layer DXF.PNG
Deepak Gupta
SOLIDWORKS Consultant/Blogger
es2058
Posts: 6
Joined: Sun May 07, 2023 7:15 am
Answers: 0
x 1

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by es2058 »

I was not able to change the different views of the drawing into layers, could only put all the views into the same layer. Is there a way to do this without converting the views to blocks/sketches?
User avatar
DanPihlaja
Posts: 862
Joined: Thu Mar 11, 2021 9:33 am
Answers: 25
Location: Traverse City, MI
x 815
x 993

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by DanPihlaja »

es2058 wrote: Tue May 30, 2023 11:28 am I was not able to change the different views of the drawing into layers, could only put all the views into the same layer. Is there a way to do this without converting the views to blocks/sketches?
That is correct, you can change the layer of a specific component that is shown in the drawing, but it changes it for every view that component is shown in.

I stand corrected. You CAN do it. see post below by @AlexB

I thought that you could select the edges of a part and change the layer of individual edges, but it doesn't look like you can do that.

You CAN change the view to a sketch, and then change the layers that way. But this breaks the link to the 3D part.
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
User avatar
gupta9665
Posts: 420
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 438
x 459

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by gupta9665 »

es2058 wrote: Tue May 30, 2023 11:28 am I was not able to change the different views of the drawing into layers, could only put all the views into the same layer. Is there a way to do this without converting the views to blocks/sketches?
Yes you can do it.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
DanPihlaja
Posts: 862
Joined: Thu Mar 11, 2021 9:33 am
Answers: 25
Location: Traverse City, MI
x 815
x 993

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by DanPihlaja »

gupta9665 wrote: Tue May 30, 2023 12:18 pm Yes you can do it.
How?

Every time I tried to change a component to a different layer, it changed it for every single view. I even toggling layer for a specific view didn't do anything, just changed the active layer.
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
User avatar
AlexB
Posts: 508
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 29
x 274
x 462

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by AlexB »

DanPihlaja wrote: Tue May 30, 2023 1:44 pm How?

Every time I tried to change a component to a different layer, it changed it for every single view. I even toggling layer for a specific view didn't do anything, just changed the active layer.
If you edit the component line font for the item shown in the view, you can select the layer and check "From Selection" to apply it to only the selected item in the selected view. It will move all of it's items to that layer prior to export.
image.png
After export to dxf (GIF, click to view)
Views On Different Layers.gif
User avatar
DanPihlaja
Posts: 862
Joined: Thu Mar 11, 2021 9:33 am
Answers: 25
Location: Traverse City, MI
x 815
x 993

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by DanPihlaja »

AlexB wrote: Tue May 30, 2023 2:20 pm If you edit the component line font for the item shown in the view, you can select the layer and check "From Selection" to apply it to only the selected item in the selected view. It will move all of it's items to that layer prior to export.
image.png

After export to dxf (GIF, click to view)
Views On Different Layers.gif
I stand corrected! Thank you!
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
User avatar
gupta9665
Posts: 420
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 438
x 459

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by gupta9665 »

AlexB wrote: Tue May 30, 2023 2:20 pm If you edit the component line font for the item shown in the view, you can select the layer and check "From Selection" to apply it to only the selected item in the selected view. It will move all of it's items to that layer prior to export.
image.png

After export to dxf (GIF, click to view)
Views On Different Layers.gif
Thank you for adding the images/explanation. I replied from the phone and didn't have SW in front at that moment.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
es2058
Posts: 6
Joined: Sun May 07, 2023 7:15 am
Answers: 0
x 1

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by es2058 »

Update.

I couldn't find the API to change the layer for the Component Line Font but was able to do it from this example:
https://help.solidworks.com/2016/englis ... ple_vb.htm

Here is what came up with:
*created the drawing templates with predefined views
*macro to take active model part and insert model into all the views of the drawing template
*save the file as DXF and close the drawing

Thanks for the help!
-------------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2

Sub main()
Dim boolstatus As Boolean
Dim swDrawing As SldWorks.DrawingDoc
Dim selMan As SldWorks.SelectionMgr
Dim drwView As SldWorks.View
Dim swDrawComp As SldWorks.DrawingComponent
Dim sRevision As String
Dim fileName As String
Dim longstatus As Long

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

'drawing template with predefined views
Set swDrawing = swApp.NewDocument("I:\Solidworks\DXF_LAYERS.drwdot", swDwgPaperSizes_e.swDwgPaperBsize, 0, 0)

'checks if active doc is a part
If (swModel.GetType <> swDocPART) Then GoTo CLEAN_UP
'inserts the current active model into the drawing template
swDrawing.InsertModelInPredefinedView swModel.GetPathName()

Set selMan = swDrawing.SelectionManager
'selects view and change view part layer
boolstatus = swDrawing.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set drwView = selMan.GetSelectedObject6(1, 0)
Set swDrawComp = drwView.RootDrawingComponent
swDrawComp.layer = "FRONT"

boolstatus = swDrawing.Extension.SelectByID2("Drawing View2", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set drwView = selMan.GetSelectedObject6(1, 0)
Set swDrawComp = drwView.RootDrawingComponent
swDrawComp.layer = "TOP"

boolstatus = swDrawing.Extension.SelectByID2("Drawing View3", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set drwView = selMan.GetSelectedObject6(1, 0)
Set swDrawComp = drwView.RootDrawingComponent
swDrawComp.layer = "RIGHT"

boolstatus = swDrawing.Extension.SelectByID2("Drawing View4", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set drwView = selMan.GetSelectedObject6(1, 0)
Set swDrawComp = drwView.RootDrawingComponent
swDrawComp.layer = "ISO"

boolstatus = swDrawing.Extension.SelectByID2("Drawing View5", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set drwView = selMan.GetSelectedObject6(1, 0)
Set swDrawComp = drwView.RootDrawingComponent
swDrawComp.layer = "LEFT"

boolstatus = swDrawing.Extension.SelectByID2("Drawing View6", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set drwView = selMan.GetSelectedObject6(1, 0)
Set swDrawComp = drwView.RootDrawingComponent
swDrawComp.layer = "BOTTOM"

boolstatus = swDrawing.Extension.SelectByID2("Drawing View7", "DRAWINGVIEW", 0, 0, 0, False, 0, Nothing, 0)
Set drwView = selMan.GetSelectedObject6(1, 0)
Set swDrawComp = drwView.RootDrawingComponent
swDrawComp.layer = "BACK"

'clear any selection
swModel.ClearSelection2 True

'fileName for dxf out put
fileName = swModel.GetPathName
fileName = Left(fileName, InStrRev(fileName, ".") - 1) & ".dxf"

' Save to dxf and close drawing
Set swModel = swDrawing
longstatus = swModel.SaveAs3(fileName, 0, 2)
swApp.QuitDoc (swModel.GetTitle)

'Clean up files
CLEAN_UP:
Set drwView = Nothing
Set swDrawing = Nothing
Set swModel = Nothing
End Sub
User avatar
gupta9665
Posts: 420
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 438
x 459

Re: Export Solidworks model views to dxf file layers instead of sheets

Unread post by gupta9665 »

I'm sure that this macro can be refined further to work without pre defined views and layers template. Will try my hands when I get some free time.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
Post Reply