Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why does my LISP crash now??

13 REPLIES 13
Reply
Message 1 of 14
RustyWa
346 Views, 13 Replies

Why does my LISP crash now??

This LISP file does not work in AutoCAD 2006 anymore. Can someone help debug it for me?

A little history. This is a LISP command from an old piping program I've been dragging along with me since AutoCAD 9 days. I've always have been able to update the LISP files in the past, but this one I'm stumped.

Any help would be appreciated.
13 REPLIES 13
Message 2 of 14
kozmos
in reply to: RustyWa

No definition for vartiable SF
here:
========================
(setq BRK-ANG (angle PNT1 PNT2)
D1 (distance PNT1 PNT2)
Pc (polar PNT1 BRK-ANG (* 0.5 D1))
CNT (fix (max 8 SF)) ;;; what is SF?
CNT (fix (min CNT 12)))
========================
Message 3 of 14
Anonymous
in reply to: RustyWa

Hi Rusty,your code wrong location on "SF" variable !!
here your code completed.
(defun CIRCTRIMS (P1 P2 / BRK-ANG D1 Pc CNT SS1 CIRC-ENT O-BMODE O-PBOX)
(setq BRK-ANG (angle P1 P2))
(setq D1 (distance P1 P2))
(setq Pc (polar P1 BRK-ANG (* 0.5 D1)))
(setq CNT (fix (max 8 SF))) ; >>>>wrong here what "SF" ???
(setq CNT (fix (min CNT 12)))
(command "CIRCLE" Pc "D" D1)
(setq SS1 (ssget Pc))
(if SS1 (progn (setq EX-ENT (ssname SS1 0)) (redraw EX-ENT)))
(setq CIRC-ENT (entlast))
(setq O-BMODE (getvar "BLIPMODE"))
(setq O-PBOX (getvar "PICKBOX"))
(setvar "BLIPMODE" 0) (setvar "PICKBOX" 2)
(command "TRIM" CIRC-ENT "" Pc "")
(repeat CNT
(setq Pt (polar Pc BRK-ANG (* 0.125 D1)))
(command "TRIM" CIRC-ENT "" Pt "")
(setq BRK-ANG (+ BRK-ANG (/ (* 360.0 dr) CNT))))
(setvar "BLIPMODE" O-BMODE) (setvar "PICKBOX" O-PBOX)
(entdel CIRC-ENT)
(princ)
)

(defun C:CIRCTRIM (/ P1 P2 P3 E1)
(prompt "Draw two point circle.. ")
(setq P1 (getpoint "\nFirst point on diameter: "))
(prompt "\nSecond point on diameter: ")
(command "CIRCLE" "2P" P1 pause)
(setq P2 (getvar "LASTPOINT"))
(setq E1 (entlast))
(entdel E1)
(CIRCTRIMS P1 P2)
(princ)
)


wrote in message news:5042922@discussion.autodesk.com...
This LISP file does not work in AutoCAD 2006 anymore. Can someone help
debug it for me?

A little history. This is a LISP command from an old piping program I've
been dragging along with me since AutoCAD 9 days. I've always have been able
to update the LISP files in the past, but this one I'm stumped.

Any help would be appreciated.
Message 4 of 14
RustyWa
in reply to: RustyWa

Thanks guys. I think SF is set by this LISP that is loaded and set when I start the piping program. Sorry about not including this in the first place, but I thought the CIRCTRIM command wasn't dependant on other settings.

;----- Sets plot scale factor
(defun SCALEFACTOR (/ ?1 C-SF STR)
(setvar "CMDECHO" 0)
(if (and USER-SF (not (null (eval (read USER-SF)))) (numberp (eval (read USER-SF))))
(setq SF (eval (read USER-SF)))
(progn
(if (or (null SF) (not (numberp SF)))
(setq STR "NOT SET") (setq C-SF SF STR (rtos C-SF 2 1)))
(setq ?1 nil)
(initget (+ 2 4))
(menucmd "S=PDQ-PIPE.PLOTSCALE")
(setq ?1 (getint (strcat "\nEnter plot scale < 1 = " STR " >: 1 = ")))
(menucmd "S=")
(if (= nil ?1) (setq SF C-SF) (setq SF (float ?1)))))
(prompt (strcat "\nPlot scale factor is set to " (rtos SF 2 1)))
(prin1)
)

(defun C:SF ()
(SCALEFACTOR)
(princ)
)
Message 5 of 14
RustyWa
in reply to: RustyWa

I made a little progress. I don't understand it, but if I remark out the following, the CIRCTRIM command seems to work. Anyone know why this LISP works in AutoCAD 2002 but not in 2006? Thanks.

;(repeat CNT
;(setq Pt (polar Pc BRK-ANG (* 0.125 D1)))
;(command "TRIM" CIRC-ENT "" Pt "")
;(setq BRK-ANG (+ BRK-ANG (/ (* 360.0 dr) CNT))))
Message 6 of 14
EC-CAD
in reply to: RustyWa

