Author Topic: Lisp commands  (Read 9712 times)

0 Members and 1 Guest are viewing this topic.

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