Jump to content

Batch


Freerefill

Recommended Posts

So, I've seen several requests (they seem to pop up frequently!) for programs/tools/scripts/whathaveyous that allow the user to apply some function to several drawings in a set.

 

Many suggestions have been passed around, and all the while, I was using one of my own creation that I had created almost exactly one year ago. I believe I posted a version of it some time ago, but even then, I was not satisfied. It was not up to par for this forum, nor was it up to par with my own improving standards. It worked, so it was used. That's pretty much what it amounted to.

 

Requests for batch programs continued to roll in though, and my growing dissatisfaction with my year-old work prompted me to bite the bullet and re-write it from the ground up. It took me a month, but I'm pleased with the results. You can apply almost any function or set of functions to any number of tabs on any number of drawings, any number of times.

 

Thus I humbly present FinalBlitz. I do hope everyone finds it useful.

 

The program is currently set up to look for the .dcl file in your C: drive, though you can modify it to whatever you need. If anyone needs any help, please feel free to message me.

 

Also, please critique this. It was my first attempt at DCL, and I admit, it's quite shabby.

 

This is also a first release, I will be improving it as time goes by.

 

Thank you.

 

~~~***~~~

 

*EDIT* Version 4 now uploaded.

 

The following is the secondary header in the program, copied here for convenience. It does reside within the code, so you can look at that if you ever need a bit of help. Explanations as well as examples are now provided.

 

Brass Tacks:

This program is free to use and distribute so long as the above header remains intact.

Users who modify the code have permission to modify the above header to reflect their work

so long as the header retains all previous information.

Questions, suggestions and comments can be sent to me at:

oofreerefilloo@gmail.com

 

I will be more than happy to help with anything.

 

Description:

This program is intended to be a quasi batch engine, the goal being to allow the end

user to run any number of commands or functions in a sort of "macro" style to any

set of AutoCAD drawings.

 

The program operates on a simple premise: if there is no drawing list selected, apply

the chosen function(s) to the current drawing. Otherwise, create a script which will

open up the first drawing in a list and run the chosen function(s) on it. As long as

files remain in the list, after all the function(s) have completed, the script will

be re-written and ran again, thereby closing the affected drawing and opening up the

next in the list, and so on.

 

Please note that this program creates two files:

finalBlitzScript.scr

finalBlitzFileList.txt

which by default will be located in the users C: drive.

 

Note also that this program utilizes a DCL file. The default location for this file is your C: drive, however you may put it anywhere

so long as you alter the code in the tabDia and dwgDia functions.

 

Usage:

Data is passed to the (finalblitz) function in the form:

(finalblitz )

Where:

- A list of all the functions the user wishes to apply, and their appropriate input

- A numerical list of tabs or a proper string, defining which set of tabs to operate on

- A list of drawings, properly formatted with full directory and extention

- An optional toggle to force a check before proceeding with operations

- A numerical indicator to determine how many times the process should be repeated

 

Note that all input could be nil. The program will first check the passed input, and as long as it is nil or formatted incorrectly,

the program will continue to prompt the user for said input. Once all input is satisfactory, the program will proceed with operations.

 

For all passed data that is nil or formatted improperly, navigate the prompt menu to define the desired data.

The menu is formatted such that the first four choices will allow you to navigate through the menu and all other

options are selectable. This will become clearer in a moment.

 

If you were to pass all nil input (finalblitz nil nil nil nil nil) you will see the following prompt:

>> Select Option or [Tab/Drawing/Check/Repeat][Multiple]:

This is the initial prompt. The menu is broken up into two sections.

The first four are your navigation options. Again, these allow you to navigate through the menu systems and select options.

The remaining are the special options you're allowed to set.

 

Option Selection:

>> Select Option or [Tab/Drawing/Check/Repeat][Multiple]:

For option selection, simply type in the string corresponding to the desired option. The options available are in the optSel function.

For any selection other than what is part of the condition statement in the optSel function, you will be prompted to select again.

If you wish to use multiple options, you can toggle that by typing "M"

 

Tab Selection:

>> Select Tabs or [Option/Drawing/Check/Repeat][Layouts/This/Model/Special/DIAlog]:

