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) |
Parameters
- Cookie
Cookie specified as defined in ISwAddin::ConnectToSW
- MethodName
Name of the application function used to save the file
- Description
File description
- Extension
Filename extension
- DocumentType
Type of document to save as defined in swDocumentTypes_e
Return Value
True if the item was added to the menu, false if not
Example
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))
Debug.Print
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
Do
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 "#extensions = " & lNumExtensionOccurrences
'
' There will be 1 real extension and n*2 non real extension
'
lNumNonRealExtensions = (lNumExtensionOccurrences \ 2)
If bVerbose Then Debug.Print "#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
Do
If bVerbose Then Debug.Print "Start = " & lStart
If (lStart = -1) Then
If bVerbose Then Debug.Print "Search string = " & strSearchString
Else
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
Example
Remarks
See Also
Availability
SolidWorks 2003 FCS, Revision Number 11.0