Macro to Run AutoCAD Script on Batch of Files Not Working

I'm new to Keyboard Maestro.

I used Quickeys for years and have been looking for a new program and Keyboard Maestro is the first thing I found that really seems capable of replacing it.

I need to create a batch process to open files in a certain folder, run a script on each one in AutoCAD and then save to a new location.

I've looked at other macros and forum posts trying to figure out all the steps I need to make this work but I think I've just gotten more confused.

I've attached what I've created so far.

I don't have a lot of extra time right now so I'm looking for someone to help me finish this macro so it works. I figured this would be a good place to ask if anyone is willing to do this work for me or know where I can hire someone for this task?

Update ACad Page Setup.kmmacros (13.5 KB)

Macro Image

Many of us won't have Autocad, so it will help if you tell us what isn't working -- it'll still be guesswork, but it'll more informed guesswork!

One question -- does Autocad really use the file path rather than the (more usual) file name as the window title? After you open the file your "Pause" action waits for a window title containing %Variable%LocalFile%, and I'm wondering if it should be %Variable%LocalFileName% (from the "Split" action) instead.

I honestly don't think it's working at all right now.

I originally had it broken into a single drawing macro and then was trying to build a batch macro but could not figure out how to get it to run through a group of files so I changed it to be one macro so I could mimic another macro I found here.

I tried changing the Split action title like you suggested, and it gave me an error "Macro Cancelled - Split Path Failed because with path..." so I think the first path may be the correct way for Mac since it doesn't give an error.

On the other hand, I get nothing, no action happening or notifications of errors when I run it like I uploaded it.

I think my first real question is, does this appear to be setup to batch a set of files in a folder correctly or is there something I'm missing?

I think I can get the individual steps to work since I got them to work before, but the batching is much more complicated than I'm used to and I think I must be missing something. Especially since I get no action.

What I need is for it to open each drawing in a specific folder one at a time, run a script in AutoCAD, and save them to a different folder.

The steps within AutoCAD are to enter Script which pops up a dialogue, then navigate to the correct script file, run it on the drawing and save it.

Sorry, meant to say Thank you for responding so quickly!

Wrong way round. The "Split" is fine, but you then use the unsplit full path when you test the window title -- does AutoCAD use the full path or just the filename?

Cleverer people than me will tell you to use KM's Debugger to step through your macro and see what's happening. But I rely on dialogs, so here's quick test, without all the AutoCAD bits:

Update ACad Page Setup Test.kmmacros (8.7 KB)


If I run that on a test folder containing TestFile.dwg the first dialog is

LocalFile: /Users/nige_s/Desktop/AutocadTest/TestFile.dwg
LocalFileName: TestFile
LocalExt: dwg

...and the second is

Not a DWG

Straight away you'll see what I mean about your "Pause until front window title contains" action -- you are testing with the contents of your LocalFile variable, and I doubt that the title of the window is that full path.

More subtle is the second thing, and it's this that makes it look like your macro isn't doing anything -- you'll see that LocalExt is being set to "dwg". But your "If" condition test is if it is ".dwg". Note the period! The period isn't included in "Split path: Extension" result and you shouldn't include it in your test.

Because the "If" is false every time, the rest of your macro never happens -- currently it just looks at every file in the directory and says "Nah. Next please!". An easy mistake to make, and I (and, I bet, most people here) do something similar almost daily :wink: