Jump to content

Saving file to specific folder


Recommended Posts

I'm editing STL CAD files in Blender and I'm trying to save these stl files to a project folder in my document folder. I have a script that can initiate the save as command and enter the file name but I want to do it in a way that when the save as window pops up, it will go to the folder of my choice. Can someone help me in figuring out how to change the save as path?

$ProjectNumber = InputBox("Enter Project Number", "Project Number")
$ProjectName = "Project - " & $ProjectNumber &".stl"
$FolderPath = "D:\Documents\ProjectFolder"

Send("^s")

Sleep(100)
WinWait("Save Part(s) As")
WinActivate("Save Part(s) As")
Sleep(100)
ControlSend("Save Part(s) As", "", '[ID:1001]', $ProjectName)
Sleep(100)
ControlClick ("Save Part(s) As", "&Save", "[ID:1]", "left", 1)

 

Link to comment
Share on other sites

13 minutes ago, KickStarter15 said:

Why not use FileSaveDialog() to save file in your own choice.

I tried that method but all I get is a save as window that pops up and the controlsend function doesn't seem to work where no file name is entered into the text box. Unless I'm doing something wrong. Here's my code for that part. When I do try to save the file manually when the save as window pops up, nothing is saved.

Another method that I also thought of was to use FileCopy but I can't seem to think of a way to get the current saved path location of the active stl. As I will be editing different stl files from different locations and there should be a way to locate the path location of the active stl in current use without having to manually input it.

$ProjectNumber = InputBox("Enter Project Number", "Project Number")
$ProjectName = "Project - " & $ProjectNumber &".stl"
$FolderPath = "D:\Documents\ProjectFolder"

FileSaveDialog("Save Part(s) As", $FolderPath, "STL (COLOR) files (*.stl)")
Sleep(100)
WinWait("Save Part(s) As")
WinActivate("Save Part(s) As")
Sleep(100)
ControlSend("Save Part(s) As", "", '[ID:1001]', $ProjectName)
Sleep(100)
ControlClick ("Save Part(s) As", "&Save", "[ID:1]", "left", 1)

 

Edited by imagine
Link to comment
Share on other sites

FileCopy() function file must exist to work with your code.

In order to use FileSaveDialog() as what you wanted, need to create the file .stl.

Try this:

#Include <File.au3>
$ProjectNumber = InputBox("Enter Project Number", "Project Number")
$ProjectName = "Project - " & $ProjectNumber &".stl"
$FolderPath = "D:\Documents\ProjectFolder"

$FilePath = FileSaveDialog("Save Part(s) As", $FolderPath, "STL (COLOR) files (*.stl)")
_FileCreate($FilePath&".stl")
Sleep(100)
WinWait("Save Part(s) As")
WinActivate("Save Part(s) As")
Sleep(100)
ControlSend("Save Part(s) As", "", '[ID:1001]', $ProjectName)
Sleep(100)
ControlClick ("Save Part(s) As", "&Save", "[ID:1]", "left", 1)

 

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

3 hours ago, Subz said:

So what software are you using to do "Save Part(s) As", I have Blender but it doesn't appear to have the same Ids as your OP.

Sorry, it's actually Solidworks, don't know why I was thinking of Blender, late night I guess.

Link to comment
Share on other sites

10 hours ago, KickStarter15 said:

FileCopy() function file must exist to work with your code.

In order to use FileSaveDialog() as what you wanted, need to create the file .stl.

Try this:

#Include <File.au3>
$ProjectNumber = InputBox("Enter Project Number", "Project Number")
$ProjectName = "Project - " & $ProjectNumber &".stl"
$FolderPath = "D:\Documents\ProjectFolder"

$FilePath = FileSaveDialog("Save Part(s) As", $FolderPath, "STL (COLOR) files (*.stl)")
_FileCreate($FilePath&".stl")
Sleep(100)
WinWait("Save Part(s) As")
WinActivate("Save Part(s) As")
Sleep(100)
ControlSend("Save Part(s) As", "", '[ID:1001]', $ProjectName)
Sleep(100)
ControlClick ("Save Part(s) As", "&Save", "[ID:1]", "left", 1)

 

With your modification, the save as window pops up but it stops at the ControlSend command. I can manually type in the file name and manually click the save button but the file that is saved has no data (0 KB) in it.

Yes, FileCopy() is probably the best way to do. But I just need to figure out how to get the source path of the file without having to manually input it in every time.

I can save the stl file to whatever the current folder it currently presides in but to copy from that folder to another is a problem since there are 4 other stl files in that same folder as well and I just want to copy only one.

Edited by imagine
More ideas came into my mind
Link to comment
Share on other sites

Have a copy of SolidWorks 2017 as well and was able to get it to work for me using the following code:

Local $sProjectPath = "D:\Documents\ProjectFolder\"
    ;~ Check if the project path exists
    If FileExists($sProjectPath) = 0 Then DirCreate($sProjectPath)
;~ Create full project path e.g. D:\Documents\ProjectFolder\Project - 1234.stl
Local $sProjectName = $sProjectPath & _ProjectName()

;~ Wait until SolidWorks window is active
Local $hSWorks = WinWaitActive("SOLIDWORKS", "")
;~ Send Alt + FA for Save As Dialogue
ControlSend($hSWorks, "", "", "!FA")

;~ Wait until SolidWorks "Save As" window is active
Local $hSWSaveAs = WinWaitActive("Save As",  "")

