Author Topic: Lisp commands  (Read 9714 times)

0 Members and 1 Guest are viewing this topic.

AVCAD

  • Guest
Lisp commands
« on: November 12, 2004, 01:58:54 PM »
I am working on a simple lisp routine to draw a line. NOthing special. I just want it to ask if the line is for Audio or Video.

Depending on the Input A or V it would draw a line on a differant layer.

Here is my Code so far. TO me it looks like it should work but after I put the Input it the comman just stops..Anyhelp would be great.

Code: [Select]

(defun C:wire ()
(setq P (getSTRING "(A)udio or (V)ideo: ")))
    (IF P (= A (command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" "")))
    (IF P (= V (command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" "")))

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Lisp commands
« Reply #1 on: November 12, 2004, 02:18:03 PM »
Try this
Code: [Select]

(defun C:wire ()
(setq P (getSTRING "(A)udio or (V)ideo: "))
(IF (= P "A")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" ""))
(IF (= P "V")(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "" "" "LINE" ""))
)
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

AVCAD

  • Guest
Lisp commands
« Reply #2 on: November 12, 2004, 02:21:42 PM »
this just gives me a NIL

it still doesnt finish the command

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Lisp commands
« Reply #3 on: November 12, 2004, 02:25:29 PM »
which is what is should ... but you will have the settings you specify, but keep in mind it is only checking for a capital letter.
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

PDJ

  • Guest
Lisp commands
« Reply #4 on: November 12, 2004, 02:38:36 PM »
Couldn't you make specific commands for each type of line you're using?? say something like this:

Code: [Select]

(defun C:AL ()
(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "A-WIRING" "C" "RED" "" "" "" "LINE" "")
)


and then:

Code: [Select]

(defun C:VL ()
(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "RED" "" "" "" "LINE" "")
)



This way, you type either AL or VL and you're on the correct layer and everything.  Then, we can step a little farther and do something along these lines:

Code: [Select]

(defun C:VL ()
        (setq cl  (getvar "clayer")        ;current layer
            cc  (getvar "cecolor")       ;current color
        )
(command "ORTHO" "ON" "" "SNAP" ".25" "-LAYER" "M" "V-WIRING" "C" "RED" "" "" "" "LINE" "")
(if (/= cl)(command "LAYER" "S" cl ""))
           (if (/= cc)(command "COLOR" cc))
(princ)
)


where in this one will remember the layer you were on before you started the VL command and switch back to it when you complete the command.  The same thing can be done for the ortho and snap settings if you want.

This is the neat thing about Lisp.. You can ask 10 different programmers and they'll come up with 12 different ways (We ALL know Keith and CAD will both submit at least 2 different ways :D )

Hope this gives you inspiration.

AVCAD

  • Guest
Lisp commands
« Reply #5 on: November 12, 2004, 02:39:24 PM »
OK..COOL. I guess I was on the right track.

I got it to work with either lowercase and upper.

Code: [Select]

Command:
WIRE (A)udio or (V)ideo: A
Unknown command "WIRE".  Press F1 for help.
Unknown command "WIRE".  Press F1 for help.
nil
Specify first point:
Specify next point or [Undo]:
Specify next point or [Undo]:


How do i get rid of the
Code: [Select]
Unknown command "WIRE".  Press F1 for help.
Unknown command "WIRE".  Press F1 for help.
nil
on the command line when this is ran??

Here is teh code I am using again.

Code: [Select]

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


Thanks for the help.

AVCAD

  • Guest
Lisp commands
« Reply #6 on: November 12, 2004, 02:44:20 PM »
In response to PDL's Post..

I thought about having a seperate command but...this iwll be used my multiple people and I would rather have one command that asks what line they want. This way there is less of a chance for them to screw up and use the wrong line.

But it is an Idea with the saving the previous layer and such..I will look in to incorporating it. Although I am not taht great at wrinting my own lisp files I am very much a Novice at it.

I usually read over and over and over again others lisps and try to figure oiut what the hell is going on in it and then I try to incorporate it. I figure If I can get it to work I must understand it.

Thanks for Help!

PDJ

  • Guest
Lisp commands
« Reply #7 on: November 12, 2004, 03:03:54 PM »
All you really need to do is a little cut and pasting.. The two lines after the defun line are the ones that remember the settings, the two at the end are the ones that restore the settings.  The Osnap and the snap setting you had are similar but different.. (Ahh, a Yogi Berraism..)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Lisp commands
« Reply #8 on: November 12, 2004, 03:21:47 PM »
that is because of an extra blank entry in the command sequence. Likely behind the ortho command
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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #9 on: November 12, 2004, 03:35:24 PM »
How about something like this?
Code: [Select]
(defun C:wire ()
  (initget "Audio Video"); gets a or v
  (setq P (getkword "(A)udio or (V)ideo: <A>"))
  ;; returns "Audio" or "Video" or nil
  ;; default to Audio
  (command "ORTHO" "ON" "" "SNAP" ".25")
  (if (= p "Video")
    (command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "")
    (command "-LAYER" "M" "A-WIRING" "C" "RED" "" "")
  )
  (command "LINE" )
)
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 #10 on: November 12, 2004, 03:38:47 PM »
You could also do this:
Code: [Select]
(defun wire (typ)
  (command "ORTHO" "ON" "" "SNAP" ".25")
  (if (= typ "Video")
    (command "-LAYER" "M" "V-WIRING" "C" "GREEN" "" "")
    (command "-LAYER" "M" "A-WIRING" "C" "RED" "" "")
  )
  (command "LINE" )
)

(defun C:wireA ()
  (wire "Audio")
)
(defun C:wireV ()
  (wire "Video")
)
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.

ronjonp

  • Needs a day job
  • Posts: 7529
Lisp commands
« Reply #11 on: November 12, 2004, 04:22:10 PM »
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.





Code: [Select]
(defun c:bb () ;used for inserting bubbler laterals
  (setvar 'plinegen 1)
  (initget "Tree Shrub Bub") ; gets a or v
  (setq P (getSTRING "(T)ree or (S)hrub or (B)ub Lateral: <T>"))

  (if (= p "Tree")
 
     (setvar 'plinewid (* (getvar "dimscale") 0.05))
      (command ".-layer"    "make" "0280-tree-lateral"
      "l"    "hidden2" ""      "color"
      "4"    "" ""      "pline"
     )
    )

    (if (= p "Shrub")
     
       (setvar 'plinewid (* (getvar "dimscale") 0.0125))
(command ".-layer"     "make"     "0280-shrub-lateral"
"color"       "6"     ""
""       "pline"
)
      )
(if (= p "Bub")

  (setvar 'plinewid (* (getvar "dimscale") 0.0))
   (command ".-layer" "make"     "0280-bub-lateral"
    "l" "hidden2"   "" "color"
    "5" ""     "" "pline"
   )
 )
)
     
   



Thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Lisp commands
« Reply #12 on: November 12, 2004, 04:29:38 PM »
i was playing around with these lisps trying to apply them to my discipline. i was thinking i could also make a button something like this but is there anyway to pause for user input? here' my attempts:

Button:

(setq var (getvar "clayer"));(command "-layer" "n" "0-GLASS" "c" "CYAN" "0-GLASS" ) ;setvar clayer "0-GLASS";orthomode;1;snap;.25;line;\;_LayerP



Code: [Select]
(defun recc (typ)
  (command "ORTHO""ON" "" "SNAP" ".25")
  (if (= typ "Glass")
    (command "-LAYER" "M" "0-GLASS" "C" "Cyan" "" "" "" )
    (command "-LAYER" "M" "0-STAINLESS STEEL" "C" "Yellow" "" "" "")
  )
  (command "Rectangle" )
)

(defun C:SS ()
  (recc "Stainless Steel")
)
(defun C:G ()
  (recc "Glass")
)


Code: [Select]
(defun C:LL ()
  (initget "Glass Stainless Steel"); gets G or S
  (setq P (getSTRING "(G)lass or (S)tainless Steel: <G>"))
  ;; returns "Glass" or "Stainless Steel" or nil
  ;; default to Glass
  (command "ORTHO" "ON" "" "SNAP" ".25")
  (if (= p "Stainless Steel")
    (command "-LAYER" "M" "0-GLASS" "C" "CYAN" "" "" "" )
    (command "-LAYER" "M" "0-STAINLESS STEEL" "C" "YELLOW" "" "" "")
  )
  (command "LINE" )
)

ELOQUINTET

  • Guest
Lisp commands
« Reply #13 on: November 12, 2004, 04:34:17 PM »
by the way here's the behavior or misbehavior i get: it is changing to stainless steel layer no matter what. also i'm getting the unknown command. pretty cool toy though interesting

Command: ll
(G)lass or (S)tainless Steel: <G>
ORTHO Enter mode [ON/OFF] <ON>: ON
Command: LL Unknown command "LL".  Press F1 for help.

Command: SNAP
Specify snap spacing or [ON/OFF/Aspect/Rotate/Style/Type] <0'-0 1/4">: .25
Command: -LAYER
Current layer:  "0-GLASS"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
M
Enter name for new layer (becomes the current layer) <0-GLASS>: 0-STAINLESS
STEEL Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
C
Enter color name or number (1-255): YELLOW
Enter name list of layer(s) for color 2 (yellow) <0-STAINLESS STEEL>: Enter an
option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
Command: LL Unknown command "LL".  Press F1 for help.

Command: LINE Specify first point: nil
Specify first point:

CADaver

  • Guest
Lisp commands
« Reply #14 on: November 12, 2004, 04:46:02 PM »
Quote from: eloquintet
Code: [Select]
(defun recc (typ)
  (command "ORTHO""ON" "" "SNAP" ".25")
  (if (= typ "Glass")
    (command "-LAYER" "M" "0-GLASS" "C" "Cyan" "" "" "" )
    (command "-LAYER" "M" "0-STAINLESS STEEL" "C" "Yellow" "" "" "")
  )
  (command "Rectangle" )
)

(defun C:SS ()
  (recc "Stainless Steel")
)
(defun C:G ()
  (recc "Glass")
)


Code: [Select]
(defun C:LL ()
  (initget "Glass Stainless Steel"); gets G or S
  (setq P (getSTRING "(G)lass or (S)tainless Steel: <G>"))
  ;; returns "Glass" or "Stainless Steel" or nil
  ;; default to Glass
  (command "ORTHO" "ON" "" "SNAP" ".25")
  (if (= p "Stainless Steel")
    (command "-LAYER" "M" "0-GLASS" "C" "CYAN" "" "" "" )
    (command "-LAYER" "M" "0-STAINLESS STEEL" "C" "YELLOW" "" "" "")
  )
  (command "LINE" )
)


Too many "" following the layer command.

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.

ELOQUINTET

  • Guest
Lisp commands
« Reply #30 on: November 15, 2004, 01:03:09 PM »
cab i was trying to modify this so i could then specify which command to run, line pline or rectangle. i'm getting malformed list so am i even close to formatting this right or no? here's what i got:

Code: [Select]
(defun c:lll (/ p) ;USED FOR DRAWING LINE ON SPECIFIED LAYER
  (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" "" "")
     )
    )
  )
    (initget 1 "Line Pline Rectangle") ;Gets L or P or R
  (setq p (getkword
            "\nEnter an option (L)ine (P)line (R)ectangle: "
          )
  )
  (cond
    ((= p "Line")
     (progn
       (command "Line")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  (cond
    ((= p "Pline")
     (progn
       (command "Pline")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  ((= p "Rectangle")
     (progn
       (command "Rectangle")
  (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )
  (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7529
Lisp commands
« Reply #31 on: November 15, 2004, 01:18:19 PM »
Quote
Here is another method.


Thanks CAB! :D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #32 on: November 15, 2004, 01:25:26 PM »
Actually you don't need this
Code: [Select]
 (while (> (getvar "CMDACTIVE") 0)
    (command pause)
  )

  If the command is the last thing the LISP does, you can return control to the ACAD command.
  Like this:
Code: [Select]
(defun c:lll (/ p) ;USED FOR DRAWING LINE ON SPECIFIED LAYER
  (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" "" "")
     )
    )
  )
  (initget 1 "Line Pline Rectangle") ;Gets L or P or R
  (setq p (getkword
            "\nEnter an option (L)ine (P)line (R)ectangle: "
          )
  )
  (cond
    ((= p "Line") (command "Line"))
    ((= p "Pline") (command "Pline"))
    ((= p "Rectangle") (command "Rectangle"))
  )
)
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 #33 on: November 15, 2004, 02:26:11 PM »
cab here's what i've done with the lisp. i had some toolbars for different hatches for different materials. so i've modified those and just made glass steel and aluminum toolbars which also include buttons for drawing each type line pline and rectangle pretty sweet thanks man

http://www.theswamp.org/screens/dan/NEW%20TOOLS.doc

ELOQUINTET

  • Guest
Lisp commands
« Reply #34 on: November 15, 2004, 02:27:05 PM »
can't see them very well but i think u get the idea  :wink:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Lisp commands
« Reply #35 on: November 15, 2004, 02:30:32 PM »
Good for you, dan
Keep it up..
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.

MikePerry

  • Guest
Lisp commands
« Reply #36 on: November 15, 2004, 03:51:49 PM »
Quote from: CAB
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.

Hi CAB

I don't mind in the slightest, after all I'm no LISP Programmer.... totally agree the use of the "cond" sub is much cleaner and works much better in this situation.

Cheers, Mike