PDA

View Full Version : Balloon Lisp


sgiffin
2007-10-16, 11:54 PM
I'm trying to update the old balloon lisp to incorporate turning off ortho and osnap and turn them back to their original state after the routine finishes. It's not working for me for some reason. I'd also like it to make the arrow and line one piece like the qleader but I have no idea how to do that. And I'd like it to use the osnap "nearest" as the default pick point if that's possible.

I know there's a much newer Ballons lisp routine that is much more advanced and I may use that one once in a while if I need the balloon to be a polygon but this one is much faster to use.


(defun c:b ()
(setq *CMD* (getvar "cmdecho")
*ORT* (getvar "orthomode")
*OSM* (getvar "osmode")
)
(setvar "cmdecho" 0)
(setvar "orthomode" 0)
(setvar "osmode" 0)
(setq ds (getvar "dimscale"))
(initget 1) (setq p1 (getpoint "\nFrom point: "))
(command "_nea")
(initget 1) (setq p2 (getpoint p1 "\nTo point: "))
(if (<= (car p2) (car p1)) (setq b (* -0.375 ds))
(setq b (* 0.375 ds)))
(setq p3 (list (+ (car p2)(/ b 4)) (cadr p2)))
(setq p4 (list (+ (car p3) (/ b 2)) (cadr p3)))
(command "dim1" "leader" p1 p2 p3 ^C^C)
(command "circle" p4 (/ (abs b) 2))
(initget 1) (setq c (getstring t "\nText for bubble: "))
(command "text" "m" p4 (* 0.094 ds) 0 c) (princ))
(setvar "orthomode" *ORT*)
(setvar "osmode" *OSM*)
(setvar "cmdecho" *CMD*)

Any help is greatly appreciated! TIA

Scott

madcadder
2007-10-17, 01:31 AM
double check your osmode before running.
Try doing a setq for each at the beginning.

T.Willey
2007-10-17, 01:38 AM
Here you go Scott. You should also make your variables local, I will leave that to you, but let us know if you need help there.

(defun c:b ()
(setq
*CMD* (getvar "cmdecho")
*ORT* (getvar "orthomode")
*OSM* (getvar "osmode")
)
(setvar "cmdecho" 0)
(setvar "orthomode" 0)
(setvar "osmode" 512)
(setq ds (getvar "dimscale"))
(initget 1)
(setq p1 (getpoint "\nFrom point: "))
(initget 1)
(setq p2 (getpoint p1 "\nTo point: "))
(if (<= (car p2) (car p1))
(setq b (* -0.375 ds))
(setq b (* 0.375 ds))
)
(setq p3 (list (+ (car p2)(/ b 4)) (cadr p2)))
(setq p4 (list (+ (car p3) (/ b 2)) (cadr p3)))
;(command "dim1" "leader" p1 p2 p3 ^C^C)
(command "_.leader" p1 p2 p3 "" "" "_n")
(command "circle" p4 (/ (abs b) 2))
(initget 1)
(setq c (getstring t "\nText for bubble: "))
(command "text" "m" p4 (* 0.094 ds) 0 c)
(setvar "orthomode" *ORT*)
(setvar "osmode" *OSM*)
(setvar "cmdecho" *CMD*)
(princ)
)

sgiffin
2007-10-17, 03:22 PM
Thanks a lot Tim! Works like a charm. You'll have to forgive me. I haven't messed with lisp files for years. If you wouldn't mind, could you refresh my memory about how to make my variables local.

Kindest regards, Scott

T.Willey
2007-10-17, 05:05 PM
You're welcome Scott. To make variables local you must put them into the parenthesis that follow the command name, after a forward slash and a space. Example (not using your code).

(defun c:Test ()

(setq a "This is a test.")
)

In this code, the variable 'a' is set to a string, and after the code is finished it will still be floating around Acad (in the current drawing) for use in other routines, but if you do

(defun c:Test (/ a)

(setq a "This is a test 2.")
)

'a' will not hold it's value out side of the routine, and it will not inherit the value from the other variable 'a' floating around in Acad.

Hope that makes sense.

CAB2k
2007-10-17, 09:40 PM
You should turn off osmode during the commands else it may snap to a hearby object.
(defun c:b ()
(setq *CMD* (getvar "cmdecho")
*ORT* (getvar "orthomode")
*OSM* (getvar "osmode")
)
(setvar "cmdecho" 0)
(setvar "orthomode" 0)
(setvar "osmode" 512)
(setq ds (getvar "dimscale"))
(initget 1)
(setq p1 (getpoint "\nFrom point: "))
(initget 1)
(setq p2 (getpoint p1 "\nTo point: "))
(if (<= (car p2) (car p1))
(setq b (* -0.375 ds))
(setq b (* 0.375 ds))
)
(setq p3 (list (+ (car p2) (/ b 4)) (cadr p2)))
(setq p4 (list (+ (car p3) (/ b 2)) (cadr p3)))
(command "_.leader" "_non" p1 "_non" p2 "_non" p3 "" "" "_n")
(command "circle" "_non" p4 (/ (abs b) 2))
(initget 1)
(setq c (getstring t "\nText for bubble: "))
(command "text" "m" "_non" p4 (* 0.094 ds) 0 c)
(setvar "orthomode" *ORT*)
(setvar "osmode" *OSM*)
(setvar "cmdecho" *CMD*)
(princ)
)

T.Willey
2007-10-17, 09:44 PM
Good catch Alan.

Do you like seeing how many things you can find wrong in the code I post??


:smile: :wink:

CAB2k
2007-10-17, 10:10 PM
Not at all. Just that I've been burnt so many times with those osnaps in my own code. I know you almost never use the COMMAND so you don't have to worry about it.

T.Willey
2007-10-17, 11:42 PM
Yea, it has been a long time since I used command in a new lisp. My old ones always turned them off, so I never would run into those problems.

sgiffin
2007-10-18, 01:20 PM
Thanks again. Good info from both of you!