Jump to content

Recommended Posts

Posted

Good Morning,

In the last few days I have been looking at AutoCad Core Console to do  stuff on a batch of DWGs. So I have a simple LISP file to select the files to process, and the script file. It loads the DWGs and script file as it should and runs the core console, all good so far. I now want to load lisp files to core console via the script to use the lisp. It appears that using 'load' works but calling the lisp afterwards nothing happens.... and I don't know why.

 

here is what I am doing:

Basic Lisp file:

(defun c:cctest (/ dwg-lst scr)
  (setq dwg-lst (LM:getfiles "Select Drawings" "C:\\Users\\-thisisme-\\Desktop" "dwg")) ;;Returns a list of files. See Lee Macs website to get this
  (setq scr (getfiled "Select script file" "" "scr" 0))

  (if (and scr
           dwg-lst
      ) ; end and
    (foreach dwg dwg-lst
      (command "start"
        (strcat
          "accoreconsole.exe "
          "/i \""dwg"\" "
          "/s \""scr"\" "
          "/l en-us"
        ) ;end strcat
      ) ;end comamnd
    ) ; end foreach
  ) ; end if
)

and this is a simple script to try to load a Lisp file:

 

(load "c:\\Users\\-thisisme-\\Desktop\\DrawLine.lsp")
;;(defun c:DrawLine()
;;(command "line" "0,0" "-100,100" "")
;;)
(c:DrawLine)
.qsave

And here is my draw line lisp

 

(defun c:DrawLine()
  (command "line" "0,0" "-100,100" "")
)

So if I run core console and without closing it using as above, nothing happens, I can type in gibberish as a command, it tells me unknown command, if I type in DrawLine it accepts it but doesn't change the drawing - so I assume the LISP file has loaded. If I take out the load command and put the defun in the script file as shown then run it, then it will all work. I'm not trying anything complicated, this is as simple as I can make it for now.

 

So what am I doing wrong I wonder?

 

Thanks for any help

 

 