For tab selection, you have the familiar navigation options (see how "Tab" is now gone, and "Option" is back?), and this time, several others.

"Layout" will select all layout tabs, and this will carry through for all drawings if you choose a set.

"This" will apply to whatever the currently viewed tab is.

"Model" will apply the functions to the Model tab only.

"Special" will allow you to type a properly formatted string to numerically select layout tabs.

String must be formatted in a particular style, for example: 1,2,4-6 will select the Model tab and the first, third, fourth, and fifth Layout tabs.

"DIAlog" will open up a small dialog box for you to select all the tabs you wish.

Note that you must type "DIA", because just typing "D" will bring up the drawing selection menu.

 

Drawing Selection:

>> Select Drawings or [Option/Tab/Check/Repeat][Dialog/Files/CLear]:

Drawing selection is likely to be "none" by default, however here you can change that.

"Dialog" will open a dialog box, allowing you to navigate and create a drawing list.

"Files" will let you view the files in a list format.

"CLear" will clear your selection, and your functions will operate only on the active document.

 

Check Toggle:

>> Toggle Check or [Option/Tab/Drawing/Repeat][Yes/No]:

Real simple. If "Check" is on, you will be prompted before the program runs in order to accept or discard your settings.

If "Check" is not on, it'll just go ahead and do it.

 

Repetition Selection:

>> Select Repetitions or [Option/Tab/Drawing/Check][Reset/Endless]:

Input any integer to specify how many times your selected functions should repeat themselves.

This is especially useful if you have to plot several copies of a drawing.

"Reset" resets the repetition number to 1, and "Endless" will repeat forever (or until you escape).

Note that you cannot input zero repetitions.

 

To create a unique function, simply copy an existing Condition and edit the data.

Each condition has a condition within it. These nested conditions represent the parts of each function.

The first condition simply returns True in all cases. This is so the program can check to see if the option is available.

The second condition is a test. All passed input can be checked here, to determine if the passed input is correct.

Note that this check is optional, and can simply return True if you don't wish to devise a check.

The third condition returns a list in the format: ( ...)

You can create a custom function which returns data in this form, which can be checked by the second condition and used by the fourth.

The fourth function uses the passed data as intended. This will become clearer in the examples.

 

Examples:

To get an idea of how the Option selection works in FinalBlitz, try running this routine:

Note that you can simply copy and paste the (finalblitz ...) function into the command line.

(defun c:cir1( / ) (finalblitz '(("CMD" (vl-cmdf "circle" (getpoint) 5))) '("THIS") t t 1))

Notice how all parameters are set. Running this function will not prompt the user.

This example uses the "CMD" function, which evaluates the second item in the list as a single command. This does not

have to be a vl-cmdf expression, but any single LISP expression, including a LISP itself, such as (c:lisp).

Running this expression will prompt the user for a point and create a circle at that point.

 

Mixing it up just a bit,

(defun c:cir2( / ) (finalblitz '(("CMD" (vl-cmdf "circle" (getpoint) 5))) '("THIS") t t 3))

Notice the only difference is the "repeat" factor has changed. Now, you will be prompted to create three circles.

Notice also, when you run this, that the vl-cmdf expression is simply being repeated, in its entirety, three times.

 

To get a better idea of the strength of this function, try it this way:

(defun c:cir3( / ) (finalblitz '(("CMD" (vl-cmdf "circle" (getpoint) 5))) '("LAYOUTS") t t 1))

Again, it's just like the first, only this time, your drawing will shift to all the layout tabs and prompt you

to create a circle.

 

Now lets have some fun. It's time to explore the menu options and get a real idea for the power of this thing.

 

Run this function. You'll see now, it's prompting you for more information.

(defun c:cir4( / ) (finalblitz nil nil t t 1))

The first prompt has you choose an option. Type "CMD" and hit 'Enter'

The next prompt you'll see is to enter a Visual LISP code. Type:

(vl-cmdf "circle" (getpoint) 5)

and hit 'Enter'. You'll be brought back to the option menu, but you'll see that your option is printed in the form

