imagine

Saving file to specific folder

8 posts in this topic

#1 ·  Posted

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)

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted

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)

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

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.

Share this post


Link to post
Share on other sites

#6 ·  Posted

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#8 ·  Posted

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

 

Share this post


Link to post
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