Discussion:
VB code for for activating the save dialog
(too old to reply)
h***@gmail.com
2005-09-21 10:34:39 UTC
Permalink
Can somebody tell me which code should be used to pop up the "save as"
dialog box and fill the field with something like "test.sldprt"?

All I want to do is give the user the possibility to change the
proposed file name into something else. So I have to pop up the save
dialog box instead of saving the document immediately.

It seems to me something very simple, but I couldn't find any
documentation about it.
Markku Lehtola
2005-09-21 10:40:28 UTC
Permalink
Post by h***@gmail.com
Can somebody tell me which code should be used to pop up the "save as"
dialog box and fill the field with something like "test.sldprt"?
All I want to do is give the user the possibility to change the
proposed file name into something else. So I have to pop up the save
dialog box instead of saving the document immediately.
It seems to me something very simple, but I couldn't find any
documentation about it.
I asked this while ago from the API support and...it's not possible to
fill in the filename...so I guess there is no point to show the dialog
either (that is possible I guess).
--
Markku Lehtola

www.markkulehtola.net
TVO
2005-09-21 11:01:49 UTC
Permalink
Try to look at the CommonDialog Control and program your "own" saveas.
It should be possible to fill in your desired filename.
If it is not available you have to make a reference to it - RMB in
toolbox (forms) and it should be in the list if you have the right file
"C:WINNT\system32\comdlg32.ocx". Not sure but maybe you have to install
Visual Basic first.

Good luck
Thomas
h***@gmail.com
2005-09-21 13:19:51 UTC
Permalink
Unfortunately I need VB6 for this. And I don't have VB6.
And even when I had VB6, I had to program a complex form with all the
options which are now at the standard save as dialog box.
I am afraid I don't have the programming skills to make this.

Maybe a freeware tool to do the job?
Post by TVO
Try to look at the CommonDialog Control and program your "own" saveas.
It should be possible to fill in your desired filename.
If it is not available you have to make a reference to it - RMB in
toolbox (forms) and it should be in the list if you have the right file
"C:WINNT\system32\comdlg32.ocx". Not sure but maybe you have to install
Visual Basic first.
Good luck
Thomas
That70sTick
2005-09-21 14:57:09 UTC
Permalink
There is a way to invoke Common Dialog with VBA/macro. It involves
using Windows API. I have done this many times.

Try a Google search using keywords: VBA API Windows Common Dialog.

Learning some Windows API manipulation can really extend your macro
capability by allowing you to call objects that are normally only
available to licensed VB6 users. Yes, it's legal.
Matze
2005-09-22 22:42:11 UTC
Permalink
Post by h***@gmail.com
Unfortunately I need VB6 for this. And I don't have VB6.
And even when I had VB6, I had to program a complex form with all the
options which are now at the standard save as dialog box.
I am afraid I don't have the programming skills to make this.
Maybe a freeware tool to do the job?
Maybe something like this:

Option Explicit

Dim swApp As Object
Sub main()
Dim i As Integer
Set swApp = Application.SldWorks
SendKeys "%{F}" 'invoke file menu
For i = 0 To 6 'go down to the saveas dialog
SendKeys "{down}"
Next i
SendKeys "{enter}" 'enter
End Sub

ok, not very elegant but it does the job.

M.
h***@gmail.com
2005-09-23 07:37:45 UTC
Permalink
This is only a part of the solution, because the file name in the file
name field should be filled with someting dynamic. And this is not
possible with the standard save as dialog.
GreenHex
2005-09-23 16:43:58 UTC
Permalink
Just 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
Markku Lehtola
2005-09-23 17:07:42 UTC
Permalink
Post by GreenHex
Just 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
Tony
2005-09-28 22:13:44 UTC
Permalink
Yes, 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 Lehtola
Post by GreenHex
Just 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
h***@gmail.com
2005-10-11 14:55:17 UTC
Permalink
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 Tony
Yes, 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 Lehtola
Post by GreenHex
Just 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
m***@gmail.com
2005-09-21 15:45:14 UTC
Permalink
yep, Not with the SW APIs but Win32 API
I did it "long time ago" with sw03
http://www.programming.e-cnc.com
yes, you need vb6 and bit skills to subclass SW save as dialog

Mike
h***@gmail.com
2005-09-22 06:33:30 UTC
Permalink
Unfortunately, there is no download link for you SWMenuini.zip...
Post by m***@gmail.com
yep, Not with the SW APIs but Win32 API
I did it "long time ago" with sw03
http://www.programming.e-cnc.com
yes, you need vb6 and bit skills to subclass SW save as dialog
Mike
Loading...