you see it in the previous examples. Now, type "T" to go to the "Tab" menu, and type "T" again to select "This"

Once you hit enter, you'll be prompted for a point, and again, you'll create a single circle.

 

For the final example, make sure you have downloaded the .dcl file and edited this code to properly reference it.

To keep it as simple as possible, we're going to go back to the first example, with a minor edit:

(defun c:cir5( / ) (finalblitz '(("CMD" (vl-cmdf "circle" (getpoint) 5))) '("THIS") nil nil 1))

You can see here that the only differences this time are that the two "t's" are now "nils". This means you will

be prompted for further information. Note that you will simply be brought to the menu, NOT specifically

to the file selection menu. To get to the file selection menu, enter "D" for "Drawings"

At the drawings prompt, enter "D" again to bring up the file selection dialog box.

Use the drop-down list to select your drive, and click "Browse" to view its contents.

Navigate the folders until you find a set of drawings. Highlight all of them, then click the "Add File" button.

Once the files show up in the top box, click "Okay"

You'll notice the printed line above the prompt has changed. The "none" is now "(list)", indicating that

you have a selection of files.

You'll also notice for the first time that you are prompted if you wish to continue with your settings.

If your settings are accurate, type "y" to continue.

The drawings will automatically open, prompt you to create a circle, and then close.

FinalBlitz.dcl

textfind2.lsp

finalBlitzPublish.LSP

Link to comment
Share on other sites

Just some constructive critism:

 

I find it very hard to work out what it does?

 

The first thing is: what does

Select Option or [Tab/Drawing/Check/Repeat/Multiple] mean ?

I would expect a dialog box to appear first after internal checking.

Also the dialog box is very cryptic.

 

In the line - you can not have an argument and a declared local variable on the same line:

