Author Topic: Lisp commands  (Read 9713 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
Lisp commands
« Reply #15 on: November 12, 2004, 05:38:28 PM »
WOOHOOO!! IT WORKS...

Here is the Code if anyone is intrested.


Code: [Select]

;Creates a line on a specified layer for Audio/Video Signal Flows
;Layer's are chosen by either typing "A, Audio, V, Video" in either upper or Lowercase
;in the command line when prompted.
;
;Tested in AutoCAD 2004 - Added to Button for ease of use.
;Button code:
;^C^C(LOAD "G:/CHI-CUSTOMCAD/LISP/WIRING");WIRE;
;
;www.theswamp.org
;
;Written by Philip DeCanio, for Shen Milsom & Wilke - 11-12-2004

(defun C:wire ()
(setq P (getstring "(A)udio or (V)ideo: "))
(command "ORTHO" "ON" "SNAP" ".25")
(IF (= P "A")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "V")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(IF (= P "a")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "v")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(IF (= P "audio")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "video")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(IF (= P "AUDIO")(command "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "LINE"))
(IF (= P "VIDEO")(command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "LINE"))
(princ)
)


Thanks for the help everyone.

CarlB

  • Guest
Lisp commands
« Reply #16 on: November 12, 2004, 05:57:54 PM »
Avcad-

Look into the function "getkword" - it would reduce the code required by quite a bit.

Ronjop - I think "getkword" instead of "getstring" would solve your problem as well.

MikePerry

  • Guest
Lisp commands
« Reply #17 on: November 12, 2004, 06:21:55 PM »
Quote from: ronjonp
What am I doing wrong here? I saw the code examples and wanted to combine 3 lisps that I use. It doesn't use the options though.

Hi

Below snippet is from the AutoLISP Reference Help File -

<snip>
initget Function

The getstring function is the only user-input function that does not honor keywords.
</snip>

Therefore below is my humble re-working -

Code: [Select]
(defun c:bb (/ P) ;Used for inserting bubbler laterals
  (setvar 'plinegen 1)
  (initget 1 "Tree Shrub Bub") ;Gets T or S or B
  (setq P (getkword
   "\nEnter an option (T)ree or (S)hrub or (B)ub Lateral: "
 )
  )
  (if (= P "Tree")
    (progn
      (setvar 'plinewid (* (getvar "dimscale") 0.05))
      (command "_.-Layer"   "_Make" "0280-tree-lateral"
      "_L"    "hidden2" ""      "_Color"
      "4"    "" ""
     )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
(command pause)
      )
    )
  )
  (if (= P "Shrub")
    (progn
      (setvar 'plinewid (* (getvar "dimscale") 0.0125))
      (command "_.-Layer"     "_Make"     "0280-shrub-lateral"
      "_Color"      "6"     ""
      ""
     )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
(command pause)
      )
    )
  )
  (if (= P "Bub")
    (progn
      (setvar 'plinewid (* (getvar "dimscale") 0.0))
      (command "_.-Layer"   "_Make" "0280-bub-lateral"
      "_L"    "hidden2" ""      "_Color"
      "5"    "" ""
     )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
(command pause)
      )
    )
  )
  (princ)
)


Have a good one, Mike

ronjonp

  • Needs a day job
  • Posts: 7529
Lisp commands
« Reply #18 on: November 12, 2004, 07:02:36 PM »
Thanks guys. Works like a charm now. :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

AVCAD

  • Guest
Lisp commands
« Reply #19 on: November 15, 2004, 10:11:08 AM »
I tried using the getkword function, but for some reason it I was having trouble with it so I started over and used getstring.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #20 on: November 15, 2004, 10:33:36 AM »
Quote from: AVCAD
I tried using the getkword function, but for some reason it I was having trouble with it so I started over and used getstring.


Try the first code i posted, I changed it to use getkword.
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.

ELOQUINTET

  • Guest
Lisp commands
« Reply #21 on: November 15, 2004, 11:14:23 AM »
i modified mike's but can't figure out why the stainless steel portion isn't working, any help would be great

Code: [Select]
(defun c:LLL (/ P)         ;USED FOR DRAWING LINES ON CERTAIN LAYERS
  (initget 1 "Glass Stainless steel Aluminum")      ;Gets G or S or A
  (setq   P (getkword
       "\nEnter an option (G)lass (S)tainless steel (A)luminum: "
     )
  )
  (if (= P "Glass")
    (progn
      (command "_.-Layer"   "_Make"    "0-GLASS"
          "_L"       "CONTINUOUS"    ""         "_Color"
          "Cyan"       ""       ""
         )
      (command "Line")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (if (= P "Stainless steel")
    (progn
      (command "_.-Layer"   "_Make"    "0-STAINLESS STEEL"
          "_L"       "Continuous"    ""         "_Color"
          "Yellow"       ""       ""
         )
      (command "Line")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (if (= P "Aluminum")
    (progn
      (command "_.-Layer"   "_Make"    "0-ALUMINUM"
          "_L"       "Continuous"    ""         "_Color"
          "Green"       ""       ""
         )
      (command "Line")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #22 on: November 15, 2004, 11:48:16 AM »
Quote
Keyword Specifications

The string argument is interpreted according to the following rules:
Each keyword is separated from the following keyword by one or more spaces. For example, "Width Height Depth" defines three keywords.


No Spaces allowed
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #23 on: November 15, 2004, 11:49:24 AM »
Mike,
That is a good one. Your code is perfectly fine and very readable.
But if you don't mind here is another way to do it.
Because you use INITGET 1 the routine will not continue unless the user enters a
keyword. So with that guarantee you can use a cond stmt to test the keyword and
unlike the multiple if statements it will stop testing as soon as it finds a match.
This is just another approach. The pline code is the same for each condition so it
can be moved to a point after the condition statement and you will not need to
duplicate the code.
If you could not guarantee the keyword you could use a True condition to catch
anything that fell through. Like this
Code: [Select]
(cond
  ((= p "Tree")
    Do Tree stuff)
  ((= p "Shrub")
    Do Shrub stuff)
  (T
    (alert "Nothing to do."))
 )

 
 But you would have to use the pline code conditionally now. Like this:
Code: [Select]
(if (memeber p '("Tree" "Shrub"))
   (progn
     (command "_.PLine")
     (while (> (getvar "CMDACTIVE") 0)
      (command pause)
     )
    )
  )

 
  Here is the code done with cond statement
 
 
Code: [Select]
(defun c:bb (/ p) ;Used for inserting bubbler laterals
  (setvar 'plinegen 1)
  (initget 1 "Tree Shrub Bub") ;Gets T or S or B
  (setq p (getkword
            "\nEnter an option (T)ree or (S)hrub or (B)ub Lateral: "
          )
  )
  (cond
    ((= p "Tree")
     (setvar 'plinewid (* (getvar "dimscale") 0.05))
     (command "_.-Layer" "_Make" "0280-tree-lateral" "_L" "hidden2" "" "_Color" "4" "" "")
    )
    ((= p "Shrub")

     (setvar 'plinewid (* (getvar "dimscale") 0.0125))
     (command "_.-Layer" "_Make" "0280-shrub-lateral" "_Color" "6" "" "")
    )
    ((= p "Bub")
     (setvar 'plinewid (* (getvar "dimscale") 0.0))
     (command "_.-Layer" "_Make" "0280-bub-lateral" "_L" "hidden2" "" "_Color" "5" "" "")
    )
  )
  (command "_.PLine")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )

  (princ)
)
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.

ELOQUINTET

  • Guest
Lisp commands
« Reply #24 on: November 15, 2004, 12:12:08 PM »
cab i suspected that was it so i took the spaces out so it read as "Stainlesssteel" but still couldn't get it to work. what spaces are you referring to?

ronjonp

  • Needs a day job
  • Posts: 7529
Lisp commands
« Reply #25 on: November 15, 2004, 12:15:12 PM »
I also added:

Code: [Select]
(if (tblsearch "layer" "0280-tree-lateral")
(command "-layer" "thaw" "0280-tree-lateral" "on" "0280-tree-lateral" "")
)


To thaw and turn on the layer. If the layer existed and was frozen the lisp would break since frozen layers cannot be made current.

Dan,

When I run your lisp I get a syntax error for some reason.....can't figure it out.


Code: [Select]
(defun c:drip (/ P)         ;Used for inserting bubbler laterals

  (setvar 'plinegen 1)
  (initget 1 "Tree Shrub Bub Header Cv")      ;Gets T or S or B or H or C
  (setq   P (getkword
       "\nEnter an option (T)ree, (S)hrub, (B)ub, (H)eader, or (C)v Lateral: "
     )
  )
  (if (= P "Tree")
    (progn

(if (tblsearch "layer" "0280-tree-lateral")
(command "-layer" "thaw" "0280-tree-lateral" "on" "0280-tree-lateral" "")
)

      (setvar 'plinewid (* (getvar "dimscale") 0.05))
      (command "_.-Layer"   "_Make"    "0280-tree-lateral"
          "_L"       "hidden2"    ""         "_Color"
          "4"       ""       ""
         )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (if (= P "Shrub")
    (progn
(if (tblsearch "layer" "0280-shrub-lateral")
(command "-layer" "thaw" "0280-shrub-lateral" "on" "0280-shrub-lateral" "")
)
      (setvar 'plinewid (* (getvar "dimscale") 0.0125))
      (command "_.-Layer"     "_Make"        "0280-shrub-lateral"
          "_Color"         "6"        ""
          ""
         )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (if (= P "Bub")
    (progn
(if (tblsearch "layer" "0280-bub-lateral")
(command "-layer" "thaw" "0280-bub-lateral" "on" "0280-bub-lateral" "")
)
      (setvar 'plinewid (* (getvar "dimscale") 0.0))
      (command "_.-Layer"   "_Make"    "0280-bub-lateral"
          "_L"       "hidden2"    ""         "_Color"
          "5"       ""       ""
         )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (if (= P "Header")
    (progn
(if (tblsearch "layer" "0280-netafim_header")
(command "-layer" "thaw" "0280-netafim_header" "on" "0280-netafim_header" "")
)
      (setvar 'plinewid (* (getvar "dimscale") 0.05))
      (command "_.-Layer"   "_Make"    "0280-netafim_header"
          "_L"       "continuous"    ""         "_Color"
          "white"       ""       ""
         )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (if (= P "Cv")
    (progn
(if (tblsearch "layer" "0280-netafim_cv")
(command "-layer" "thaw" "0280-netafim_cv" "on" "0280-netafim_cv" "")
)
      (setvar 'plinewid (* (getvar "dimscale") 0.025))
      (command "_.-Layer"   "_Make"    "0280-netafim_cv"
          "_L"       "hidden2"    ""         "_Color"
          "yellow"       ""       ""
         )
      (command "_.PLine")
      (while (> (getvar "CMDACTIVE") 0)
   (command pause)
      )
    )
  )
  (princ)
)


Thanks for the help.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #26 on: November 15, 2004, 12:25:40 PM »
Quote from: eloquintet
cab i suspected that was it so i took the spaces out so it read as "Stainlesssteel" but still couldn't get it to work. what spaces are you referring to?

The one in the initget and the test
Code: [Select]
(defun c:lll (/ p) ;USED FOR DRAWING LINES ON CERTAIN LAYERS
  (initget 1 "Glass Stainlesssteel Aluminum") ;Gets G or S or A
  (setq p (getkword
            "\nEnter an option (G)lass (S)tainless steel (A)luminum: "
          )
  )
  (cond
    ((= p "Glass")
     (progn
       (command "_.-Layer" "_Make" "0-GLASS" "_L" "CONTINUOUS" "" "_Color" "Cyan" "" "")
     )
    )
    ((= p "Stainlesssteel")
     (progn
       (command "_.-Layer" "_Make" "0-STAINLESS STEEL" "_L" "Continuous" "" "_Color" "Yellow" "" "")
     )
    )
    ((= p "Aluminum")
     (progn
       (command "_.-Layer" "_Make" "0-ALUMINUM" "_L" "Continuous" "" "_Color" "Green" "" "")
     )
    )
  )
  (command "Line")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  (princ)
)
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.

ELOQUINTET

  • Guest
Lisp commands
« Reply #27 on: November 15, 2004, 12:26:56 PM »
hmmm no message here maybe i'll modify this one and get back to ya

ELOQUINTET

  • Guest
Lisp commands
« Reply #28 on: November 15, 2004, 12:29:03 PM »
cool that one works cab tanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #29 on: November 15, 2004, 12:48:22 PM »
Ron
Here is another method.
Code: [Select]
(defun c:bb (/ p dimx lyr) ;Used for inserting bubbler laterals
  (setvar 'plinegen 1)
  (initget 1 "Tree Shrub Bub") ;Gets T or S or B
  (setq p (getkword
            "\nEnter an option (T)ree or (S)hrub or (B)ub Lateral: "
          )
  )
  (cond
    ((= p "Tree")
     (setq dimx 0.05)
     (setq lyr (list "0280-tree-lateral" "_L" "hidden2" "" "_Color" "4" "" ""))
    )
    ((= p "Shrub")
     (setq dimx  0.0125)
     (setq lyr (list "0280-shrub-lateral" "_Color" "6" "" ""))
    )
    ((= p "Bub")
     (setq dimx  1.0)
     (setq lyr (list "0280-bub-lateral" "_L" "hidden2" "" "_Color" "5" "" ""))
    )
  )

  (if (tblsearch "layer" (car lyr))
    (command "-layer" "T" (car lyr) "ON" (car lyr) "")
    (command "_.-layer" "_make" (foreach x lyr (command x)))
  )
  (setvar 'plinewid (* (getvar "dimscale") dimx))
 
  (command "_.PLine")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )

  (princ)
)
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.