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).
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.
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.
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.
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
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.
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.
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
T> > Just guessing, but would it be possible to remove the standard
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 =3D Application.SldWorks Set swModel =3D swApp.ActiveDoc
PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.