Author Topic: Lisp commands  (Read 9711 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.