Looks like this line is a problem. It uses a 'function'
or 'variable' by the name of 'dr'.. and I don't see it
defined.
(setq BRK-ANG (+ BRK-ANG (/ (* 360.0 dr) CNT))))

Bob
Message 7 of 14
RustyWa
in reply to: RustyWa

Could dr be a standard setting in older versions of autocad that is no longer used? I don't see it being defined (setq) in any of the lisp files for my program.
Message 8 of 14
EC-CAD
in reply to: RustyWa

The 'dr' is not a function / short-cut key that I know of.
In the line:
(setq BRK-ANG (+ BRK-ANG (/ (* 360.0 dr) CNT))))
.. it looks like a 'constant' is needed there, so try:
(setq BRK-ANG (+ BRK-ANG (/ (* 360.0 1.0) CNT))))
and see what it does.

Bob
Message 9 of 14
EC-CAD
in reply to: RustyWa

Better yet, try PI in there:
(setq BRK-ANG (+ BRK-ANG (/ (* 360.0 pi) CNT))))

Bob
Message 10 of 14
RustyWa
in reply to: RustyWa

I think I've narrowed it down some more. It appears to be related to the trim command. If there is nothing to trim in the circle, the program hangs and won't go on.

Could this be a behavior change from earlier versions of the trim command?

Is there a way around it?

Thanks again.
Message 11 of 14
EC-CAD
in reply to: RustyWa

RustyWa,
I'm not sure what the original program was intended to
do, but if you change it slightly.. runs better.
(defun CIRCTRIM (PNT1 PNT2 / BRK-ANG D1 Pc CNT SS1 CIRC-ENT O-BMODE O-PBOX)
;; Degrees to Radians, Radians to Degrees
(defun dtr (d) (* pi (/ d 180.0)))
(defun rtd (r) (* 180.0 (/ r pi)))

(setq BRK-ANG (angle PNT1 PNT2)
D1 (distance PNT1 PNT2)
Pc (polar PNT1 BRK-ANG (* 0.5 D1))
CNT (fix (max 8 SF))
CNT (fix (min CNT 12)))
(command "CIRCLE" Pc "D" D1)
(setq SS1 (ssget Pc))
(if SS1 (progn (setq EX-ENT (ssname SS1 0)) (redraw EX-ENT)))
(setq CIRC-ENT (entlast)
O-BMODE (getvar "BLIPMODE")
O-PBOX (getvar "PICKBOX"))
(setvar "BLIPMODE" 0) (setvar "PICKBOX" 2)
(command "TRIM" CIRC-ENT "" Pc "")
(repeat CNT
(setq Pt (polar Pc BRK-ANG (* 0.125 D1)))
(command "TRIM" CIRC-ENT "" Pt "")
;; (setq BRK-ANG (+ BRK-ANG (/ (* 360.0 dr) CNT))))
(setq BRK-ANG (+ BRK-ANG (/ (dtr 360.0) CNT)))
); repeat
(setvar "BLIPMODE" O-BMODE) (setvar "PICKBOX" O-PBOX)
(entdel CIRC-ENT)
(princ)
)

I added new functions for 'dtr' and 'rtd' .. Degrees to radians,
and Radians to degrees, replaced the 'dr' with:
(dtr 360.0), which returns PI.

It might be helpful if you would prepare a simple .dwg, zip it up
and attach to this posting... to show 'before' and 'after' running
this Lisp.. make a couple of notes in there..
Maybe we can come up with a better (updated) version of
lisp program to do the same result..

Bob
Message 12 of 14
RustyWa
in reply to: RustyWa

I got the CIRCTRIM command to work, for the most part.

I ended up changing the setq PT section from 0.125 to 0.5, which now matches the Pc setq setting. After this change the lisp file seems to work. Not sure why, as I'm not a programmer. But I'm cool with that. 🙂

I can still get the program to crash. I'm pretty sure it crashes at the section where it's calling the trim command. It runs TRIM, selects CIRC-ENT for its trim edge, but if it doesn't find an expected line or polyline at the Pc or Pt point, it crashes.

Any clues to get around this problem?

Thanks.
Message 13 of 14
EC-CAD
in reply to: RustyWa

Try this sequence for the repeat loop...
(repeat CNT
(setq ss nil); null selection set..
(setq Pt (polar Pc BRK-ANG (* 0.5 D1)))
(setq ss (ssget "C" Pt Pt)); grab entity at Pt
(if ss
(command "TRIM" CIRC-ENT "" Pt "")
(prompt "\nNothing to Trim at Pt")
); if
(setq BRK-ANG (+ BRK-ANG (/ (dtr 360.0) CNT)))
); repeat

What it does, is to try to 'grab' something at the Pt..
And if nothing, (ss will be nil), just prompts..else,
does the Trim operation.

Bob
Message 14 of 14
RustyWa
in reply to: RustyWa

That seemed to do the trick!!

I had to change the ssget from a crossing window to a "pick" at Pt, otherwise it wasn't grabbing polylines with thicknesses defined on them.

I really appreciate your help Bob.

Eric

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost