Hide Table of Contents
AddFileSaveAsItem2 Method (ISldWorks)

Adds a file type to the SOLIDWORKS Save As dialog box.

.NET Syntax

Visual Basic (Declaration) 
Function AddFileSaveAsItem2( _
   ByVal Cookie As System.Integer, _
   ByVal MethodName As System.String, _
   ByVal Description As System.String, _
   ByVal Extension As System.String, _
   ByVal DocumentType As System.Integer _
) As System.Boolean
Visual Basic (Usage) 
Dim instance As ISldWorks
Dim Cookie As System.Integer
Dim MethodName As System.String
Dim Description As System.String
Dim Extension As System.String
Dim DocumentType As System.Integer
Dim value As System.Boolean
value = instance.AddFileSaveAsItem2(Cookie, MethodName, Description, Extension, DocumentType)
System.bool AddFileSaveAsItem2( 
   System.int Cookie,
   System.string MethodName,
   System.string Description,
   System.string Extension,
   System.int DocumentType
System.bool AddFileSaveAsItem2( 
&   System.int Cookie,
&   System.String^ MethodName,
&   System.String^ Description,
&   System.String^ Extension,
&   System.int DocumentType



Cookie specified as defined in ISwAddin::ConnectToSW


Name of the application function used to save the file


File description


Filename extension


Type of document to save as defined in swDocumentTypes_e

Return Value

True if the item was added to the menu, false if not


The filename passed to the callback is not the true filename; it contains some additional information (shown in boldface in the following line): 

"E:\Folder\Assembly1.EXT Assembly1EXT w"


The following example shows how to parse this string and extract the true filename and filename extension:


Option Explicit

Sub Main()

    Dim lIdx              As Long
    Dim strFileNames(6)   As String
    strFileNames(0) = "C:\temp\Assem.EXT AssemEXT w"
    strFileNames(1) = "C:\temp\Assem.ext1.EXT Assem.ext1EXT w"
    strFileNames(2) = "C:\temp\Assem.ext2.ext1.EXT Assem.ext2.ext1EXT w"
    strFileNames(3) = "C:\temp\Assem 1.EXT Assem 1EXT w"
    strFileNames(4) = "C:\temp\Assem1 .EXT Assem1 EXT w"
    strFileNames(5) = "
\\aserver\temp\Assem.EXT AssemEXT w"
    strFileNames(6) = "Assem.EXT AssemEXT w"
    For lIdx = LBound(strFileNames) To UBound(strFileNames)    
        Debug.Print ParseFilename(strFileNames(lIdx))
    Next lIdx
End Sub

Public Function ParseFilename(ByVal strFileName As String) As String

    Dim strExtension              As String
    Dim lPos                      As Long
    Dim lNumExtensionOccurrences  As Long
    Dim lStart                    As Long
    Dim strSearchString           As String
    Dim lNumNonRealExtensions     As Long
    Dim strExtensionWithPeriod    As String
    Dim bVerbose                  As Boolean
    ' Set return value
    ParseFilename = ""
    bVerbose = True
    ' Set the extension for which to look
    strExtension = "ext"
    strExtensionWithPeriod = "." & strExtension   
    If bVerbose Then Debug.Print "Raw string = " & strFileName
    ' Strip the trailing 'w' or 'r' and any leading and trailing white space
    strFileName = Trim$(Left$(strFileName, Len(strFileName) - 1))
    If bVerbose Then Debug.Print "After 'w'/'r' removal = " & strFileName
    ' Strip extension from the back
    strFileName = Trim$(Left$(strFileName, Len(strFileName) - Len(strExtension)))
    If bVerbose Then Debug.Print "After extension removal = " & strFileName
    ' Find all occurrences of extension and period
    ' Change to lowercase to make search case-insensitive
    strSearchString = LCase$(strFileName)
    lNumExtensionOccurrences = 0
    lStart = 1
        If bVerbose Then Debug.Print "Start = " & lStart
        If bVerbose Then Debug.Print "Search string = " & Mid$(strSearchString, lStart)
        lPos = InStr(lStart, strSearchString, LCase$(strExtensionWithPeriod))
        If (lPos > 0) Then
            lNumExtensionOccurrences = lNumExtensionOccurrences + 1
            ' Move start point of search
            lStart = lPos + Len(strExtensionWithPeriod)
        End If
    Loop While (lPos > 0)
    If bVerbose Then Debug.Print "solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks~addfilesaveasitem2.html#extensions = " & lNumExtensionOccurrences
    ' There will be 1 real extension and n*2 non real extension
    lNumNonRealExtensions = (lNumExtensionOccurrences \ 2)
    If bVerbose Then Debug.Print "solidworks.interop.sldworks~solidworks.interop.sldworks.isldworks~addfilesaveasitem2.html#non-real extensions = " & lNumNonRealExtensions
    ' Start searching from the end to locate the real extension
    ' Skip the number of non-real extensions, before reaching he real extension
    ' Change to lowercase to make search case-insensitive
    strSearchString = LCase$(strFileName)
    lStart = -1
        If bVerbose Then Debug.Print "Start = " & lStart
        If (lStart = -1) Then
            If bVerbose Then Debug.Print "Search string = " & strSearchString
            If bVerbose Then Debug.Print "Search string = " & Left$(strSearchString, lStart)
        End If
        lPos = InStrRev(strSearchString, LCase$(strExtensionWithPeriod), lStart)
        If (lPos > 0) Then
            lNumNonRealExtensions = lNumNonRealExtensions - 1
            ' Move start point of search
            lStart = lPos - 1
        End If
    Loop While ((lPos > 0) And (lNumNonRealExtensions >= 0))
    ' HERE: lStart points to the start of real extension
    If bVerbose Then Debug.Print "Filename = " & Left$(strFileName, lStart) & strExtensionWithPeriod
    ParseFilename = Left$(strFileName, lStart) & strExtensionWithPeriod
End Function




If your application is unloaded using the Add-In Manager, then you must remove any file types added with this method using ISldWorks::RemoveFileSaveAsItem2.


See Also


SOLIDWORKS 2003 FCS, Revision Number 11.0

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   AddFileSaveAsItem2 Method (ISldWorks)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2015 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.