Author Topic: Pairing scripts to be run on associated drawings and batch processing  (Read 2711 times)

0 Members and 1 Guest are viewing this topic.

PipelinerUSA

  • Mosquito
  • Posts: 2
I have a directory populated with several hundreds of drawings and scripts. For every drawing "A.dwg" there is a script "A.scr":

A.dwg  A.scr
B.dwg  B.scr
C.dwg  C.scr
D.dwg  D.scr
....


What I am looking to do is figure out a way to run every script on its associated drawing.  Tools like ScriptPro.exe and the Civil 3D out-of-the-box Batch Save Utility work by running 1 script on many drawings in a folder, but in my case there is one unique script to be ran on one unique drawing. Any ideas?

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #1 on: November 22, 2021, 10:22:06 AM »
Thought: You could just tweak the script runner (using `accoreconsole`) I created and use drag and drop.

https://www.theswamp.org/index.php?topic=56891.0
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org


JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #3 on: November 22, 2021, 01:13:12 PM »
Thank you for the heads up. Although I don't like it when people "fish for the best" instead of thinking themselves I would still prefer to help because we do have a lot of people that do not frequent both forums.

Also, each thread/post isn't just about answering the OP's question but it is also an opportunity to answer a future problem another person is having as well (someone may find your solution years from now).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #4 on: November 22, 2021, 03:30:02 PM »
Quote from: danAllen

link=https://www.cadtutor.net/forum/topic/74046-batch-processing-of-script-files-on-drawing-files-with-matching-names/?do=findComment&comment=586532

have a single script with this content? then each drawing will run a script with same file name
Code: [Select]
(command "script" (strcat (vl-filename-base (getvar "dwgname")) ".scr"))

Thinking about this topic more, I don't like the two AutoCAD/Lisp solutions posted at CADTutor. It makes maintenance too cumbersome. That is to say, the AutoCAD/Lisp system works if you need to process something before or during a drawing session but if you need to publish or do something to 100's of files then this solution is worthless.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

danAllen

  • Newt
  • Posts: 133
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #5 on: November 22, 2021, 04:26:51 PM »
Without knowing why the OP has the hundreds of existing scripts, it is hard for me to pass judgement on that system. Taking that as a given, I'm just proposing an easy answer to their specific question, if they used ScriptPro.

PipelinerUSA

  • Mosquito
  • Posts: 2
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #6 on: November 23, 2021, 10:41:41 AM »
I work for a company that has communications towers all over the country, each with a specific unit number.  The towers all have different assets attached to them.  Those assets exist in a block catalog.  I have a script for each tower that inserts those blocks at the appropriate location.  Each tower is 1 drawing, and they are all unique.  Also included in the script is the creation of property filters and their definitions (wildcard criteria), layer color assignments, etc.

It is possible the script solution is not even the best practice, but it is what I came up with.  But then the scale of the project kept growing to the point where I am searching for something more automated instead of manually dragging and droppping hundreds of scripts and opening and closing .DWG files.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #7 on: November 23, 2021, 11:10:31 AM »
Then you'd want the batch script I linked to in my first reply; you can build/keep a windows batch script to run entire directories of files and keep those script(s) to run again and again.

You could either modify the batch script to run a script titled the same as the drawing or you could make the `BatchDrawings_accoreconsole.scr` call the script to be run for each file using the line danAllen posted.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

danAllen

  • Newt
  • Posts: 133
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #8 on: November 23, 2021, 11:31:52 AM »
John,

I see accoreconsole has this line. Does vl-filename-base qualify as plain AutoLisp?

Quote
Because accoreconsole will only allow the use of plain AutoLisp some utilities have to be rewritten

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #9 on: November 23, 2021, 11:43:44 AM »
John,

I see accoreconsole has this line. Does vl-filename-base qualify as plain AutoLisp?

Quote
Because accoreconsole will only allow the use of plain AutoLisp some utilities have to be rewritten

Nope (but I suspect you already know that *hmm*).

You'd have to use plain AutoLisp.
Code - Auto/Visual Lisp: [Select]
  1. ;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2. ;; STR_SUBST
  3. ;;  replace text in a string with new text
  4. ;;
  5. ;;  Takes  new    string to replace with
  6. ;;         old    string to be replaced
  7. ;;         txtstr string to search in
  8. ;;
  9. ;;  Returns modified string, or unmodified string if old not found
  10. ;;  WARNING : no error checking! function WILL hang or crash if it doesn't
  11. ;;            recieve sensible values (i.e. no emtpy strings!)
  12. ;;
  13. ;;  BY: Iqbal Lotey
  14. ;;  Newsgroups: autodesk.autocad.customization
  15. ;;  Date: 1999/09/10
  16. (defun str_subst ( new old txtstr / i char)
  17.   (setq i 1)
  18.   (while ( <= i (strlen txtstr))
  19.     (setq char (substr txtstr i (strlen old)))
  20.     (if (equal char old)
  21.       (setq txtstr (strcat (substr txtstr 1 (- i 1))
  22.                            new (substr txtstr
  23.                                        (+ i (strlen old))))
  24.             i (+ i (- (strlen new) 1))
  25.       )
  26.       (setq i (1+ i))
  27.     )
  28.   )
  29.   txtstr
  30. )
  31.  
