Author Topic: Xlines revisited  (Read 2298 times)

0 Members and 1 Guest are viewing this topic.

krampaul82

  • Guest
Xlines revisited
« on: April 06, 2012, 08:49:04 AM »

The following xline code does not change to the layer sketch before the command is executed were as it does on the other xline lisps with input from Lee-Mac Programming
(see post xlines dated march 27) Any help appreciated



;  THIS FUNCTION WILL WILL PLACE A USER SPECIFIED ANGLED XLINE ON THE SKETCH LAYER (NO-PLOT) AT THE USERS PICK POINT.
;  IF IT DOES NO EXIST IT WILL MAKE THE LAYER AND CHANGE TO IT BEFORE IT EXECUTES THE COMMAND
;  IT WILL THEN CHANGE BACK TO THE LAYER YOU WERE PREVIOUSLY ON AND THE END THE COMMAND. (THANKS TO LEE-MAC PROGRAMMING FOR ERROR HANDLING AND LAYER MANIPULATION)


Code: [Select]
(defun c:clang (/ *error* sysvar values )

;; Error Handler to reset System Variables if things go wrong
    (defun *error* ( msg )
        (mapcar 'setvar sysvar values)
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
 
;; Store current System Variables
    (setq sysvar '(CMDECHO CLAYER OSMODE)
          values  (mapcar 'getvar sysvar)
    )
 
;; Set System Variables
    (setvar 'CMDECHO 0)
    (setvar 'OSMODE  0)
 
;; If "Sketch" layer exists...
    (if (tblsearch "LAYER" "Sketch")
        ;; Unlock it, Thaw it, Turn it On, and set it current
        (command "_.-layer" "_U" "Sketch" "_T" "Sketch" "_ON" "Sketch" "_S" "Sketch" "")
        ;; Otherwise create it (also sets it current)
        (command "_.-layer" "_M" "Sketch" "_C" "_Cyan" "Sketch" "")
    )

;; Tell user what's about to happen...
   (prompt "Once you enter a value This puts a An angled xline at your pick point...") (terpri)

 
;; Create the Angled XLine: 
   (command "xline" "a" "PAUSE" )[color=red] ;I am thinking this line might be causing the problem? [/color]
 
   ;; Reset System Variables
    (mapcar 'setvar sysvar values)
    (princ)
 )

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Xlines revisited
« Reply #1 on: April 06, 2012, 09:33:06 AM »
Very interesting.  I see what you mean.  I removed the the table search function an inserted one of my brute force code for creating code and it still did not work.  I have to enter a meeting, so I can not take it any further until later this afternoon.  Hopelfully someone will come along see the the quirky item that is causing the hiccup.

Cheers.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Xlines revisited
« Reply #2 on: April 06, 2012, 09:51:01 AM »
Change:

Code: [Select]
(command "xline" "a" "PAUSE" )
to:

Code: [Select]
(command "_.xline" "_a")
(while (= 1 (logand 1 (getvar 'CMDACTIVE)))
    (command pause)
)

'pause' is a symbol (not a string), with a value of "\" (meaning pause for user input).

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Xlines revisited
« Reply #3 on: April 06, 2012, 09:55:42 AM »
Looking at the code more thoroughly, you might want to change it to this:

Code: [Select]
(defun c:clang (/ *error* sysvar values )

    ;; Error Handler to reset System Variables if things go wrong
    (defun *error* ( msg )
        (mapcar 'setvar sysvar values)
        (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
 
    ;; Store current System Variables
    (setq sysvar '(CMDECHO CLAYER)
          values  (mapcar 'getvar sysvar)
    )
 
    ;; Set System Variables
    (setvar 'CMDECHO 0)
 
    ;; If "Sketch" layer exists...
    (if (tblsearch "LAYER" "Sketch")
        ;; Unlock it, Thaw it, Turn it On, and set it current
        (command "_.-layer" "_U" "Sketch" "_T" "Sketch" "_ON" "Sketch" "_S" "Sketch" "")
        ;; Otherwise create it (also sets it current)
        (command "_.-layer" "_M" "Sketch" "_C" "_Cyan" "Sketch" "")
    )

    ;; Tell user what's about to happen...
    (prompt "\nOnce you enter a value this puts a an angled XLine at your pick point...")
    (setvar 'CMDECHO 1)
   
    ;; Create the Angled XLine:
    (command "_.xline" "_a")
    (while (= 1 (logand 1 (getvar 'CMDACTIVE)))
        (command pause)
    )
 
    ;; Reset System Variables
    (mapcar 'setvar sysvar values)
    (princ)
)

Since the XLines are now being placed by the user, there is no need to change the OSMODE setting.

krampaul82

  • Guest
Re: Xlines revisited
« Reply #4 on: April 06, 2012, 10:08:41 AM »
 :kewl:

Thank You for the replies
I used your corrected code (Lee-Mac Programming) and it works as intended.
Again, Thank You!

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Xlines revisited
« Reply #5 on: April 06, 2012, 10:31:58 AM »
You're welcome, I hope you can learn from the code  :-)

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Xlines revisited
« Reply #6 on: April 06, 2012, 01:27:58 PM »
You're welcome, I hope you can learn from the code  :-)

I know I did.  Thanks.  and now to make my code look a little lest brutish.  :lol:
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Xlines revisited
« Reply #7 on: April 07, 2012, 07:11:15 AM »
Good stuff  8-)