PDA

View Full Version : help with old .lsp file


tom.g
2008-12-19, 02:00 PM
Hello,
Enclosed is an old .lsp file we use to draw a wire pull on drawer fronts of casework.
It was set up to draw a 4" wide pull which is what we use 99.9% of the time. I am working on a big job that needs 5" wide pulls. I am not the .lsp guru I wish I was so I need some help.
As you can see, the user picks the lower left and upper right of the space and the pull is centered vertically and horizontally. If I just change the length to 5, the pull is not centered.

thanks for your help
Tom Goodman
Wilson. NC

tedg
2008-12-19, 03:31 PM
Try this:

;----- HPULL5 -----
(defun c:hpull5 () ;position a horizontal pull
;(savvar)
(setq osm (getvar "osmode"))
(setq lyr (getvar "clayer"))
;;LCA - WARNING: The OSMODE sysvar has changed.
(setvar "osmode" 32)
(setq p1 (getpoint "Lower left: "))
(setq p2 (getpoint "Upper right: "))
;;LCA - WARNING: The OSMODE sysvar has changed.
(setvar "osmode" 0)
;(quiet)
;;LCA - COMMENT: The LAYER command has new options.
(if (= (tblsearch "layer" "2") nil)
(command "LAYER" "MAKE" "2" "COLOR" "2" "" ""))
(command "layer" "s" "2" "")
(setq x (- (car p2) (car p1)) x (/ x 2) x (- x 2.5))
(setq x (+ (car p1) x))
(setq y (- (cadr p2) (cadr p1)) y (/ y 2) y (+ y 0.15625))
(setq y (- (cadr p2) y))
(command
"line" (list x y)
(list (+ x 5.0) y)
(list (+ x 5.0) (+ y 0.3125))
(list x (+ y 0.3125))
"c"
)
(setvar "osmode" osm)
(setvar "clayer" lyr)
;(resvar)
(princ)
)

I didn't recognize some of the code, (in red) so I disabled it (?)
I added some stuff to clean it up too (in blue)
I fixed two values in your code to divide by two to center your pull

Opie
2008-12-19, 04:18 PM
I didn't recognize some of the code, (in red) so I disabled it (?)
I added some stuff to clean it up too (in blue)
I fixed two values in your code to divide by two to center your pull

It appears the items in Red were two external routines. The first was most likely a routine that saved the current variables (the ones you added in Blue), while the second was to restore them.

tedg
2008-12-19, 04:21 PM
It appears the items in Red were two external routines. The first was most likely a routine that saved the current variables (the ones you added in Blue), while the second was to restore them.
Ahhh, thanks.... makes sense now.
What about "(quiet)", do you think it's part of external routine aswell?

tom.g
2008-12-19, 04:27 PM
Hi Ted,
Thanks for the help. Here are those file you were asking about.

Tom G.



;----- SAVVAR -----
(defun savvar () ;save current settings
(setq sbm (getvar "blipmode")
sce (getvar "cmdecho")
sos (getvar "osmode")
slr (getvar "clayer")
)
)
(savvar)

;----- RESVAR -----
(defun resvar () ;restore settings
(cond
((/= (getvar "clayer") slr) ;avoid message if unchanged
(command "layer" "s" slr "")
)
)
(setvar "blipmode" 1) ;was sbm, reset anyway to on
(setvar "cmdecho" sce)
(setvar "osmode" sos)
)
;----- QUIET -----
(defun quiet () ;avoid "noise"
(setvar "blipmode" 0)
(setvar "cmdecho" 0)
)

Moderator Note:
Please use [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code)

Opie
2008-12-19, 04:36 PM
Ahhh, thanks.... makes sense now.
What about "(quiet)", do you think it's part of external routine aswell?
It probably is an external routine, if I had to guess.

tedg
2008-12-19, 04:37 PM
Hi Ted,
Thanks for the help. Here are those file you were asking about.

Tom G.
;----- SAVVAR -----
(defun savvar () ;save current settings
(setq sbm (getvar "blipmode")
sce (getvar "cmdecho")
sos (getvar "osmode")
slr (getvar "clayer")
)
)
(savvar)

