PDA

View Full Version : ~Gap line Lisp, plz I need help


james.hodson
2009-07-23, 05:47 PM
So I am trying to make a Lisp that will when activated, allow you to pick one line, and then a second line crossing the first line, then it will place a gap in the first line around the intersection of the lines. That is what I currently have working, but now I have a couple other things I need to fix with this lisp.

Problem 1) I need this to continue running until the user hits the 'ESC' key to halt the process. Right now it only does one intersection, on drawings sometimes I have 20 intersections.

Problem 2) I think it is turning off OSNAPS, and unchecking them all. Is there a way I could buffer what the user has for osnaps, and then re-instate that when done gapping.

Thank you for your help, Below is the code:

(defun C:gl (/ *ERROR* ar OS OL LINE1 LN P1 P2 AN LINE2 P3 P4 IN BPT1 PBT2)
(setq *error* myer)
(SETVAR "CMDECHO" 0)
(setq OS (getvar "osmode"))
(setvar "osmode" 0)
(setq ar 0.08)
(setq OL (getvar "clayer"))
(while (not (setq ENT1 (car (entsel "\nSelect crossing line to break: "))))
(princ "\nNull Selection please try again: ")
)
(setq LINE1 (entget ENT1))
(setq LN (cdr (assoc 8 LINE1)))
(setq P1 (trans (cdr (assoc 10 LINE1)) 0 1 ))
(setq P2 (trans (cdr (assoc 11 LINE1)) 0 1 ))
(setq AN (angle P1 P2))
(while (not (setq ENT2 (car (entsel "\nSelect line to cross over: "))))
(princ "\nNull Selection please try again: ")
)
(setq LINE2 (entget ENT2))
(setq P3 (trans (cdr (assoc 10 LINE2))0 1))
(setq P4 (trans (cdr (assoc 11 LINE2))0 1))
(setq IN (inters P1 P2 P3 P4))
(setq BPT1 (polar IN AN (* AR 1)))
(setq BPT2 (polar IN (+ AN pi) (* AR 1)))
(command "break" ENT1 BPT1 BPT2)
(setvar "osmode" OS)
(setq *error* nil)
(princ)
)

(defun myer (msg)
(setvar "osmode" OS)
(setq att "***Resetting system variable was done***")
(princ att)
)

james.hodson
2009-07-23, 05:51 PM
the 8) in the script is actually this with out the spaces in the numbers to the close parenthesis " (setq ar 0 . 0 8 )"

Thanks again,
James

ccowgill
2009-07-23, 06:16 PM
So I am trying to make a Lisp that will when activated, allow you to pick one line, and then a second line crossing the first line, then it will place a gap in the first line around the intersection of the lines. That is what I currently have working, but now I have a couple other things I need to fix with this lisp.

Problem 1) I need this to continue running until the user hits the 'ESC' key to halt the process. Right now it only does one intersection, on drawings sometimes I have 20 intersections.

Problem 2) I think it is turning off OSNAPS, and unchecking them all. Is there a way I could buffer what the user has for osnaps, and then re-instate that when done gapping.

Thank you for your help, Below is the code:

(defun C:gl (/ *ERROR* ar OS OL LINE1 LN P1 P2 AN LINE2 P3 P4 IN BPT1 PBT2)
(setq *error* myer)
(SETVAR "CMDECHO" 0)
(setq OS (getvar "osmode"))
(setvar "osmode" 0)
(setq ar 0.08)
(setq OL (getvar "clayer"))
(while (not (setq ENT1 (car (entsel "\nSelect crossing line to break: "))))
(princ "\nNull Selection please try again: ")
)
(setq LINE1 (entget ENT1))
(setq LN (cdr (assoc 8 LINE1)))
(setq P1 (trans (cdr (assoc 10 LINE1)) 0 1 ))
(setq P2 (trans (cdr (assoc 11 LINE1)) 0 1 ))
(setq AN (angle P1 P2))
(while (not (setq ENT2 (car (entsel "\nSelect line to cross over: "))))
(princ "\nNull Selection please try again: ")
)
(setq LINE2 (entget ENT2))
(setq P3 (trans (cdr (assoc 10 LINE2))0 1))
(setq P4 (trans (cdr (assoc 11 LINE2))0 1))
(setq IN (inters P1 P2 P3 P4))
(setq BPT1 (polar IN AN (* AR 1)))
(setq BPT2 (polar IN (+ AN pi) (* AR 1)))
(command "break" ENT1 BPT1 BPT2)
(*error* "")
(princ)
(C:GL)
)

