AnsweredAssumed Answered

Export DWG macro rotates view and adds un-needed text to filename

Question asked by Paul Flores on Mar 5, 2015
Latest reply on Mar 6, 2015 by Solidworks Selim

The macro below saves the current view of a part as a DWG file, and it also adds " (Current)" to the end of the file name.  For example,  "12345.sldprt" is saved as "12345 (Current).dwg".  I would like this macro to only save it as filename.dwg without adding the word current to it.

 

The other issue is that if a part is parallel to the X-Y plane, the exported DWG view matches the current view and is not rotated.  However, if the part is parallel to the Z-Y or X-Z plane then the exported DWG file is rotated 90 degrees.  Is it possible to save the view as a DWG without having it rotated, regardless of what plane the part view is?

 

Not sure if this matters, but these parts were not created with the sheet metal feature tool, the sketches were simply extruded. 

 

'Export Part View as DWG.swp -------------10/18/13

'Description: Macro to export part view as DWG.

'Precondition: Any active part file with some feature(s)

' Postconditions: DWG file of the current view orientation will be saved in the same location with same file name as the part.

'                 The file name may contains "(Current)"

' Please back up your data before use and USE AT OWN RISK

 

' This macro is provided as is.  No claims, support, refund, safety net, or

' warranties are expressed or implied.  By using this macro and/or its code in

' any way whatsoever, the user and any entities which the user represents,

' agree to hold the authors free of any and all liability.  Free distribution

' and use of this code in other free works is welcome.  If any portion of

' this code is used in other works, credit to the authors must be placed in

' that work within a user viewable location (e.g., macro header).  All other

' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited

' without the expressed written consent by the authors.  Use at your own risk!

' ------------------------------------------------------------------------------

' Written by: Deepak Gupta (http://gupta9665.com/)

' -----------------------------------------------------------------------------

Option Explicit

 

Dim swApp                   As SldWorks.SldWorks

Dim swModel                 As SldWorks.ModelDoc2

Dim swPart                  As SldWorks.PartDoc

Dim sModelName              As String

Dim sPathName               As String

Dim varAlignment            As Variant

Dim dataAlignment(11)       As Double

Dim varViews                As Variant

Dim dataViews(0)            As String

 

Sub main()

 

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swPart = swModel

 

dataAlignment(0) = 0#

dataAlignment(1) = 0#

dataAlignment(2) = 0#

dataAlignment(3) = 1#

dataAlignment(4) = 0#

dataAlignment(5) = 0#

dataAlignment(6) = 0#

dataAlignment(7) = 1#

dataAlignment(8) = 0#

dataAlignment(9) = 0#

dataAlignment(10) = 0#

dataAlignment(11) = 1#

 

varAlignment = dataAlignment

 

dataViews(0) = "*Current"

varViews = dataViews

 

sPathName = Left(swModel.GetPathName, Len(swModel.GetPathName) - 6)

 

swPart.ExportToDWG sPathName & "dwg", swModel.GetPathName, 3, False, varAlignment, False, False, 0, varViews

 

End Sub

Outcomes