Author Topic: Opening Drawings and Running LISP  (Read 6056 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Opening Drawings and Running LISP
« on: July 25, 2011, 03:01:49 PM »
Ok, I found the thread that discusses how to open drawings at http://www.theswamp.org/index.php?topic=37145.0

So, I am able to open the drawing and have it as the active drawing. I have now found two methods that this works with, without using SDI mode. My problem is after opening the drawings, I want to make some modifications to the drawing using LISP, save the drawing and close it.

I am using OpenDCL and I have done this in the past by using some events within it, but I would prefer to avoid that as it slows the process down a bit.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Opening Drawings and Running LISP
« Reply #1 on: July 25, 2011, 04:00:01 PM »
Use ObjectDBX, Lee has a nice helper routine here somewhere.

Here is on from Tim:
http://www.theswamp.org/index.php?topic=29933.msg354958#msg354958

Maybe this one from Lee
http://www.theswamp.org/index.php?topic=31827.0
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10658
Re: Opening Drawings and Running LISP
« Reply #2 on: July 25, 2011, 04:36:17 PM »
Use ObjectDBX, Lee has a nice helper routine here somewhere.

Here is on from Tim:
http://www.theswamp.org/index.php?topic=29933.msg354958#msg354958

Maybe this one from Lee
http://www.theswamp.org/index.php?topic=31827.0

*sigh* Isn't any of my stuff ever worth mentioning? Makes me glad I spend time posting...On the bright side, maybe even this post will get ignored.
http://www.theswamp.org/index.php?topic=37475.msg425205#msg425205

...but ODBX is not the tool I would use OR would ODBX be what I think the OP is asking for. Use vl-load-all like VovKa demonstrates here:
http://www.theswamp.org/index.php?topic=32294.msg378106#msg378106
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Opening Drawings and Running LISP
« Reply #3 on: July 25, 2011, 04:58:17 PM »
All of the above code is great, but the problem that I am running into is I have to run some pretty complex code on this, I will list everything that I have to do:
  • Switch to modelspace
  • Unlock, turn on and thaw all layers
  • Make sure that nothing is placed on layer 0 and automatically move it if it is.
  • Convert to style based plotting if the drawing is using color based plotting
  • Change all layers to color 8 with a plot style of shaded
  • Change all xrefs from Overlay to attachments (This is optional and is set before my command runs)
  • Change all Xrefs, Images, PDFs, DGNs, etc. to use relative paths
  • Set all objects to bylayer, including within blocks
  • Purge and Audit the drawing

I already have LISP routines that do all of these things, but they rely heavily on the command function, which appears not to work with any of the above code. As I am sure you can imagine many of these routines are quite complicated and some took a lot of tweaking to make them actually work, particularly the overly to attach.

Please note that in case it matters, I do not need to copy variable between drawings, each drawing is independent, the only thing I need to do is run these routines on the newly opened drawing, save it and close it.
« Last Edit: July 25, 2011, 05:02:18 PM by cmwade77 »

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Opening Drawings and Running LISP
« Reply #4 on: July 26, 2011, 07:35:23 AM »
How about using a Script (.scr) to:
  • Open
  • Load/Run LISPs
  • Save
  • Close
Although not as quick as ObjectDBX, this method doesn't impose the restrictions incurred by using ObjectDBX, yet you still have the power & error trapping offered by LISP over a simple script.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Opening Drawings and Running LISP
« Reply #5 on: July 26, 2011, 04:30:43 PM »
suggestion..

Auto-Batch

:P
Keep smile...

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Opening Drawings and Running LISP
« Reply #6 on: July 26, 2011, 04:36:18 PM »
suggestion..

Auto-Batch

:P
I have considered it, but I have some custom options that need to be set before batch processing. I think I am going to have to go the script route outlined above, but I am taking a break from this part to work on the PDF portion. This is all part of our own setup, revision and inserting Title 24 forms routine that we use here.

deegeecees

  • Guest

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Opening Drawings and Running LISP
« Reply #8 on: July 27, 2011, 02:30:37 PM »
My halfacent:

http://www.theswamp.org/index.php?topic=6657.msg84407#msg84407
Thanks, with a couple of minor tweaks that will save me a ton of time.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Opening Drawings and Running LISP
« Reply #9 on: July 27, 2011, 04:39:51 PM »
well,..

The avantage of lisp when running script is to detect if the file you need to open
can be open. I mean,..

-check version,
-check file system attribute,
-check locked file,
-check read/write acces folder,
-etc..

so by using only SCR can't do that.
so it will generate an error or stop the process when hit a problem.
Keep smile...

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Opening Drawings and Running LISP
« Reply #10 on: July 27, 2011, 07:17:13 PM »
My halfacent:

http://www.theswamp.org/index.php?topic=6657.msg84407#msg84407
Ok, so nthat works for the most part, but it does not save and close the drawing, please note that I change the scrline to:
(setq scrline (strcat "open" " " n2 " " "(load rt.lsp)" " " "(RT_BSR)" " " "qsave" " " "close" " "));;;;;;;COMMANDS FOR BATCH GO HERE

Did I somehow mess it up?

Lee Mac

  • Seagull
  • Posts: 12924
  • London, England
Re: Opening Drawings and Running LISP
« Reply #11 on: July 27, 2011, 07:33:19 PM »
This old program of mine may help with your scripting.  :-)

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Opening Drawings and Running LISP
« Reply #12 on: July 27, 2011, 07:43:52 PM »
Wow, that is a lot of code Lee. It will take me a while to go through that and get what I need.

In the meanwhile the script writer that I have is writing the script, the problem is that when it is run it get through the first file, but will not save it or close it, I am guessing there is something wrong in the script, here is the output from the script:

Code: [Select]
open "H:\BEI-Temp\ROOF PLAN KEYNOTES.dwg" (load rt.lsp) (RT_BSR) qsave close
open "H:\BEI-Temp\SITE PLAN -DEMO KEYNOTES.dwg" (load rt.lsp) (RT_BSR) qsave close
open "H:\BEI-Temp\SITE PLAN -REMODEL KEYNOTES.dwg" (load rt.lsp) (RT_BSR) qsave close

Ok, I just tested both and it appears to work if I don't rum my lisp routine, which is as follows:

Code: [Select]
  (defun RT_BSR (/)
(vl-init2)
  (setvar "tilemode" 1)
  (DelAllLayouts)
  (command "._-layer" "_unlock" "*" "_on" "*" "_freeze" "*" "")
  (cond
((= (getvar "pstylemode") 1)
  (command "._convertpstyles" "conversion.stb")
)
  )
  (command "._-insert" "H:\\0ACAD Support\\AutoCAD\\Support Files\\Plot Styles\\shaded.dwg" nil)
  (command "._-layer" "_thaw" "*" "_color" "8" "*" "_pstyle" "SHADED" "*" "")
  (setvar "setbylayermode" 113)
  (command "._setbylayer" "all" "" "_yes" "_yes")
  (RT_Lay0)
  (princ)
)
Supporting Functions are:
Code: [Select]
(defun RT_Lay0 ( / i ss e el d e f )
  (if (setq i -1 ss (ssget "_X" '((8 . "0"))))
    (while (setq e (ssname ss (setq i (1+ i)))) (setq el (entget e))
      (setq d (cond ( (cdr (assoc 2 el)) ) ("Misc"))
            e (cond ( (cdr (assoc 0 el)) ) ("MiscTyp"))
            f (cond ( (cdr (assoc 5 el)) ) ("MiscOb"))
      )
      (entmod (subst (cons 8 (vl-string-translate ":;*?,<>/\\|." "$$$$$$$$$$$" (strcat "WAS0 - " d "-" e "-" f))) (assoc 8 el) el))
    )
  )
  (princ)
)


(defun DelAllLayouts (/ Layout TabName)
  (vlax-for Layout
                     (vla-get-Layouts
                       (vla-get-activedocument (vlax-get-acad-object))
                     )
      (if
          (/= (setq TabName (strcase (vla-get-name layout))) "MODEL")
         (vla-delete layout)
      )
    )
  )
(defun VL-Init2 (/)
  (vl-load-com)
(setq *ACAD_DOC* (vla-get-ActiveDocument (vlax-get-acad-object))
  *ACAD_LAYERS* (vla-get-layers *ACAD_DOC*)
)
)

Any ideas what in this would cause the script to stop?
« Last Edit: July 27, 2011, 07:59:08 PM by cmwade77 »

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2149
  • class keyThumper<T>:ILazy<T>
Re: Opening Drawings and Running LISP
« Reply #13 on: July 27, 2011, 08:05:29 PM »

I'm surprised no-one has mentioned AutoCAD ScriptPro 2.0

http://labs.autodesk.com/utilities/adn_plugins/supported_apps/  (Nov 2010)

It can load and run lisp ( and provide suitable error trapping to eradicate the gremlins that will halt conventional scripts.

Just a thought :)
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

jaydee

  • Guest
Re: Opening Drawings and Running LISP
« Reply #14 on: July 28, 2011, 12:44:27 AM »
This the script batch engine i have been using

http://www.angelfire.com/clone/ezscript/
If all your lisp are preloaded and you're running your lisp via command lines, then simply open a text editor (notepad)
and save file as .scr and fill the script file with a series of your command that you normally typed them in in acad.

ie
mycmd1
mycmd2
mycmd3
mycmd4
mycmd5

Hope this help.

deegeecees

  • Guest
Re: Opening Drawings and Running LISP
« Reply #15 on: July 28, 2011, 10:26:22 AM »
My halfacent:

http://www.theswamp.org/index.php?topic=6657.msg84407#msg84407
Ok, so nthat works for the most part, but it does not save and close the drawing, please note that I change the scrline to:
(setq scrline (strcat "open" " " n2 " " "(load rt.lsp)" " " "(RT_BSR)" " " "qsave" " " "close" " "));;;;;;;COMMANDS FOR BATCH GO HERE
(setq scrline (strcat "open" " " n2 " " "(load\"batch_core\")" " " "batch_insert" " " "qsave" " " "close"))

Did I somehow mess it up?


I included the original for you to examine the differences. It's old code, and although it ain't pretty, it works.

Also, note that in the 'batch_core' lisp, the call out uses c: to get a command line call.

Code: [Select]
(defun c:batch_insert ()
(setq tester1 (SSGET "X" (LIST (CONS 0 "insert") (CONS 2 "Tsbder57"))))
(if tester1
(progn
(SETQ fixer1 (ssname tester1 0))
(SETQ ats3 (ENTGET fixer1))
(if ats3
(progn
(setq attit1(cdr (assoc 41 ats3)))
(setq wutscale (rtos attit1))
(command "-insert" "c:\\yourblock" "0,0" wutscale wutscale "")
(command "-insert" "c:\\yourotherblock" "0,0" wutscale wutscale "")
)
)
)
)


(princ)

)
« Last Edit: July 28, 2011, 10:30:10 AM by Plankton »

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Opening Drawings and Running LISP
« Reply #16 on: July 28, 2011, 11:14:45 AM »

I'm surprised no-one has mentioned AutoCAD ScriptPro 2.0

http://labs.autodesk.com/utilities/adn_plugins/supported_apps/  (Nov 2010)

It can load and run lisp ( and provide suitable error trapping to eradicate the gremlins that will halt conventional scripts.

Just a thought :)
Unfortunately the last time that I tried using this, it opened a new session of AutoCAD for every single drawing, which added about 2 minutes per drawing, not bad when there are only a few drawings, but when I need the routine, it quite often is for 200+ drawings. Add to that the fact that I need to set options prior to running the script and you can see things would get complicated with it.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Opening Drawings and Running LISP
« Reply #17 on: July 28, 2011, 11:27:28 AM »
My halfacent:

http://www.theswamp.org/index.php?topic=6657.msg84407#msg84407
Ok, so nthat works for the most part, but it does not save and close the drawing, please note that I change the scrline to:
(setq scrline (strcat "open" " " n2 " " "(load rt.lsp)" " " "(RT_BSR)" " " "qsave" " " "close" " "));;;;;;;COMMANDS FOR BATCH GO HERE
(setq scrline (strcat "open" " " n2 " " "(load\"batch_core\")" " " "batch_insert" " " "qsave" " " "close"))

Did I somehow mess it up?


I included the original for you to examine the differences. It's old code, and although it ain't pretty, it works.

Also, note that in the 'batch_core' lisp, the call out uses c: to get a command line call.

Code: [Select]
(defun c:batch_insert ()
(setq tester1 (SSGET "X" (LIST (CONS 0 "insert") (CONS 2 "Tsbder57"))))
(if tester1
(progn
(SETQ fixer1 (ssname tester1 0))
(SETQ ats3 (ENTGET fixer1))
(if ats3
(progn
(setq attit1(cdr (assoc 41 ats3)))
(setq wutscale (rtos attit1))
(command "-insert" "c:\\yourblock" "0,0" wutscale wutscale "")
(command "-insert" "c:\\yourotherblock" "0,0" wutscale wutscale "")
)
)
)
)


(princ)

)
Thank you, I figured I probably mangled that line somehow, I have that working now, next up is adding in the rest of what I need my LISP routine to do.

deegeecees

  • Guest
Re: Opening Drawings and Running LISP
« Reply #18 on: July 28, 2011, 01:43:36 PM »
YW. Nice to see that getting some extended mileage. I used it for a large firm that needed to update 1000's of dwgs. Set it and forget it.


Boldly go forth and batch. lol