(if I can't do it this way, I guess I can make up a script file on the fly, saved in the temp files folder with all the lisps I want to use written directly into it, but that will be a lot more work)

Posted

not sure about this but somewhere burried deep in a dark corner of my last working braincell I recall not to use '.qsave' but just 'save'

Posted
53 minutes ago, rlx said:

not sure about this but somewhere burried deep in a dark corner of my last working braincell I recall not to use '.qsave' but just 'save'

 

Thank - I'll bear that in mind, honoured that your single brain cell woke up long enough to throw that out.

 

Didn't fix my problem though, suspect you are onto something that it will be a very basic thing

Posted

I used something like this in a script :


zoom
extents
line
(getvar "extmin")
(getvar "extmax")

line
(list (car (getvar "extmin")) (cadr (getvar "extmax")))
(list (car (getvar "extmax")) (cadr (getvar "extmin")))

zoom
.9x
save

just simple commands , no loading of other lisp file , maybe try first by putting your commands in a script


line

0,0

-100,100

 

save

Posted

Forgot to say RLX - thanks for the example, I saw that post from before and I can get that to work nicely.

 

If I copy the LISP into a script file (and along with constraints such as no 'VL-' commands and so on), it is all happy. For example, I have it plotting PDFs quite happily. So I can do it with a (c:defun…. ) or just the commands listed so long as they are all in the scr script file (my second example bit of code, lines 2, 3 and 4).

 

 

 

The ultimate goal is to string several LISPS together and run them as a batch... and I am thinking if I can load them into the coreconsole and run them from there this will be quicker than the batch process I have just now (1 second a drawing saving is enough time to get a coffee). What I use just now opens each drawing one at a time, does stuff and moves on - since it is full AutoCAD doing it, it can do everything, but ties up the computer. The idea I have, load LISP, Run LISP, load next LISP, run next LISP sounds like it should work.... As I said - a bit more work to do but I think I can copy the text out of the LSP file, paste into a SCR file and do it like your example.. but that sounds like a long way around.

Posted

in my batch appie I can select single or multiple thread core console. When you use core console in a loop , each loop starts its own core console. This works as long as the timing is right because if your start a new thread before the previous is finished your system can run out of resources. So I have an option to include a delay or the option to create one big fat bat file. This means AutoCad is free as soon as the bat file is generated and started. Code below can't be run on its own but should show you how it works (i hope)


; method 1 : use in loop
; is a little bit messier, more parallel processes, more demanding on system but is faster
; did a saveas on 185 dawings : 5 minutes so thats less then 2 sec's a drawing
; increase wait to make sure each process has enough time to finish if system runs out of recources
(defun Rlx_AcadCore_Multi_Thread ( / dwg)
  (if (and scr (vl-consp dwg-list))
    (foreach dwg dwg-list
      (command "start" (strcat "accoreconsole.exe /i " "\"" dwg "\"" " /s " "\"" scr "\"" " /l en-us"))
      ; with large drawing list pc became unresponsive when wait was zero so delay must be 1 (sec) or higher
      (if (or (not #RlxBatch-CoreConsole-Delay)(not (distof #RlxBatch-CoreConsole-Delay))
          (< (distof #RlxBatch-CoreConsole-Delay) 1)) (setq #RlxBatch-CoreConsole-Delay "1"))
      (wait (distof #RlxBatch-CoreConsole-Delay))
    )
  )
)

; method 2 : use batch file
; same drawing set took 12 minutes , disable timeout could reduce this time by 185 seconds (3 minutes)
; advantage is that its less demanding of recources so it probably runs better as backgroud task.
(defun Rlx_AcadCore_Single_Thread ( / bat dwg)
  (if (and scr (vl-consp dwg-list) (setq fp (open (setq bat "c:\\temp\\tmp.bat") "w")))
    (progn
      (foreach dwg dwg-list
    (write-line (strcat "accoreconsole.exe /i " "\"" dwg "\"" " /s " "\"" scr "\"" " /l en-us") fp)
    (write-line "timeout /t 1 /nobreak" fp); skip or adjust to match system speed
      )
      (if fp (progn (write-line "exit" fp)(close fp)(gc) (command "start" bat)))
    )
  )
)

(defun wait  (sec / stop) (setq stop (+ (getvar "DATE") (/ sec 86400.0))) (while (> stop (getvar "DATE"))))

 

the multiple thread is most fun to use and can be fastest but single thread (bat) is best to be able to free up AutoCad. But (surprise) IT has blocked the use of all bat files ...

 

  • Like 2
Posted

Maybe a solution copy all the lisps into 1 and as your using console remove the c:defuns and just let it run as global variables should not be a problem. Also (command "DRAWLINE") should work.

Posted

Thanks RLX - I went through that the other day and wondered why you were doing a pause, I was testing things on only 3 or 4 drawings so haven't encountered that problem yet

This bit will look familiar in what I have done..... (foreach dwg dwg-list       (command "start" (strcat "accoreconsole.exe /i " "\"" dwg "\"" " /s " "\"" scr "\"" " /l en-us"))

 

 

Big Al, the more I am looking at this the more I am thinking that I will need to copy the LISP definitions that I want into the script file, like you are suggesting, rather than loading them as the script runs. That's annoying if so but not the end of the world. Just feel that there should be someway to do what I want.

Posted

if the number of drawings is small , 100 or less , you'll probably won't run into the timing issue assuming your routine only needs a few seconds to complete. But if you move into the hundreds or thousands of drawings with (too) many parrallel threads , time can become a factor. Also if you work with VPN , network response time can bite you. Thats why I recently added option to first copy all drawings to local disk , run script and then put them back on network. But this all depends on your own circumstances ofcourse. Usually I only use core for simple tasks. If speed is essential I try object dbx but if this takes too much time to write , just use normal script , get a beer and relax. Computer is meant to do the hard work , not the other way around.

Posted (edited)

I know with making slides on a hundered dwg's took a little while, but not sure what happens if you open a 2nd session of Autocad ? Work in one have a script running in other as I say try it really dont know. You may see a bit of slowing down but your still working.

 

Like the idea copy dwgs from server amend on local drive check if happy bulk copy back. gets rid of network traffic problems. I would not do a 1000 in one go just 1 will hiccup can almost guarantee.

 

I thought I used Load a lisp but I only tested on like 3 dwgs and did 1 change.

Edited by BIGAL
Posted

Our document control system checks out drawings to a specific (project)folder structure based on drawing type. There engineers often pick up the drawings and create their own structure like all loops are in folder \\project-name\LD\... and then they create structure \\project-name\unit-1\Loops\... , \\project-name\unit-2\Loops\... and move loops accoordingly. But when finished all drawings must be moved back to folder where document control system left them. My (batch) app doesn't care where it finds them but when drawings are done I just say , move them back to 'document-control-program-project-folder' ,  the folder where our document program expects to find them. Never lost one bit moving them around because I check every step , rename old file to bak , check if succesful , copy new file and check if succesful. Even created extended log file , documenting every step and also have option to only show if something went wrong so in the (very) unlikely case something went wrong I know where it went wrong. Usualy zip originals first so I have always a backup if needed. Call me paranoid dragon, but if you loose info it is always your own fault.

Posted

Thanks RLX, I added a delay to the LISP and weirdly with that and only a few drawings it appears to process it a bit faster overall. So I am going to keep that in. As for the rest I have been trying a few things over the weekend and am coming to the conclusion that you cannot just load a LISP to use like you would load one into AutoCAD normally - all the LISP definitions have to be written into the script file (you can create a LISP Defun in there and call it as you need). So I am going to make up a couple of useful scripts for now, such as a PDF Plot and put this to one side for now. Thinking in the future to create a separate script file which is basically a LISP file, saved as a 'scr' file, then load and run them one at a time in the core console - see how that works - I might have more questions in the future for this....

 

And then I got a beer as you suggested.

 

Hoping the dragons are all good

 

Posted

Thanks, I had seen your blog and it was useful, I liked the link to the commands that can be used with the Core Console.

 

The basic problem I have is still there in that I cannot see how in the script file you can load and run a LISP that is saved in another file. Each batch will need a separate script file writing, which is great for procedures we do all the time such as plotting - I can have that set up - but not so great for one offs. I'm going to put this to one side for now, but have thoughts of how to make it a more useful utility (copy the LISP routine into script file created on the fly in the temp folder, then since it is all in one file use that..... problem I think is that all the useful LISPS will need a separate file to allow them to be copied into a temporary file.. which is where the work comes in)

Posted

A couple of old fashioned DOS commands

 

Copy File1+file2+File3 file4

Dir d:\cadtemp\*.dwg /b /s > dirlst.txt      makes a list of all your dwgs including sub directories.

 

For me I use Word to make scripts using Replace ^p which is end of line so can do like ^pOpen which adds open to start of every line, like wise save^p dont forget spaces in replace.

  • Like 1
Posted

I think the answer is to make your lisp routines self starting

lsp :


(defun draw-circle ( / vs vc)
  (command "_.zoom" "_extents")
  (setq vs (getvar 'viewsize) vc (getvar 'viewctr))
  (command "_.circle" vc "diameter" vs)
)

(defun c:draw-cross ()
  (command "_.line" (getvar "extmin") (getvar "extmax") "")
  (command "_.line" (list (car (getvar "extmin")) (cadr (getvar "extmax"))) (list (car (getvar "extmax")) (cadr (getvar "extmin"))) "")
  (command "_.zoom" ".9x")
)

(draw-circle)
(c:draw-cross)

 

script :


(load "c:/temp/lisp/draw-cross.lsp")
qsave

 

and yes , qsave works just as good as save despite me thinking it didn't. But when using save don't forget to set expert variable or include yes to confirm do you wish to overwrite existing drawing

 

🐉

 

 

Posted

I hate it when you wake up in the middle of the night thinking why would the lisps jut not be auto started. I was sure I had tested in aeccoreconsole. Lots of code i post I add the (c:defun) to run it on load. Rlx just posted before me will go back to sleep now.

 

Not sure need to test

(load "c:\\test\\mylisp\\draw-cross")
(draw-circle)
(c:draw-cross)
qsave

 

Posted

Thanks, and I know the feeling about waking up! Didin't have chance to look at this yesterday, but will try it today

Posted

I had a look at the suggestion to make the LISP self starting, it didn't work for me... I'll leave this for now, thanks for your help - it was useful. I honestly thought you were onto something to do it that way. I might come back to this thread later if I can work it out to make it do what I want

Posted

Sorry to learn it didn't work for you Steven. Sample I posted worked for me so only thing I could offer is if you sent me a private message with an example of a drawing , your lsp and scr file so I could check on my own system if it works or maybe just a problem with one of your files. And else , normal script (and a coffee break) it is for you...

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...