Code: [Select]
(str_subst ".scr" ".dwg" (getvar 'DWGNAME))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #10 on: November 23, 2021, 12:06:05 PM »
You can also just create a simple windows batch script to pass each through my BatchDrawings_accoreconsole.bat.

The following, while untested, should work.
Code - Bash: [Select]
  1. @echo off
  2. setlocal enableDelayedExpansion
  3.  
  4. SET PROG="C:\some\location\to\BatchDrawings_accoreconsole.bat"
  5.  
  6. set SCRIPT="%~dp0\job-filelist_script.scr"
  7. set logfile="%~dp0\scripting.log"
  8.  
  9. :: Run the script.
  10. for %%F in (*.dwg) do (
  11.         set SCRIPT="%%~nF.scr"
  12.         call %PROG% "%%~nF.dwg")
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

danAllen

  • Newt
  • Posts: 133
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #11 on: November 23, 2021, 03:03:01 PM »
Nope (but I suspect you already know that *hmm*).

I run Bricscad, so I don't have accoreconsole. I did suspect that was the case, hence my question. I had thought about referring (in CadTutor) the OP to your post with respect to my one line script, but then realized maybe my line would not work with your solution.

Your last post looks like a good solution.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #12 on: November 23, 2021, 03:16:35 PM »
Both should work.

I have just learned that you can run Briscad invisibly in the background by using the `/automation` switch (thanks MP). I have added a note to the accoreconsole batch script. [ https://www.theswamp.org/index.php?topic=56891.msg605601#msg605601 ] So, you can use that script I wrote too.

VisualLisp has functions that start with VL
AutoLisp has functions that do not.

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

danAllen

  • Newt
  • Posts: 133
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #13 on: November 23, 2021, 03:25:15 PM »
For Bricscad, batch processing drawings is easy. A single drawing can open/close a list of drawings from lisp, and run lisp commands on them at same time. (Either auto or visual lisp.) Much easier than the boot-strap autocad methods.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #14 on: November 23, 2021, 03:44:30 PM »
For Bricscad, batch processing drawings is easy. A single drawing can open/close a list of drawings from lisp, and run lisp commands on them at same time. (Either auto or visual lisp.) Much easier than the boot-strap autocad methods.


I get the impression you don't like AutoCAD.

So can AutoCAD. The point about using `accoreconsole.exe` (a stripped down version of AutoCAD) is that you don't load the UI (user interface) so processing a 100+ or so drawings will take a few minutes vs an hour. ScriptPro used to be a way "faster way" to launch AutoCAD and run a script but it was so slow no one liked using it because a separate AutoCAD instance launched each time (ANNOYING!). ScriptPro died a long time ago.

This was my replacement for scriptpro (10 years ago when I used AutoCAD). ...yay! But the whole point to Automation is trying to be as quick as you can; a full blown interface is not efficient and neither is launching a program to run another program to automate (hence why I wrote the windows batch script; I dont have to launch anything to run a script).
 
Code - Auto/Visual Lisp: [Select]
  1.      (function
  2.        (lambda ( x )
  3.          (cond
  4.            ((wcmatch x "*.lsp")
  5.             (load (strcat (cadr (assoc "source" _paths)) x))
  6.             )
  7.            );_ end cond
  8.          );_ end lambda
  9.        );_ end function
  10.      _user-files-to-update
  11.      )
  12.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

danAllen

  • Newt
  • Posts: 133
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #15 on: November 23, 2021, 04:21:49 PM »
I get the impression you don't like AutoCAD.

So can AutoCAD. The point about using `accoreconsole.exe` (a stripped down version of AutoCAD) is that you don't load the UI (user interface) so processing a 100+ or so drawings will take a few minutes vs an hour. ScriptPro used to be a way "faster way" to launch AutoCAD and run a script but it was so slow no one liked using it because a separate AutoCAD instance launched each time (ANNOYING!). ScriptPro died a long time ago.

This was my replacement for scriptpro (10 years ago when I used AutoCAD). ...yay! But the whole point to Automation is trying to be as quick as you can; a full blown interface is not efficient and neither is launching a program to run another program to automate (hence why I wrote the windows batch script; I dont have to launch anything to run a script).

Those are all good points, no disagreement. For the OP, perhaps learning to use accoreconsole.exe, edit batch scripts, etc would be too much. I only mentioned ScriptPro because OP did in first post. Lee Mac's Script Write may be more accessible than ScriptPro. http://www.lee-mac.com/scriptwriter.html

But I agree it could be to their benefit to learn your method. I did not mean to infer your solution was a bootstrap, I was thinking about my past experience. I'm sorry if I offended you.

I last used AutoCAD v2005. I recall at the time that in one session one drawing could not open another drawing and run lisp commands. It was necessary to write script files. At the time we used sweep.lsp by Looking Glass MicroProduct / Phil Kreiker to do batch processing, which created a master script by merging list of drawings with separate script of actions. When I switched to BrisCAD I learned one drawing could open and control another drawing through simple lisp, without using more advanced ObjectDBX.

The only thing I didn't like about AutoCAD was the price, thus the switch to BricsCAD.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #16 on: November 23, 2021, 04:35:04 PM »
The utility by Lee looks to be just a script WRITER not a script RUNNER.

I don't know how much easer to make things than drag-n-drop or double clicking. Sorry. And honestly, those two options sound far easier to use then launching a program, creating, loading and then running lisps. Sorry, again.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

danAllen

  • Newt
  • Posts: 133
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #17 on: November 23, 2021, 04:54:54 PM »
You may be right. My mileage varies.

FYI (for others), if you don't have AutoCAD, accoreconsole.exe is installed by default with the free Autodesk DWG TrueView. (Which I just discovered - thank you Search Everything - https://www.voidtools.com/ )

BIGAL

  • Swamp Rat
  • Posts: 1417
  • 40 + years of using Autocad
Re: Pairing scripts to be run on associated drawings and batch processing
« Reply #18 on: November 23, 2021, 10:55:58 PM »
Nice pick up about True view for Bricscad users etc.
A man who never made a mistake never made anything