Jump to content

User Select Files - Open AutoCAD run Script


Recommended Posts

Hello all new to autoit but seems like a very nifty program to be able to write scripts to save alot of users time.

What i am after is to be able to run a .exe to allow the user to select files in the folder he/she specifies and then runs an autocad script on each of the selected files.

This is what i have so far from general browsing over the forums..

#Include
#Include
#include
$MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
$message = "Hold down Ctrl or Shift to choose multiple files."
$var = FileOpenDialog($message, $MyDocsFolder & "\", "All Files (*.dwg*)", 1 + 4 )
If @error Then
MsgBox(4096,"","No File(s) chosen")

This part allowing the user to select .dwg files from any location he/she wants with performing error message if no files selected. The idea i got was from an Autodesk University tutorial for being able to run scripts through .bat programs though I don't think its possible for .bat files to be able to have user specify files. The Code below is from the .bat functions (where path is the directory the script is stored)

For %%f in (path\*.dwg) do start /wait C:\"Program Files"\"AutoDesk"\"AutoCad 2013"\acad.exe "%%f" /b path\scriptname.scr

Run ('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "path\scriptfilename.scr"')

This is where i got to with AutoIT being able to open up AutoCAD and being able to run a script though how do you go about setting the files previously selected as variables so you can tell AutoCAD to open each file and run the script.

Thanks for taking the time to read this and all help is much appreciated :)

Mark.

Link to comment
Share on other sites

Maybe this?

$message = "Hold down Ctrl or Shift to choose multiple files."
$var = FileOpenDialog($message, @MyDocumentsDir, "All Files (*.dwg*)", 1 + 4)
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
EndIf
ConsoleWrite($var & @CRLF) ;For Debug Only
Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "' & $var & '"')

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Nessie, this allows the user to select files then open the files up but what it is trying to do is open multiple files at once so if drawing1.dwg and drawing2.dwg were selected it trys to open drawing1.dwgdrawing2.dwg as one file and then it is not recognized.

Link to comment
Share on other sites

Actually even if one file is selected it still says invalid file name it is storing the file name information but not the path of the file so it the users selects c:folder1drawing1.dwg it tries to just open drawing1.dwg and cannot find any path.

Link to comment
Share on other sites

Try this:

;#include <Array.au3> ;Needed only for _ArrayDisplay

$message = "Hold down Ctrl or Shift to choose multiple files."
$var = FileOpenDialog($message, @MyDocumentsDir, "All Files (*.dwg*)", 1 + 4)
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
EndIf
;ConsoleWrite($var & @CRLF) ;For Debug Only

If StringInStr($var, "|") Then ;Multiple file
    $split = StringSplit($var, "|")
    ;_ArrayDisplay($split)
    For $i = 2 To UBound($split) - 1
        $file_path = @WorkingDir & "\" & $split[$i]
        ;ConsoleWrite('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "' & $file_path & '"' & @CRLF)
        Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "' & $file_path & '"')
    Next
Else
    Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "' & $var & '"')
EndIf

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Hi :)

This is grabbing the file path but now it is grabbing it multiple times, C:Folder1C:Folder1drawing1.dwg.

Also to run the script I would assume that this would be the correct function?

Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" "' & $file_path & '"') /b c:\scriptfolder\script.scr

thanks for your help :)

Link to comment
Share on other sites

Check out now the code to the my previous message ;)

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

I have tried multiple variations of how to get it to open the folderdrawing.dwg but with the modified code of yours it still only tries to open drawing.dwg no path - then if u add @workingdir it then brings up the @workingdir@workingdirdrawing.dwg

Same thing happens if you select multiple files the program opens two versions of itself and then only opens drawing.dwg with no path information

very confusing haha

Edited by wheats
Link to comment
Share on other sites

This is what i get with multiple file:

"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "C:\Test\a.dwg"
"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "C:\Test\b.dwg"
"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "C:\Test\c.dwg"

And with only one file:

"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "C:\Test\a.dwg"

Is that the output that you want?

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Yes this is the output I am after though this does not work for me.

I just removed the /b from the code and it opens for the file correctly.

"C:Program FilesAutoDeskAutoCad 2013acad.exe" "C:Testa.dwg" - opens "C:Testa.dwg"

and with the /b in the code

"C:Program FilesAutoDeskAutoCad 2013acad.exe" /b "C:Testa.dwg" - opens "a.dwg"

The /b is obviously having a impact on the opening of the file in regards to its path directory. The /b is a start up switch for AutoCAD telling the program batch process - so hopefully it should only open up one copy of the program and process each file at a time.

-- This is where i original got the code for the .bat program ---

md c:datafilesCP12-3Ldwgwb

FOR %%f in (c:datafilesCP12-3Ldwg*.dwg) do start /wait c:”program

files””AutoCAD 2006”acad.exe “%%f” /b c:datafilesCP12-3Lwbout.scr

What does this all mean?

The first line creates a new folder (directory, sub-directory) name “wb” within an existing folder, so the new

versions of the drawing files can be placed there until their integrity is confirmed.

The replaceable parameter %%f represents the name of each specified file within the folder named

“c:datafilesCP12-3Ldwg.” Each .dwg file in that location will be processed in alphabetical order as it is set to the

replaceable parameter %%f. %%f will then be used in the second portion of the line as a variable, changing with

each pass to the next drawing name. The START /WAIT option starts a windows application and returns control

to the batch file when done. Acad.exe is the windows application that is being started.

AutoCAD will now start and open each drawing. Because of the /b switch, the script file named “wbout.scr” will run

every time AutoCAD starts. When all files with a .dwg extension have been processed (made equal to variable

%%f), the program will stop.