(defun dwgDia(filLst / diaID1 endWhl root dirLst filLst addLst remLst lstClk rotLst chTile lstIni);

 

Just my 2 cents worth......

Link to comment
Share on other sites

Just some constructive critism:

 

I find it very hard to work out what it does?

 

The first thing is: what does

Select Option or [Tab/Drawing/Check/Repeat/Multiple] mean ?

I would expect a dialog box to appear first after internal checking.

Also the dialog box is very cryptic.

 

In the line - you can not have an argument and a declared local variable on the same line:

(defun dwgDia(filLst / diaID1 endWhl root dirLst filLst addLst remLst lstClk rotLst chTile lstIni);

Just my 2 cents worth......

 

I explained what it does, it allows you to run commands in a batch format, mainly on several files.

 

And yes, there are two dialog boxes in the program, one is for tab selection and one is for file selection. I don't think the dialog box is -that- cryptic, though I'm sure a few labels here and there couldn't hurt.

 

The opening dialog.. well, you choose what you want. Here, I'll try to give a rundown. I'm not at my terminal at the moment so it'll have to be mainly from memory.

 

There are five main selections: Option, Tab, Drawing, Check, Repeat

 

Option lets you select which function you want. I suppose a list of what functions are available would be helpful... I'll add that in.

Tab lets you select which tabs you want. So far there's no default selection, but you can select the Model tab, Layout tabs (as a group), a numerical input (1,2,4-6 that sort of thing) or open up the tab dialog box.

Drawing lets you select which drawings you want.

By default, once those three options are selected, the function will run. You can, however, turn Check on (the fourth option) so that it will only run once you approve of your settings.

Repeat is how many times it will repeat your function

 

As for the passed argument, yeah, I didn't spot that. Mainly because I spent the last two weeks getting the bloody thing to work. I've never used DCL before, it was my first attempt. I'll fix that.

 

To get an idea of what it's useful for, try this:

1. Open up a new drawing.

2. Draw something, or some things. Anything random will do.

3. Copy the stuff to your clipboard (Ctrl+C)

4. Run the program

5. Select, as your option (that is to say, type it at the first prompt), 400

6. Hit "T" to switch to the Tab option set

7. Type "L" for all layouts

 

Once you enter "L", the program should automatically run through all the tabs in your drawing, and paste your clipboard selection at basepoint 0,0.

 

Try creating a few blank drawings, and testing out the Drawing option. Note that by default, nothing is saved. So, you will have to turn on the Multiple toggle in your option selection, and you can select option 400, as well as "Save".

 

If you have any other questions, feel free to ask.

Link to comment
Share on other sites

  • 3 weeks later...

All the options are in the "optsel" function. That function is a condition statement which first checks the option (you'll note that all options are lists, and each list starts with a string, which indicates the option you wish. All other items in the list are pieces of information that that option will use.) and then returns a value depending on what value you're looking for (the "op" variable that gets passed is used in the nested condition statements, and that decides which value is returned by those nested statements.).

 

As for the actual name of it, in my previous batch program (which is too much of a mess to bother posting here), my initial options were for printing/plotting, and those were all numerical between 1 and 100. As I began to realize its flexibility, I decided to organize the numbers between 1 and 1000 into groups of 100, each group with a unique task (global plot functions, modified plot functions, drawing manipulation, etc). In the early stages of this batch program, I took the same theory, but since I was focused more on the program and not on the options, I tended to go with the first thing that popped into my head. In this case, "400", "401" and "402" were all "paste clipboard" functions, which I later found I could combine into a single "400".

Link to comment
Share on other sites

  • 1 month later...

Hi Mark,

 

First of all thanks for sharing, that looks like it would have taken ages and I reckan with a bit of polishing you could make it a pro product.

Secondly, can you help me with this? I'm wanting to run simple code with your program.

And to do this I've put in

(finalblitz '(("CMD" ChAtt)) nil nil nil 1)

Then selected the drawings, and then tried to select all tabs ("T" for tabs then "L" Layouts then "y" for accept). Aside: How can I skip this step? (as my code doesn't use layouts)

Then it goes to work but nothing changes. Does it save? I've made sure the block and tag exist.

Here's the function:

(defun c:ChAtt (/ blkname attTag ss newStr subEn)
 (if (AND ;(not (eq
         (setq blkname [color=Red]"Border 0"[/color]) ;(getstring "\nEnter Block Name: ")) ""))
      ;(not (eq
         (setq attTag [color=Red]"TITLE1"[/color]) ;(getstring "\nEnter Attribute Tag: ")) ""))
      (setq newStr [color=Red]"HELLO"[/color]) ;(getstring "\nEnter New String: "))
      (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname))))
      )
  (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (setq subEn en)
    (while (AND (setq subEn (entnext subEn))
        (eq (cdr (assoc 0 (entget subEn))) "ATTRIB"))
      (If (eq (cdr (assoc 2 (entget subEn))) attTag)
    (entmod (subst (cons 1 newStr) (assoc 1 (entget subEn)) (entget subEn)))
    )
      )
    )
  )
 (princ)
 )

Thanks

Link to comment
Share on other sites

Hi Mark,

 

First of all thanks for sharing, that looks like it would have taken ages and I reckan with a bit of polishing you could make it a pro product.

Secondly, can you help me with this? I'm wanting to run simple code with your program.

And to do this I've put in

(finalblitz '(("CMD" ChAtt)) nil nil nil 1)

Then selected the drawings, and then tried to select all tabs ("T" for tabs then "L" Layouts then "y" for accept). Aside: How can I skip this step? (as my code doesn't use layouts)

Then it goes to work but nothing changes. Does it save? I've made sure the block and tag exist.

Here's the function:

(defun c:ChAtt (/ blkname attTag ss newStr subEn)
 (if (AND ;(not (eq
         (setq blkname [color=Red]"Border 0"[/color]) ;(getstring "\nEnter Block Name: ")) ""))
      ;(not (eq
         (setq attTag [color=Red]"TITLE1"[/color]) ;(getstring "\nEnter Attribute Tag: ")) ""))
      (setq newStr [color=Red]"HELLO"[/color]) ;(getstring "\nEnter New String: "))
      (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 blkname))))
      )
  (foreach en (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
    (setq subEn en)
    (while (AND (setq subEn (entnext subEn))
        (eq (cdr (assoc 0 (entget subEn))) "ATTRIB"))
      (If (eq (cdr (assoc 2 (entget subEn))) attTag)
    (entmod (subst (cons 1 newStr) (assoc 1 (entget subEn)) (entget subEn)))
    )
      )
    )
  )
 (princ)
 )

