Lisp works but autocad fails

Lisp works but autocad fails

DGRL
Advisor Advisor
1,030 Views
7 Replies
Message 1 of 8

Lisp works but autocad fails

DGRL
Advisor
Advisor

Dear forum members,

 

Having an very simple routine but my system keeps failing to execute it


My issue

I run this script and on the last part of it when it opens an new dwg my system hangs and need to kill process through task manager

Can someone test this routine and let me know what is wrong?
I cant figure this out anymore

 

This routine simply opens an dwg and closes it.

If this works I will add more into it

Error that I get back on last dwg is NIL

Acad simply hangs

 

 

(defun GrabAllFiles (Path FileExt / tempPath FileList revdate dwgname tempsize strrev status_o status_t strtitle)
; [Path] is the path to search it, and all it's sub-directory
; [FileExt] is the extenstion (with the period) of the type of files to look for.
; Example (GrabAllFiles "c:\\" ".dwg")

 (setq Path
  (if (= (substr Path (strlen Path)) "\\")
   Path
   (strcat Path "\\")
  )
 )
 (foreach file (vl-directory-files Path)
  (setq tempPath (strcat Path file))
  (if
   (not
    (or
     (= file ".")
     (= file "..")
    )
   )
   (if (vl-file-directory-p tempPath)
    (setq FileList (append FileList (GrabAllFiles tempPath FileExt)))
    (if (= (strcase FileExt) (strcase (vl-filename-extension tempPath)))
     (setq FileList (cons tempPath FileList))
    )
   )
  )
 )
 FileList
)

(setq a (GrabAllFiles "PATH TO DIR WITH DWG" ".dwg"))


(foreach dwg a
(command "open" dwg)
(command "new" "y")
);end foreach
(setvar "sdi" 0)
(command "new" "y")

 

The 2 red lines let my system hang for ever

I have about 10 dwg's in the dir that I read out and the routine is doing all of them except the last dwg

 

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Accepted solutions (1)
1,031 Views
7 Replies
Replies (7)
Message 2 of 8

DGRL
Advisor
Advisor

If I use the close command after the last dwg autocad closed it but the cpu remains in high load


Does any of you know why autocad remains in high cpu load and how can I avoid such?

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant

[That's not a "script" -- that word has a specific, and different, meaning in AutoCAD.]

 

An AutoLisp routine can't start in one drawing and continue in another.  You'll have to find another way to do it.  One way is through a [true] Script and use of something like ScriptPro to run it in different drawings -- Search the Forum for examples.  In connection with some of those you will find some other approaches suggested.

Kent Cooper, AIA
0 Likes
Message 4 of 8

DGRL
Advisor
Advisor

Hi @Kent1Cooper

 

Thanks for the answer and correcting me

 

For your info
The way I open dwg's with this routine is working Try it yourself

Make an directory and fill it with a few dwg's Refer to that directory in the routine and run it


I just tried it an a machine of my colleague and on his system this code is working perfect.

I used this code many times before with success

 

For some reason on my system it is not working anymore WHILE IN FACT IT WORKED a few days ago

Maybe some settings are changed but I don't have a clue

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

@DGRL wrote:

....
The way I open dwg's with this routine is working Try it yourself

Make an directory and fill it with a few dwg's Refer to that directory in the routine and run it

.... 


Okay -- this is what I get on loading, having set up a C:\temp directory containing drawings called trash, junk and garbage:

 

Command: open
Command: c:\temp\trash.dwg Unknown command "DWG".  Press F1 for help.

Command: new
Command: y Unknown command "Y".  Press F1 for help.

Command: open
Command: c:\temp\junk.dwg Unknown command "DWG".  Press F1 for help.

Command: new
Command: y Unknown command "Y".  Press F1 for help.

Command: open
Command: c:\temp\garbage.dwg Unknown command "DWG".  Press F1 for help.

Command: new
Command: y Unknown command "Y".  Press F1 for help.

Command: new
Command: y Unknown command "Y".  Press F1 for help.

Command: nil

 

It does create the list of drawings:

 

Command: !a
("c:\\temp\\trash.dwg" "c:\\temp\\junk.dwg" "c:\\temp\\garbage.dwg")

 

But none of the drawings is open [is it supposed to end up with all of them open in AutoCAD?], nor has anything happened in any of them [modified times not updated, for instance], nor are any New drawings created.

 

[Acad2016 vanilla here.  The New command doesn't have a "y" option -- are you using an overlay program that has a differently-defined New command?]

Kent Cooper, AIA
0 Likes
Message 6 of 8

john.uhden
Mentor
Mentor

I have never used SCRIPTPRO.  This old dog uses acaddoc.lsp which gets loaded with every drawing open or new.  If I start something in one drawing and want it to continue (sort of) in the next, I will set a symbol in the bulletin board (vl-bb-set) that acaddoc.lsp can look for (vl-bb-ref) and take its course depending on the value.

Couple that with MDI and you can have one DWG open others, preferably one at a time.  That's how I processed over 13,000 drawings in one AutoCAD session.

John F. Uhden

0 Likes
Message 7 of 8

ActivistInvestor
Mentor
Mentor

@DGRL wrote:

Hi @Kent1Cooper

 

Thanks for the answer and correcting me

 

For your info
The way I open dwg's with this routine is working Try it yourself

Make an directory and fill it with a few dwg's Refer to that directory in the routine and run it


I just tried it an a machine of my colleague and on his system this code is working perfect.

I used this code many times before with success

 

For some reason on my system it is not working anymore WHILE IN FACT IT WORKED a few days ago

Maybe some settings are changed but I don't have a clue

 

 

 


You can do that if the SDI system variable is 1, but not if it is 0.

0 Likes
Message 8 of 8

DGRL
Advisor
Advisor
Accepted solution

Found solution myself

 

after the last dwg was processed the routine wanted to close the last dwg

Not allowed with SDI on 1

That is the reason for autocad to hang with full cpu load.

 

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes