API / Macro Help

Jun 21, 2004 1 Replies

I recorded a macro to save our drawing files as DWG files. This is pretty simple stuff. However, the file name of the open drawing was recorded into the macro, and I am trying to get the code so solidworks just grabs the current file name to save as DWG instead of the recorded name. I don't really have any knowledge of VB or the solidworks API.



Thanks,



Justin


Here's a macro I modified to export a dwg file for every sheet in the drawing. It also rebuilds each sheet, adds a sheet number and the revision level to the file name. Maybe you can find what you need in it, or modify it to do what you want. Be sure to correct the word wrapping if you paste it into a macro file.

Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2

Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc If swModel.GetType 3 Then swApp.SendMsgToUser "Run this on a .SLDDRW file, you silly person!" Exit Sub End If

Dim SheetNames As Variant Dim SheetCount As Integer Dim i As Integer Dim ActiveView As Object 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 strRevLevel As String ' Show current settings Debug.Print "DxfMapping = " & swApp.GetUserPreferenceToggle(swDxfMapping) Debug.Print "DXFDontShowMap = " & swApp.GetUserPreferenceToggle(swDXFDontShowMap) Debug.Print "DxfVersion = " & swApp.GetUserPreferenceIntegerValue(swDxfVersion) Debug.Print "DxfOutputFonts = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputFonts) Debug.Print "DxfMappingFileIndex = " & swApp.GetUserPreferenceIntegerValue(swDxfMappingFileIndex) Debug.Print "DxfOutputLineStyles = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputLineStyles) Debug.Print "DxfOutputNoScale = " & swApp.GetUserPreferenceIntegerValue(swDxfOutputNoScale) Debug.Print "DxfMappingFiles = " & swApp.GetUserPreferenceStringListValue(swDxfMappingFiles) Debug.Print "DxfOutputScaleFactor = " & swApp.GetUserPreferenceDoubleValue(swDxfOutputScaleFactor) Debug.Print "" ' Turn off showing of map bShowMap = swApp.GetUserPreferenceToggle(swDXFDontShowMap) Debug.Print "bShowMap = " & bShowMap swApp.SetUserPreferenceToggle swDXFDontShowMap, True 'get all sheet names SheetNames = swModel.GetSheetNames 'get total number of sheets SheetCount = swModel.GetSheetCount 'Get revision strRevLevel = swModel.CustomInfo2("", "Revision") For i = 0 To SheetCount - 1 ' active first sheet retval = swModel.ActivateSheet(SheetNames(i)) swModel.GraphicsRedraw2

'loop through all views and update Set ActiveView = swModel.GetFirstView Do While Not ActiveView Is Nothing If ActiveView.IsModelOutOfDate = True Then retval = swModel.EditRebuild3 End If Set ActiveView = ActiveView.GetNextView Loop ' Strip off SolidWorks drawing file extension (.slddrw) ' and add DXF file extension (.dxf) sPathName = swModel.GetPathName If sPathName = "" Then swApp.SendMsgToUser ".SLDDRW file be saved first" Exit Sub End If sPathName = Left(sPathName, Len(sPathName) - 7) sPathName = sPathName & " Rev_" & strRevLevel & " SH_" & Format ((i + 1), "000") & ".dwg" 'export sheet to dwg bRet = swModel.SaveAs4(sPathName, _ swSaveAsCurrentVersion, _ swSaveAsOptions_Silent, _ nErrors, _ nWarnings) Next swApp.SendMsgToUser "View updates complete." ' 'Get the current sheet name ' CurrentSheetName = CurrentSheet.GetName Set ActiveView = Nothing Set ActiveNote = Nothing End Sub

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required