LISP crashing Autocad on last line of code

LISP crashing Autocad on last line of code

brandtpileggi
Contributor Contributor
1,217 Views
7 Replies
Message 1 of 8

LISP crashing Autocad on last line of code

brandtpileggi
Contributor
Contributor

Good afternoon everyone! I have this routine that is just about done except that it crashes autocad or gets into an infinite loop right at the end. Everything crashes when I re-open the original file. If I comment that and everything below it out, it works. If I break them into 2 lisp commands, both halves work perfectly fine. It's just when they're in the same file or if the second half LISP is being called from within the first. Even if I have both halves as functions and try to call them from a 3rd LISP, even if I put delays and repeat the command for the 2nd half over and over, it just ignores the second half. Thank you to everyone for your time!

 

(defun c:TakeItAll ()

;set SDI to 1 [Single-Drawing Interface],
(setvar "filedia" 0)
(setvar "SDI" 1)

;QSAVE the current drawing,
(command "_qsave")

;OPEN the other one [which will CLOSE the current one],
(command "_.open" "c:\\source\\filepath")

;select all lines on layer 1-4

(command "._copybase" "_non" '(0 0) (ssget "_X" '((8 . "layer1, layer2, layer3, layer4"))) "")

 

;--------End of first half---------;

;--------beginning of second half---------;

 

;open original file  [<---- Locks up/eternally loops somewhere around here.]
(command "_.open" "_Y" "C:\\target\\filepath")


;and paste to coordinates
(command "_.pasteclip" '(100 100))

;reset filedia and sdi
(setvar "filedia" 1)
(setvar "SDI" 0)

;lay back and greet our robot overlords

)

0 Likes
1,218 Views
7 Replies
Replies (7)
Message 2 of 8

scot-65
Advisor
Advisor
First off, SDI will be obsolete (/alredy is for R2020).

Not to promote 3rd. party software, but
have you looked into AutoHotKey?
Maybe needs a SCR file to assist in object selection...

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 3 of 8

Scottu2
Advocate
Advocate

Hello brandtpileggi,

 

When a lisp routine is loaded, a copy is loaded for the current drawing.

In other words switching between drawings the lisp routines may have the same routine name, but all its variables and settings are for that drawing only.

 

Using lisp to open a different drawing is like switching between drawings and does not continue.

Closing the current drawing closes all lisp routines for that drawing.

 

However, as noted by Scot-65, use a script (.scr)

The lisp routine can run a script like (command "script" filename).

Each line of the script file will contain the commands to open file, commands to perform just like typing them (it can even be a lisp routine with answers when it prompt for it), close, then repeat for the next file.

 

 

0 Likes
Message 4 of 8

dbhunia
Advisor
Advisor

Try Like this (its working for me in AutoCAD 2018/2019)....

 

(defun c:TakeItAll ()

	(setvar "filedia" 0)
	(setvar "SDI" 1)

	(command "_qsave")
	(command "_.fileopen" "c:\\source\\filepat")
	(command "._copybase" "_non" '(0 0) (ssget "_X" '((0 . "LINE")(8 . "layer*"))) "")
	 
	(command "_.fileopen" "_Y" "C:\\target\\filepath")
	(command "_.pasteclip" '(100 100))

	(setvar "filedia" 1)
	(setvar "SDI" 0)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 8

Scottu2
Advocate
Advocate

Hello dbhunia,

 

I learned something new!  Using SDI (single document) keep the lisp going.

The routine worked, using autocad 2019.

I made one change, changed copybase to cutclip since pasteclip is used.

(command "_.cutclip" (ssget "_X" '((0 . "LINE")(8 . "layer*"))) "")

 

It would be nice to specify cutclip with a base point like copybase to provide an accurate insertion point.

 

0 Likes
Message 6 of 8

john.uhden
Mentor
Mentor

I am pretty sure you can't continue AutoLisp through multiple drawings unless you...

(setvar "lispinit" 0)

 

Type: Integer
Saved in: Registry
Initial value: 1

When single-document interface is enabled, specifies whether AutoLISP-defined functions and variables are preserved when you open a new drawing or whether they are valid in the current drawing session only.

0 AutoLISP functions and variables are preserved from drawing to drawing

1 AutoLISP functions and variables are valid in the current drawing only

WhenSDI is set to 0, AutoLISP always behaves as if LISPINIT were set to 1. For information about the behavior of AutoLISP-defined functions and variables in a multiple-document interface, see Designing for a Multiple Document Environmentin the AutoLISP Developer's Guide.

John F. Uhden

0 Likes
Message 7 of 8

dbhunia
Advisor
Advisor

Another way you can try .....

 

(defun c:TakeItAll ( / ss)

	(setvar "filedia" 0)
	(setvar "SDI" 1)

	(command "_qsave")
	(command "_.fileopen" "c:\\source\\filepath")
	(command "._copybase" "_non" '(100 100) (setq ss (ssget "_X" '((0 . "LINE")(8 . "layer*")))) "")
	(command "_erase" ss "")
	
	(command "_.fileopen" "_N" "C:\\target\\filepath")
	(command "_.pasteclip" '(100 100))

	(setvar "filedia" 1)
	(setvar "SDI" 0)
)

 

For "Cut clip with Base point" check <<This>> .......

I personally do not know about "Autodesk Fabrication 2019"....

 

Hi @john.uhden  you are absolutely right about the purpose of "LISPINIT"..... But for the particular requirement where you are playing with CLIP with Known Base Point for Copy/Paste, there we do not have to set "LISPINIT" to "0".

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 8 of 8

john.uhden
Mentor
Mentor
Um, err, but what continues the process in the 2nd DWG?

<>
Virus-free.
www.avg.com
<>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

John F. Uhden

0 Likes