Author Topic: help with lisp  (Read 2778 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
help with lisp
« on: November 01, 2004, 09:39:06 AM »
i have tried to modify some of an existing lisp i have so that it will get the current layer then switch the layer to 0-construction line then revert back to the previous layer. what have i done wrong here?


Code: [Select]
;;; DRAWS A LINE THEN ASKS WHICH SIDE TO OFFSET AND DISTANCE, REFERENCE LINE

(defun C:RL (/ pt1 pt2 usercmd str en1 en2       )
;;; -------  Some Housekeeping   ------------------
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (getvar "clayer"))
  (setvar "0-construction line"))  
  (setq useros (getvar "osmode")
   str "")
  (setvar "osmode" 175)
  (prompt "/nPick points, Enter when done.")
  ;;; Draw the pline
  (setq pt1 (getpoint))
  (command "LINE" pt1 (Setq pt2 (getpoint pt1))) ;_ COMMAND
  (while (setq pt2 (getpoint pt2 "\nNext point: "))(command pt2)) ;_ WHILE
  (command "")
  (princ)
  (setq en1 (entlast))
  (initget 1)
  (setq pto (getpoint "\nSide to offset:"))
  (setq dist (getreal "\nEnter offset distance:"))
  (command "_.offset" dist en1 pto "")
  ;(setq en2 (entlast))
  (entdel en1) ; remove the user drawn line


;;;==========  Exit Sequence  ============
  (setvar "osmode" useros)
  (setvar "CMDECHO" usercmd)
  (setvar "clayer"))  
;;; Exit quietly
  (princ)

) ;_end of defun

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: help with lisp
« Reply #1 on: November 01, 2004, 10:39:39 AM »
Quote from: eloquintet

  (setvar "0-construction line"))

Never seen that before...

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
help with lisp
« Reply #2 on: November 01, 2004, 10:40:22 AM »
Well for starters, you have not grabbed the return value of GetVar and you are missing the first argument of SetVar ...

Code: [Select]

(defun C:RL (/ pt1 pt2 usercmd str en1 en2       )
;;; -------  Some Housekeeping   ------------------
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq OLAY (getvar "clayer"))
  (setvar "CLAYER" "0-construction line"))    
  (setq useros (getvar "osmode") str "")
  (setvar "osmode" 175)
  (prompt "/nPick points, Enter when done.")
  ;;; Draw the pline
  (setq pt1 (getpoint))
  (command "LINE" pt1 (Setq pt2 (getpoint pt1))) ;_ COMMAND
  (while (setq pt2 (getpoint pt2 "\nNext point: "))(command pt2)) ;_ WHILE
  (command "")
  (princ)
  (setq en1 (entlast))
  (initget 1)
  (setq pto (getpoint "\nSide to offset:"))
  (setq dist (getreal "\nEnter offset distance:"))
  (command "_.offset" dist en1 pto "")
  ;(setq en2 (entlast))
  (entdel en1) ; remove the user drawn line


;;;==========  Exit Sequence  ============
  (setvar "osmode" useros)
  (setvar "CMDECHO" usercmd)
  (setvar "clayer" OLAY)  
;;; Exit quietly
  (princ)

) ;_end of defun
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

David Bethel

  • Swamp Rat
  • Posts: 656
help with lisp
« Reply #3 on: November 01, 2004, 10:53:30 AM »
Here's a little ditty that will ensure that you get to the layer you want.

Code: [Select]
;++++++++++++ Make Layer Current +++++++++++++++++++++++++++++++++
(defun SetLayer (name / ldef flag)
  (command "_.LAYER")
  (if (not (tblsearch "LAYER" name))
      (command "_Make" name)
      (progn
        (setq ldef (tblsearch "LAYER" name)
              flag (cdr (assoc 70 ldef)))
        (and (= (logand flag  1)  1)
             (command "_Thaw" name))
        (and (minusp (cdr (assoc 62 ldef)))
             (command "_On" name))
        (and (= (logand flag  4)  4)
             (command "_Unlock" name))
        (and (= (logand flag 16) 16)
             (princ "\nCannot Set To XRef Dependent Layer")
             (quit))
        (command "_Set" name)))
  (command "")
  name)



You might want to add a (snvalid) call, but it will take care of most everything else.  -David
R12 Dos - A2K

ELOQUINTET

  • Guest
help with lisp
« Reply #4 on: November 01, 2004, 10:58:03 AM »
i was trying to figure it out for myself and here's what i came up with but yours is probably better. mine works ok except the i would like to make the layer 0-construction line be color 30 orange but can't seem to get it to change anyway here's mine and i'll try yours keith:

Code: [Select]
;;; DRAWS A LINE THEN ASKS WHICH SIDE TO OFFSET AND DISTANCE, REFERENCE LINE

(defun C:RL (/ pt1 pt2 usercmd str en1 en2       )
;;; -------  Some Housekeeping   ------------------
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq clay (getvar 'clayer))
  (command "_.layer" "m" "0-CONSTRUCTION LINE" "")
  (setq useros (getvar "osmode")
   str "")
  (setvar "osmode" 175)
  (prompt "/nPick points, Enter when done.")
  ;;; Draw the pline
  (setq pt1 (getpoint))
  (command "LINE" pt1 (Setq pt2 (getpoint pt1))) ;_ COMMAND
  (while (setq pt2 (getpoint pt2 "\nNext point: "))(command pt2)) ;_ WHILE
  (command "")
  (princ)
  (setq en1 (entlast))
  (initget 1)
  (setq pto (getpoint "\nSide to offset:"))
  (setq dist (getreal "\nEnter offset distance:"))
  (command "_.offset" dist en1 pto "")
  ;(setq en2 (entlast))
  (entdel en1) ; remove the user drawn line


;;;==========  Exit Sequence  ============
  (setvar "osmode" useros)
  (setvar "CMDECHO" usercmd)
  (setvar "clayer" clay)
;;; Exit quietly
  (princ)

) ;_end of defun

ELOQUINTET

  • Guest
help with lisp
« Reply #5 on: November 01, 2004, 11:02:18 AM »
i was just looking at yours keith what if the layer does not exist i would like it created how would i do that?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
help with lisp
« Reply #6 on: November 01, 2004, 11:15:50 AM »
Good try dan.
Here are some ideas for you.
Code: [Select]
;;; DRAWS A LINE THEN ASKS WHICH SIDE TO OFFSET AND DISTANCE, REFERENCE LINE

(defun c:rl (/ usercmd en1 clay dist)
  ;; -------  Some Housekeeping   ------------------
  (setq usercmd (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq clay (getvar 'clayer))
  (command "_.layer" "m" "0-CONSTRUCTION LINE" "C" 30 "" "")
  (setq useros (getvar "osmode"))
  (setvar "osmode" 175)
  (prompt "/nPick points, Enter when done.")
  ;; Draw the pline
  (command "PLINE") ;_ COMMAND
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  (setq en1 (entlast))
  (initget 1)
  (setq pto (getpoint "\nSide to offset:"))
  (setq dist (getreal "\nEnter offset distance:"))
  (command "_.offset" dist en1 pto "")
  (entdel en1) ; remove the user drawn line

  ;;==========  Exit Sequence  ============
  (setvar "CMDECHO" usercmd)
  (setvar "clayer" clay)
  ;; Exit quietly
  (princ)

) ;_end of defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.