Page 1 of 1

Export Solidworks model views to dxf file layers instead of sheets

Posted: Thu May 25, 2023 7:21 am
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.

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

Posted: Thu May 25, 2023 9:58 am
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.

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

Posted: Thu May 25, 2023 10:08 am
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.

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

Posted: Fri May 26, 2023 8:39 am
by es2058
Thanks, will try the drawing template and play around.

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

Posted: Fri May 26, 2023 10:17 am
by gupta9665
I just tested the template method and it works.
Views on Layer DXF.PNG

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

Posted: Tue May 30, 2023 11:28 am
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?

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

Posted: Tue May 30, 2023 11:42 am
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.

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

Posted: Tue May 30, 2023 12:18 pm
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.

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

Posted: Tue May 30, 2023 1:44 pm
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.

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

Posted: Tue May 30, 2023 2:20 pm
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

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

Posted: Tue May 30, 2023 2:33 pm
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!

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

Posted: Tue May 30, 2023 3:02 pm
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.

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

Posted: Mon Jun 05, 2023 9:12 am
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

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

Posted: Mon Jun 05, 2023 12:32 pm
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.