(defun myer (msg)
(setvar "osmode" OS)
(setq att "***Resetting system variable was done***")
(princ att)
)
you could try the changes in red, I dont know what *ERROR* is, but if it is anything like what I have used in the past, by passing "" to it, it should restore any system vars that have been changed.
This is the *Error* function I use in some of my routines:

;; error function & Routine Exit
(defun *error* (msg)
(if
(not
(member
msg
'("console break"
"Function cancelled"
"quit / exit abort"
""
)
)
)
(princ (strcat "\nError: " msg))
) ; endif
(restore_sys_vars) ; reset vars
)

;; Function to save system variables in global variable
;; call to function
;; (save_sys_vars '("CMDECHO" "CLAYER" "OSMODE" "CECOLOR"))
(defun save_sys_vars (lst)
(setq *sysvarlist* '())
(repeat (length lst)
(setq *sysvarlist*
(append *sysvarlist*
(list (list (car lst) (getvar (car lst))))
)
)
(setq lst (cdr lst))
)
)

;; Function to reset system variables
(defun restore_sys_vars ()
(repeat (length *sysvarlist*)
(setvar (caar *sysvarlist*) (cadar *sysvarlist*))
(setq *sysvarlist* (cdr *sysvarlist*))
)
)

(save_sys_vars
'("CMDECHO" "OSMODE" "CECOLOR" "CLAYER" "PICKBOX" "TEXTSTYLE" "OSNAPZ")
)
;GET SYSTEM VAR & error handling

RobertB
2009-07-23, 07:52 PM
The function myer needs to handle error messages in addition to just resetting the environment. If you check the argument msg for nil before attempting to use it in a string, you can make the error handler also act as a normal exit function, which is your intention.

(defun myer (msg)
(cond
((not msg)) ; normal exit, do not report error
((princ (strcat "\nError: " msg))))
(setvar "osmode" OS)
(setq att "***Resetting system variable was done***")
(princ att)
(princ))

(setvar "OSMode" 0) is the wrong way to handle running OSnaps. Rather, the statement should just turn off the running OSnaps, not clearing them entirely.

(setvar 'OSMode (logior (getvar 'OSMode) 16384))

Opie
2009-07-23, 08:08 PM
the 8) in the script is actually this with out the spaces in the numbers to the close parenthesis " (setq ar 0 . 0 8 )"

Thanks again,
James
Placing tags around your code will disable smilies.

ameador
2009-08-07, 06:11 PM
I believe I am attempting to accomplish the exact same thing, only in a much more simplified method...aka, I was not try to do user prompts and error code info. I have a set gap that I want to use.

http://forums.augi.com/showthread.php?p=999058#post999058

*NOTE*: I am in ABS07.

Here's the code I have, but I can't get the user input of the intersection to work.


(command "_break")
;;(setq el (entlast))
;;(command "int")
(setq pt (command "int"))
;;(command "pt")
(command "f")
(command "@-3,0")
(command "@6,0")

ameador
2009-08-07, 06:31 PM
Ok, I tried the code that you all have posted in here, in the 3 different variations.
I keep getting "myer" showing up at the command line and it doesn't know what to do with it.

I'm guess this may be b/c I am using ABS07 and maybe that's a command that is in a higher version?? Maybe it doesn't like the subroutine?

I commented that portion out with ;; 's and now I get C:GL showing up at the command line and it doesn't do anything else.

Any ideas?

ameador
2009-08-10, 04:55 PM
Check this out! I think we've got a solution...

One of my guys figured out this way to do this...

Just create a toolbar button or drop down, or whatever using this command in it:

*^C^C_circle _int \3" _trim last \ erase previous (you'll have to manually add the <enter> at the end of the command, since a regular copy and paste to drop it in won't catch that portion)

It's basically drawing a circle and using that to trim and then erasing the circle when the command is completed.