;----- RESVAR -----
(defun resvar () ;restore settings
(cond
((/= (getvar "clayer") slr) ;avoid message if unchanged
(command "layer" "s" slr "")
)
)
(setvar "blipmode" 1) ;was sbm, reset anyway to on
(setvar "cmdecho" sce)
(setvar "osmode" sos)
)
;----- QUIET -----
(defun quiet () ;avoid "noise"
(setvar "blipmode" 0)
(setvar "cmdecho" 0)
)
Very well then, thanks it helps to understand what you posted.
So you can ignore that stuff in red and blue that I put in your code, just adjust those values in PINK on your routine and you should be all set.

CAB2k
2008-12-20, 10:09 PM
Another way to handle the task.
(defun DrawDrawPull (width height / p1 p2 x1 x2 y1 y2 midpt MakeLine)
(defun MakeLine (spt ept lay)
(entmakex
(list (cons 0 "LINE")
(cons 6 "BYLAYER")
(cons 8 lay)
(cons 10 spt)
(cons 11 ept)
(cons 62 256)
)
)
)

;;(savvar) ; this routine saves sys vars

(or height (setq height 0.3125)) ; default height

;;LCA - WARNING: The OSMODE sysvar has changed.
(setvar "osmode" 32)
(if (and
(setq p1 (getpoint "Pick corner of draw: "))
(setq p2 (getpoint "Pick diaginal corner of draw: "))
)
(progn
;;LCA - COMMENT: The LAYER command has new options.
(if (tblsearch "layer" "2")
(command "layer" "s" "2" "")
(command "LAYER" "MAKE" "2" "COLOR" "2" "" "")
)
(setq midpt (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.)))
(setq x1 (- (car midpt) (/ width 2.))
x2 (+ (car midpt) (/ width 2.))
)
(setq y1 (- (cadr midpt) (/ height 2.))
y2 (+ (cadr midpt) (/ height 2.))
)
(MakeLine (list x1 y1)(list x2 y1) "2")
(MakeLine (list x1 y1)(list x1 y2) "2")
(MakeLine (list x2 y1)(list x2 y2) "2")
(MakeLine (list x1 y2)(list x2 y2) "2")
)
)
;;(resvar) ; this routine restore saved sys vars
(princ)
)

(defun c:hpull5 ()
(DrawDrawPull 5 0.3125)
(princ)
)
(defun c:hpull4 ()
(DrawDrawPull 5 0.3125)
(princ)
)
(defun c:hpull4w ()
(DrawDrawPull 5 0.5)
(princ)
)

andrea.andreetti
2008-12-24, 05:34 AM
some variant....using the Rectang function and _UNDERSCORING command to allow language compatibilities..

;-)


(defun DrawDrawPull (width height / p1 p2 x1 x2 y1 y2 midpt MakeLine 2points)

(or height (setq height 0.3125)) ; default height

;;LCA - WARNING: The OSMODE sysvar has changed.
(setvar "osmode" 32)
(if (and
(setq p1 (getpoint "Pick corner of draw: "))
(setq p2 (getpoint p1 "Pick diaginal corner of draw: "))
)
(progn
;;LCA - COMMENT: The LAYER command has new options.
(if (tblsearch "layer" "2")
(command "._layer" "_s" "2" "")
(command "._LAYER" "_MAKE" "2" "_COLOR" "2" "" "")
)
(setq midpt (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.)))
(setq x1 (- (car midpt) (/ width 2.))
x2 (+ (car midpt) (/ width 2.))
)
(setq y1 (- (cadr midpt) (/ height 2.))
y2 (+ (cadr midpt) (/ height 2.))
)

(if (and x1 x2 y1 y2)
(progn
(setq 2points (list (list x1 y1 0.0) (list x2 y2 0.0)))
(vl-cmdf "._rectang" (car 2points) (cadr 2points))
(vl-cmdf "._chprop" (entlast) "" "_L" "2" "")
)
)
)
)
(princ)
)

(defun c:hpull5 ()
(DrawDrawPull 5 0.3125)
(princ)
)
(defun c:hpull4 ()
(DrawDrawPull 5 0.3125)
(princ)
)
(defun c:hpull4w ()
(DrawDrawPull 5 0.5)
(princ)
)