Author Topic: Batch: Open DWG plus Lisp from another lisp?  (Read 7099 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 654
Batch: Open DWG plus Lisp from another lisp?
« on: March 24, 2014, 08:20:45 AM »
Hi

this is a question out of the batch-family "run script from lisp / run lisp from script / run script from script / run lisp from lisp" ...

The first, common question is:
Who knows an info / link / doc which describes the basic behaviour and possibilities of these features?

The second, detailed questions is:
How to "open a batch of DWGs and run a defined lisp ("sub.lsp") and close the DWGs" from a lisp ("main.lsp")?

My current ideas / answers are:

a) Create and run a script:
"main.lsp" creates and writes a script like: "open test.dwg (load "sub.lsp") sub qsave close test.dwg"
Then I have "(command "script" "myscript.scr")
This could work, but I don't have control over a script which could crash or hang or ....

b) Use Starting-group
I use the starting-group (is this the right name in English?) where I add my "sub.lsp" which starts immediately when the DWG will be opened.
In "main.lsp" I use "(command open test.dwg)" to open the DWG which starts the lisp.

c) ObjectDBX:
The "sub.lsp" (there are many of it ...) should also be used within AutoCAD and this is why the code should be the same without optimization for ObjectDBX.

d) Others ???
I also use OpenDCL and DosLib on a low level (and don't know all commands at the moment), but it would be fine to have commands like:
Code: [Select]
open test.dwg
start sub.lsp inside test.dwg
close test.dwg

This ( d) ) would be perfect ...

Any help would be appreciated  :-D


EDIT:
Here is a solution with VBA (from the year 2007), but VBA is nearly dead ...
Execute commands on all open drawings
« Last Edit: March 24, 2014, 11:18:49 AM by Peter2 »
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Locke

  • Guest
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #1 on: March 24, 2014, 11:51:50 AM »
I've seen option 'A' work well in a production environment.  The benefit is that it's very flexible, and can be modified quickly depending on the needs of the project. 

The downside is as you mentioned; no way to diagnose the job while it's running and react. 

Not sure how comfortable you are in .NET, but using a ServicedComponent interface bridge between AutoCAD in-process calls and interop, this sort of automation becomes effortless.

Peter2

  • Swamp Rat
  • Posts: 654
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #2 on: March 24, 2014, 11:57:23 AM »
Not sure how comfortable you are in .NET ...
:embarrassed:  :-(  :embarrassed:
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Locke

  • Guest
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #3 on: March 24, 2014, 03:09:52 PM »
Have you considered using something like Viru's ScriptPro?  When I originally looked at the source, I remember it invokes AutoCAD via Process.Start(), but it still has some intelligence for checking the health of AutoCAD, and restarting on failure.

Peter2

  • Swamp Rat
  • Posts: 654
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #4 on: March 24, 2014, 03:56:13 PM »
...something like Viru's ScriptPro?  ....
Who? Where? What?
I only know ScriptPro from Autodesk, which is fine in its way but not the solution that I need.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Locke

  • Guest
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #5 on: March 24, 2014, 04:52:58 PM »
...something like Viru's ScriptPro?  ....
Who? Where? What?
I only know ScriptPro from Autodesk, which is fine in its way but not the solution that I need.

This is what I was referring to: http://through-the-interface.typepad.com/through_the_interface/2010/10/novembers-plugin-of-the-month-live-on-autodesk-labs-scriptpro-20-for-autocad.html

Also as I'm just realizing this is specifically in the forum section for Vanilla/AutoLISP I'll let someone with more brains take over so I don't muck up your thread any more.  :wink:

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #6 on: March 24, 2014, 07:02:11 PM »
Perhaps AutoBatch from Ductisoft would help: http://www.ductisoft.com/en/drafters/Batch/AutoBatch.html

It seems to be the most robust system that I have seen.

Peter2

  • Swamp Rat
  • Posts: 654
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #7 on: March 25, 2014, 05:18:01 AM »
Hi
thanks for your hints, but I don't search a full-functional-batch software, I need the described (small?) function to integrate it into my own software.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Bhull1985

  • Guest
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #8 on: March 25, 2014, 07:24:17 AM »
http://www.lee-mac.com/odbxbase.html

Lee Mac's Object DBX wrapper.
Simply wrap your "sub.lsp" using this tool and batch process all required dwgs.

Peter2

  • Swamp Rat
  • Posts: 654
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #9 on: March 25, 2014, 07:30:09 AM »
...Lee Mac's Object DBX wrapper....
This would be great, but will it work for all lisps? Lee writes there there a "no selection sets, no commands, no ent*-methods, no system-variables". If this is "a must" then I have a problem, because I need the "forbidden functions".
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Bhull1985

  • Guest
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #10 on: March 25, 2014, 08:21:07 AM »
Use the VLA/VLAX equivalents

Peter2

  • Swamp Rat
  • Posts: 654
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #11 on: March 25, 2014, 09:35:33 AM »
Use the VLA/VLAX equivalents
The idea is that any existing lisp should be used without recoding. I will see if I can keep this idea alive - or if I have to bury it.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #12 on: March 25, 2014, 01:07:45 PM »
Publish?
James Buzbee
Windows 8

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #13 on: March 25, 2014, 06:26:15 PM »
An old Script-based application without the restrictions of ObjectDBX: Script Writer

Peter2

  • Swamp Rat
  • Posts: 654
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #14 on: March 26, 2014, 04:31:38 AM »
At first: Thanks to all for replies. The "lucky bag" ("jack of all trades device") is still missing: Script has pros and ccons, ObjectDBX too ...

At the moment I have a trivial(?) problem on the lower level. My lisp creates a script and starts it:
Code - Auto/Visual Lisp: [Select]
  1. ; write the script with open - call a lisp - close
  2. (setq x (open (strcat dwgr_sourcefolder "\\automat.scr") "w"))
  3. (princ (strcat "_.open " eintrag " taskerlisp _.close ") x)
  4. (close x)
  5.  
  6. ; start the script
  7. (if foundflag
  8.     (progn
  9.         (vl-registry-write "HKEY_CURRENT_USER\\Software\\cadtool\\automat\\monitor" "workingflag"  1)
  10.         (princ "\n1\n")
  11.         (setq x (strcat dwgr_sourcefolder "\\automat"))
  12.         (command "_.Script" x)
  13.         (princ "\n2\n")
  14.     )
  15. )

The result is:
Code - Auto/Visual Lisp: [Select]
  1. 1
  2. ; Error: invalid AutoCAD command: nil

When I copy&paste the line (command "_script"...) to the command-line it works fine: the script exists, the script works, the lisp inside the script works - but I can not start the script via my mainlisp, although I found some lisp which starts script  ...
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #15 on: March 26, 2014, 01:58:58 PM »
The only solution that I have found to be able to "batch" in lisp is a little drawn out.  I will try to explain it as simply as I can.

The solutions uses the registry and the acaddoc.lsp.

The acaddoc.lsp loads the "batch.lsp" (this is the executing lisp).  In this lisp there is some code that checks the registry for a flag (and a few other things)

;;From the acaddoc.lsp;;
Code: [Select]
;; Appload the Batch program
(load "Batch.lsp")
;;From the Batch.lsp
Code: [Select]
(setq BatchMasterKey "HKEY_CURRENT_USER\\Software\\Batch")

(if (= (vl-registry-read BatchMasterKey "Run") "T")
;; Run the batch if it is not nil
(load (vl-registry-read BatchMasterKey "Batch") "Unable to load the specified Batch!")
)

When the executing lisp is run, it creates a document reactor in the current drawing which checks for that drawing to become current again.  Then it sets the registry flags that are read by the opening lines of the batch.lsp. Then the drawings are opened. (there is a little more detail here that I am skipping).  One of the registry flags is a lisp file (this is the "batch process"). This is loaded into the (s:startup) so that it will execute once the drawing is fully opened.

Since the flag has been set, when the drawings begin to open the "batch process" is executed automatically. Once the drawing is fully opened, the "batch process" runs.  (this "batch process" closes the drawing when it is complete).  Once all of the drawings have been "processed" and the current drawing takes focus, the reactor resets the flags in the registry and deletes the reactor.

Example of a "batch process":
Code: [Select]
;; Add the start up
(defun S::STARTUP (/)

;;; ------------ ECHO TO THE COMMAND LINE
(princ "\n Begining Batch Process \n")

;; Set the dbmod
(acad-push-dbmod)
;; Run some shtuff
(alert "test")
;; Reset the dbmod
(acad-pop-dbmod)
;; Close the drawing
(vl-cmdf "CLOSE")
)
[\code]

This seems to work for me with out any issue.  I tried using scripts to batch process but if it fails, it stops.  Since I am using lisp I can capture and report errors with out stopping.  Also since I am using lisp and a document reactor I can set other flags to execute after the batch has been completed. I am able to execute .lsp, exe, .vbs, open documents, open explorer, send email, endless possibilities.

ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Peter2

  • Swamp Rat
  • Posts: 654
Re: Batch: Open DWG plus Lisp from another lisp?
« Reply #16 on: March 26, 2014, 02:07:42 PM »
Hi Tim

thank you. I will study and try. At the moment there seem to be a solution based on OpenDCL. I will try there too and will report.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23