Export Solidworks model views to dxf file layers instead of sheets
Export Solidworks model views to dxf file layers instead of sheets
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.
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
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.
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
SOLIDWORKS Consultant/Blogger
- DanPihlaja
- Posts: 862
- Joined: Thu Mar 11, 2021 9:33 am
- Location: Traverse City, MI
- x 815
- x 993
Re: Export Solidworks model views to dxf file layers instead of sheets
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)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 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
Solidworks 2022 SP4
2 Corinthians 13:14
Re: Export Solidworks model views to dxf file layers instead of sheets
Thanks, will try the drawing template and play around.
Re: Export Solidworks model views to dxf file layers instead of sheets
I just tested the template method and it works.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Export Solidworks model views to dxf file layers instead of sheets
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?
- DanPihlaja
- Posts: 862
- Joined: Thu Mar 11, 2021 9:33 am
- Location: Traverse City, MI
- x 815
- x 993
Re: Export Solidworks model views to dxf file layers instead of sheets
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
Solidworks 2022 SP4
2 Corinthians 13:14
Re: Export Solidworks model views to dxf file layers instead of sheets
Yes you can do it.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
- DanPihlaja
- Posts: 862
- Joined: Thu Mar 11, 2021 9:33 am
- Location: Traverse City, MI
- x 815
- x 993
Re: Export Solidworks model views to dxf file layers instead of sheets
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
Solidworks 2022 SP4
2 Corinthians 13:14
Re: Export Solidworks model views to dxf file layers instead of sheets
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. After export to dxf (GIF, click to view)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.
- DanPihlaja
- Posts: 862
- Joined: Thu Mar 11, 2021 9:33 am
- Location: Traverse City, MI
- x 815
- x 993
Re: Export Solidworks model views to dxf file layers instead of sheets
I stand corrected! Thank you!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
-Dan Pihlaja
Solidworks 2022 SP4
2 Corinthians 13:14
Solidworks 2022 SP4
2 Corinthians 13:14
Re: Export Solidworks model views to dxf file layers instead of sheets
Thank you for adding the images/explanation. I replied from the phone and didn't have SW in front at that moment.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
Deepak Gupta
SOLIDWORKS Consultant/Blogger
SOLIDWORKS Consultant/Blogger
Re: Export Solidworks model views to dxf file layers instead of sheets
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
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
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
SOLIDWORKS Consultant/Blogger