Thanks

 

Thank you for your kind words. You are absolutely correct, it does need a fair deal of polishing. I've been very much focused on the functionality and, since I don't have much spare time for this, actually putting it to use. As such, cleaning it up to make it user friendly is an aspect I am sadly lacking, but am aware of. I will try harder. ^.^

 

The aside first.. you can put the text '("LAYOUTS") in place of the first 'nil', and the last nil (before the 1) is there to provide a last "check" to make sure your settings are correct, you can bypass that by setting that 'nil' to 'T'. It'll look something like this:

 

(finalblitz '(("CMD" ChAtt)) '("LAYOUTS") nil T 1)

 

The way the program works is sort of like this: you pass input to it, and if the input is not valid or doesn't exist, it'll bring you into a text-based interface that prompts you for said input. If you wish, you can pass a full set of input to finalblitz and not have a prompt at all! Currently that won't work for a drawing set (only the current drawing), but I'm working on that~

 

As for your second question regarding saving.. finalblitz is the "big brother" of my previous batch LISP, called blitzprint. As its name implies, blitzprint was initially used for printing layout tabs. After I hit the limits of its functionality, I made finalblitz. However, there were a few carry-overs, namely, blitzprint didn't save the drawing. I didn't see the need to open a drawing, print it, then save it if no changes were made.. so by default, it didn't save. Finalblitz is the same.

 

However, finalblitz is delightfully more robust, and I included an option to save your drawing after making your changes. You can include that option by simply adding it to the option list, like so:

 

(finalblitz '(("CMD" ChAtt)("SAVE")) '("LAYOUTS") nil T 1)

 

Finalblitz will run all options in the option list, so you can do many things at once. You are, however, limited. There is a 255 character limit I believe, when sending things to the command line. So you cannot string too many options together. You can, however, craft your own options or sub-functions, so you can combine many into one. In that regard, it's quite customizable.

 

A final word, most LISPs I've run into that are to be run via another LISP have difficulties using the actual command of the LISP (that sounds kind of confusing.. imagine trying to use (command "chatt"), it won't work). You can get them to work, however, if you turn the command into a function, like so: (command (c:chatt)). So if your function isn't running each time a drawing is opened, try this:

 

(finalblitz '(("CMD" (c:ChAtt))("SAVE")) '("LAYOUTS") nil T 1)

 

I hope this answers all your questions, and thank you again for your kind words. If you need any more help, don't hesitate to ask. ^.^

Link to comment
Share on other sites

That's excellent, it works! thanks Mark :)

 

I'm not sure if you've detailed it but I realized finalBlitz.lsp and whatever other lisps the user runs with it need to be loaded into the startup suite so that they'll load with each drawing. This is correct?

 

Anyways, I think I'll find plenty of further use for a robust program like this.

Link to comment
Share on other sites

I'm very glad it works, Steve. I do hope it will come in good use in the future. If you have any ideas or suggestions, please let me know. I currently want to work on a more advanced dynamic command check, a way to automatically import a file list, and I know I gotta clean up those dialog boxes. I'm also trying to think of a way to run scripts, and I think I know of a good one, although it's a little hack. At any rate, I'm overjoyed (and more than a little relieved) that it works. Thank you. ^_^

 

Finalblitz.lsp does indeed need to be loaded with every drawing, since the program writes a script which, in turn, runs the program (itself), so naturally it needs to always be loaded, otherwise it won't be able to run itself. Think of it like this: the program is split into two parts, first the data collection, then using the data. If you write that data to, say, a .scr file, you can then run that script, which will let you open a new drawing, and run your saved data on that new drawing. The way it does this is by simply skipping the "data collection" part and feeding the data directly into the "using the data" part. I should point out that, in that regard, only Finalblitz.lsp needs to be loaded, as "using the data" doesn't bother with either of the dialog boxes. Textfind2.lsp is just an outside function that I included as an example, a way to batch replace text (also to batch an outside function), so that doesn't need to be in your startup suite either, unless you want to use it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...