AnsweredAssumed Answered

Example macro to export dwg with "set custom map file"

Question asked by Mario Zahren on Jun 19, 2015
Latest reply on Oct 9, 2015 by Yong Ning

Hello all,

 

I need an example to save a SolidWorks-Drawing as a DWG. Therefore it is necessary to use a mappingfile to map SolidWorks drawing entities and colors to layers when saving the drawing.

 

Any help would be appreciated.

 

Cheers

Mario

 

Here is the code I use so far:

 

Option Explicit

 

    Dim swApp                   As SldWorks.SldWorks

     Dim swModel                 As SldWorks.ModelDoc2

     Dim sPathName               As String

     Dim nErrors                 As Long

     Dim nWarnings               As Long

     Dim nRetval                 As Long

     Dim bShowMap                As Boolean

     Dim bRet                    As Boolean

     Dim CustomerA               As String

     Dim Index                   As Boolean

 

Sub main()

 

     Set swApp = Application.SldWorks

     Set swModel = swApp.ActiveDoc

 

     ' Strip off SolidWorks drawing file extension (.slddrw)

     ' and add DXF file extension (.dxf)

     sPathName = swModel.GetPathName

     sPathName = Left(sPathName, Len(sPathName) - 6)

     sPathName = sPathName + "dwg"

     CustomerA = "\\hgntsrv11\Solidworks\Dateipositionen\DXF_DWG_Abbildungsdatei\HME_Abbildungsdatei.txt"

 

    ' Turn off showing of map

     bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap)

 

     swApp.SetUserPreferenceToggle swDXFDontShowMap, False

 

     bRet = swApp.SetUserPreferenceStringValue(swDxfMappingFiles, CustomerA)

 

 

               swApp.SetUserPreferenceStringListValue swDxfMappingFiles, CustomerA

 

               Index = swApp.GetUserPreferenceIntegerValue(swDxfMappingFileIndex)

 

               If (Index = -1) Then

 

               swApp.SetUserPreferenceIntegerValue swDxfMappingFileIndex, 0

 

               End If

 

 

     bRet = swModel.SaveAs4(sPathName, swSaveAsCurrentVersion, swSaveAsOptions_Silent, nErrors, nWarnings)

      

     If bRet = False Then

         nRetval = swApp.SendMsgToUser2("Problems saving file.", swMbWarning, swMbOk)

     End If

 

    ' Restore showing of map

     swApp.SetUserPreferenceToggle swDXFDontShowMap, bShowMap

 

End Sub

 

I´m having trouble integrating the map file "CustomerA"

Can anybody help?

 

Mario

Outcomes