;~ ComboBox appears to change, so target both to set the Save As File Type
ControlCommand($hSWSaveAs, "", "ComboBox1", "SelectString", "STL")
ControlCommand($hSWSaveAs, "", "ComboBox2", "SelectString", "STL")
;~ Set the Save As full file path
ControlSetText($hSWSaveAs, "", "Edit1", $sProjectName)
;~ Send Alt + s to Save the document
ControlSend($hSWSaveAs, "", "", "!s")

Func _ProjectName()
    Local $iProjectName = InputBox("Enter Project Number", "Project Number", "", "", 200, 130)
    If @error = 1 Or $iProjectName = "" Then Exit
    Return "Project - " & $iProjectName & ".stl"
EndFunc

 

Link to comment
Share on other sites

  • 2 years later...
On 3/10/2017 at 10:43 PM, imagine said:

I want to do it in a way that when the save as window pops up, it will go to the folder of my choice.

The answer to your question - look at Steps I.a, I.b, II and IV

 

I took me a while but finally figured it out for my project, hope someone could benefit from this. It turns out the Address Bar for folder path is a combo of (Toolbar buttons and an Edit box). I don't know the actual structures but the way I visualizing it is; Edit box is nested inside ToolbarWindow32. When address bar (ToolbarWindow32) is clicked to Manually input your own Path then Edit box is activated. Imagine ToolbarWindow32 is the parent and Edit box is the child. Anyone with the knowledge please shed some light into this.

Once the script is executed notice the Address Bar has changed to 'C:\_DOC\_TEXT'

#include <GuiToolbar.au3>
#Include <File.au3>

_Change_SaveAs_Diaglog_FolderPath()

Func _Change_SaveAs_Diaglog_FolderPath()

    Run('Notepad.exe')
    Local $aTitle = '[CLASS:Notepad; TITLE:Untitled - Notepad]'
    WinWaitActive($aTitle)
    ControlSetText($aTitle,'','Edit1','new line.')
    WinMenuSelectItem($aTitle,'','&File','&Save')


    Local $AddressPath = 'C:\_DOC\_TEXT'
    Local $aFileName = 'New File.txt'
    ClipPut($AddressPath)                   ;for  Option 1

    Local $SaveAsTitle = '[CLASS:#32770; TITLE:Save As]'


# I.a

    ;get 'Save As' window handle
    Local $hWnd = WinWaitActive($SaveAsTitle, '&Save', 10)

# I.b

    ;get Address Bar handle for $AddressPath
    Local $hTollbars = ControlGetHandle($hWnd, 'Address', '[CLASSNN:ToolbarWindow324]')


# II - IMPORTANT: Address Bar must be infocus in order to activate Edit2 to set $AddressPath in step (IV)
       ;Option 2 or 3 is highly recommended


    # ;Option 1 - Select ToolbarWindow32 - Address Bar (work around -not recomended)
    #------------------------------------------------------------------------------
;~      ControlFocus($hTollbars, 'Address', '')
;~      ControlSend($hTollbars, 'Address', '','{SPACE}')
;~      Send('^v{ENTER}')

    # ;Option 2 - Select ToolbarWindow32 - Address Bar (same as Option 3)
    #-------------------------------------------------------------------
        ControlCommand($hTollbars, "Address", "", "SendCommandID", 1280)

    # ;Option 3 - Select ToolbarWindow32 - Address Bar (same as Option 2)
    #------------------------------------------------------------------------------------------
;~      ControlCommand($hWnd, "Address", "ToolbarWindow324", "SendCommandID", 1280)

    # ;Option 4 - Select ToolbarWindow32 - Address Bar (mouse pointer also relocated)
    #------------------------------------------------------------------------------------------
;~      _GUICtrlToolbar_ClickIndex($hTollbars, -1,'Left',True,1,0)

    # ;Option 5 - Select ToolbarWindow32 - Address Bar (this simulate as Run, NOT RunWait if your project required it - NOT Recommended)
    #------------------------------------------------------------------------------------------
;~      Run(@AutoItExe & ' /AutoIt3ExecuteLine "ControlCommand ( hwnd(' & $hWnd & '),'''', hwnd(' & $hTollbars & '), ''SendCommandID'', 1280 )"')


# III
        ;check if path $AddressPath exists
        If Not FileExists($AddressPath) Then DirCreate($AddressPath)

# IV
        ;set new path
        ControlSetText($hWnd, "Address", 'Edit2', $AddressPath)
;~      ControlFocus($hTollbars,'Address','')


# V
        ;commit new Path
        ControlSend($hWnd, "Address", 'Edit2','{ENTER}')

# VI
        ;set new file name
        ControlSetText($hWnd, "Namespace", "Edit1", $aFileName)
        ControlFocus($hWnd,'Namespace','Edit1')

# VII
        ;allow manual keypress {SPACE} or {ENTER} to save/cancel
;~      ControlFocus($hWnd,'&Save','Button1')
;~      ControlFocus($hWnd,'Cancel','Button2')

# VIII
        ;auto click save/cancel
;~      ControlClick($hWnd,"&Save", 'Button1','Left')
;~      ControlClick($hWnd,"Cancel", 'Button2','Left')


# IX
    #--------------------------------------------------
    # ---OR--- skip all above steps and use this work around
    #--------------------------------------------------
;~  ControlSetText($hWnd, "Namespace", "Edit1", $AddressPath&'\'&$aFileName)

EndFunc

 

Link to comment
Share on other sites

  • Developers

@zeenmakr,

As stated in my email to you a couple of minutes ago: Just focus on new thread when you like to help members posting questions or problems.
People tend to come in, dump a question and leave again like in this particular thread. member imagine registered on march 3, 2017 and last visited march 27, 2017!
So you understand it really serves no purpose answering tis after 2+ years. ;) 

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...