This is the final solution we made for the problem (thanks to the
SolidWorks API Support):
Dim swApp As SldWorks.SldWorks
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Dim TimeStamp As String
Dim FileExtension As String
Dim FileName As String
Private Declare Function GetSaveFileName _
Lib "COMDLG32.DLL" Alias "GetSaveFileNameA" _
(pOpenfilename As SAVEFILENAME) As Long
Private Type SAVEFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Sub Main()
Dim swModel As SldWorks.ModelDoc2
Dim strInitialFileName As String
Dim strFileName As String
Dim OFN As SAVEFILENAME
Dim strInitialName As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
TimeStamp = Format(Now, "HHmmss") 'Timestamp o.b.v. uren, minuten,
seconden
TimeStamp = Right(TimeStamp, 4) 'Timestamp o.b.v. minuten, seconden
strFileName = GetFileName(strInitialFileName, swModel.GetType)
'Filenaam creƫren
FileName = "_" & TimeStamp & FileExtension 'timestamp en extensie
combineren
With OFN
.lStructSize = Len(OFN) ' Size of structure.
.nMaxFile = 260 ' Size of buffer.
.lpstrInitialDir = "q:\"
.lpstrFile = FileName
.lpstrFilter = ("Part (*.prt;*.sldprt)")
Ret = GetSaveFileName(OFN) ' Call function.
If Ret <> 0 Then ' Non-zero is success.
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Part.SaveAs2 FileName, 0, False, False
Else: MsgBox ("Bestandsnaam is leeg of er is op Cancel gedrukt!")
End If
End With
End Sub
Private Function GetFileName(ByVal strInitialName As String, ByVal
nDocumentType As SwConst.swDocumentTypes_e) As String
' Initialize return value.
GetFileName = ""
' Setup error handling.
On Error GoTo FuncErr
' Set filter based on current document type.
Select Case nDocumentType
Case swDocumentTypes_e.swDocPART
FileExtension = ".sldprt"
Case swDocumentTypes_e.swDocASSEMBLY
FileExtension = ".sldasm"
Case swDocumentTypes_e.swDocDRAWING
FileExtension = ".slddrw"
Case Else
' HERE: unsupported type.
' Bail out.
Err.Raise 1
End Select
' Setup cancel handler.
On Error GoTo CancelHandler
FuncExit:
' Release.
Set cdFileDialog = Nothing
Exit Function
FuncErr:
Resume FuncExit
CancelHandler:
' HERE: user cancelled the dialog.
Resume FuncExit
End Function
End Function
Post by TonyYes, you can save the model and drawing docs through the API and assign new
names. It works like the save-as. The original documents retain their
original names. Prompt the user with a textbox, for a part name or input of
your choice. Then use that to save the document. Make sure you specify the
entire path along with the name. Not sure is this is what you're looking
for. I have the code at work if you need it. Look at
ModelDoc2.SaveAsSilent(newName As String, saveAsCopy As Boolean) As Long
Tony
Post by Markku LehtolaPost by GreenHexJust guessing, but would it be possible to remove the standard
save & saveAs menu items and replace it with your own dialog?
Vinodh Kumar M.
www.swCP3.com
I guess you can't use SaveAs or anything like that with own dialog...so
how you tell to it what you want to save...is the any API for this,
"TheWholeModelThatIsSaveble" :-) No idea. I still suggest that you go
around this problem and don't use commondialog or similar, but SaveAs and
msgboxes to ask the user for the filename.
--
regards
Markku
www.markkulehtola.net