Note: the path given to locate the “acad.exe” file is not necessary unless there is more than one acad.exe file on

the computer. This could happen if you have multiple releases of AutoCAD or if you have one or more vertical

applications on your computer, as is the case for the computers in this lab. It is generally better to be precise in

giving a path. The quotation marks within the batch file are required to compensate for spaces in the names of

files or folders. Putting quotes around the second occurrence of %%f allows you to process drawing files that

have spaces within their names as well. Place the quotations exactly as shown.

Link to comment
Share on other sites

So if i have understand well it's not my code the problem. But it's the string that launch AutoCAD the issue. Can you confirm this?

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Try this:

;#include <Array.au3> ;Needed only for _ArrayDisplay

$message = "Hold down Ctrl or Shift to choose multiple files."
$var = FileOpenDialog($message, @MyDocumentsDir, "All Files (*.dwg*)", 1 + 4)
If @error Then
MsgBox(4096, "", "No File(s) chosen")
Exit
EndIf
;ConsoleWrite($var & @CRLF) ;For Debug Only

If StringInStr($var, "|") Then ;Multiple file
$split = StringSplit($var, "|")
;_ArrayDisplay($split)
For $i = 2 To UBound($split) - 1
$file_path = @WorkingDir & "\" & $split[$i]
;ConsoleWrite('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" /b "' & $file_path & '"' & @CRLF)
Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" "' & $file_path & '" /b "c:\datafiles\CP12-3L\wbout.scr"')
Next
Else
Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" "' & $var & '" /b "c:\datafiles\CP12-3L\wbout.scr"')
EndIf

I have only changed the string inside Run function ;)

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Yeah this works now :) for a single file, thought the script section doesn't.

If you select multiple files it goes back to the original problem of only opening "a.dwg" "b.dwg" and not "C:Testa.dwg" and "C:Testb.dwg

I think the start wait command controls the program to open the files 1 at a time ?

%%f will then be used in the second portion of the line as a variable, changing with

each pass to the next drawing name. The START /WAIT option starts a windows application and returns control

to the batch file when done. Acad.exe is the windows application that is being started.

AutoCAD will now start and open each drawing. Because of the /b switch, the script file named “wbout.scr” will run

every time AutoCAD starts. When all files with a .dwg extension have been processed (made equal to variable

%%f), the program will stop.

Link to comment
Share on other sites

Try to change Run with RunWait, something change?

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

RunWait works :) and the script file is processed.

Only thing is that once the first file is opened it closes the program to open the next file with the same program, AutoCAD takes about 30seconds to open so the batch processing of this is slowing down obviously having to wait 30seconds between each file the script runs on.

I'll have a look around to see if there is any way to force AutoCAD to process each $var while staying open

Thanks for all your help Nessie :)

Edited by wheats
Link to comment
Share on other sites

Have you switched in your AutoCAD the SDI mode to 0?

SDI is the AutoCAD system variable for single-drawing compatibility mode. Acad 2000+ can open more then one drawing, but you can set it to just open one drawing like the older versions. Some commands or 3rd party software require AutoCAD to be set in single or multiple drawing mode.

There are two ways of setting this variable.

1. Go to "tools=>options", and then to the "system" tab. On the top right you should see "Single-drawing compatibility mode". Check it if you want AutoCAD to open only one drawing.

2. Type in "SDI" at the command prompt. Then type in "0" or "1".

0 = Multiple drawing mode

1 = Single drawing mode

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Yeah SDI forces AutoCAD to be able to only have 1 file open at a single time, though from my tests the autoit script doesn't process the next file in the selection until autocad has been exited and then it starts another copy and processes the next file.

Maybe the solution is to just run multiple switches on the autocad so it runs like a compatibility mode version so it doesn't have to take 30seconds to run through all the plugins.

http://usa.autodesk.com/adsk/servlet/ps/dl/item?siteID=123112&id=2894625&linkID=9240617

I may just run a couple of these along with " /b " to simplify the program and hopefully take less loading time.

:) to do these all i would have to do is add /b /nologo - is this correct?

Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" "' & $var & '" /b /nologo "c:\datafiles\CP12-3L\wbout.scr"')
Edited by wheats
Link to comment
Share on other sites

:) to do these all i would have to do is add /b /nologo - is this correct?

Run('"C:\Program Files\AutoDesk\AutoCad 2013\acad.exe" "' & $var & '" /b /nologo "c:\datafiles\CP12-3L\wbout.scr"')

You have to put $var for the single file run, and $file_path for the multiple file run. Unfortunately I haven't autocad on my pc so I cant test. As i have read on internet to launch multiple .dwg in one session you can use AutoCAD DWG Launcher that have this file name AcLauncher.exe.

AutoCAD DWG Launcher is AcLauncher.exe located at

on X64 OS C:Program Files (x86)Common FilesAutodesk SharedAcShellEx

on X86 OS C:Program FilesCommon FilesAutodesk SharedAcShellEx

Take a look here, because my mind now isn't too much clear (4:00 AM here :P)

Hi!

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Take a look here, because my mind now isn't too much clear (4:00 AM here :P)

Was there a link missing?

Oh! you should get some sleep :mad2: I had a go at launching ACLauncher.exe on its own through Windows nothing happens. I'll do some googling :)

Also figured out to make multiple switches work its

RunWait('"C:\Program Files\Common Files\Autodesk Shared\AcShellEx\AcLauncher.exe" "' & $var & '" /b "c:\datafiles\CP12-3L\wbout.scr" /nologo /nossm ')
this actually sped the process up a fair bit.

*EDIT* seems you can not run the /b switch with AcLauncher - so you can't run a batch script

Edited by wheats
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...