Author Topic: Help for LISP beginner  (Read 6113 times)

0 Members and 1 Guest are viewing this topic.

rus7755

  • Guest
Help for LISP beginner
« on: November 19, 2014, 02:46:21 PM »
I'm  somewhere beneath a rookie LISP programmer.  I was just try to write some short routines to reduce some extra clicking and to begin to learn something about LISP. 

What's wrong with this little routine written to simply rotate a selection set around a base point by 90 degrees?

(defun c:90()
   (SETQ SLT(SSGET))
   (SETQ PNT (GETPOINT "\nBASE POINT "))
       (command "ROTATE" SELECTION "" PNT "90")
   (SETQ SLT NIL)
)

;; Silent load.
(princ)


Thanks for the help,
rus7755

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Help for LISP beginner
« Reply #1 on: November 19, 2014, 02:54:12 PM »
I'm  somewhere beneath a rookie LISP programmer.  I was just try to write some short routines to reduce some extra clicking and to begin to learn something about LISP. 

What's wrong with this little routine written to simply rotate a selection set around a base point by 90 degrees?

(defun c:90()
   (SETQ SLT(SSGET))
   (SETQ PNT (GETPOINT "\nBASE POINT "))
       (command "ROTATE" SELECTION "" PNT "90")
   (SETQ SLT NIL)
)

;; Silent load.
(princ)


Thanks for the help,
rus7755

You don't have the selection set correct in the rotate command. Also, it is good practice to use the language independent and internally defined commands where you are able.

Code: [Select]
(defun c:90()
   (SETQ SLT(SSGET))
   (SETQ PNT (GETPOINT "\nBASE POINT "))
       (command "._ROTATE" SLT "" PNT "90")
   (SETQ SLT NIL)
)

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

rus7755

  • Guest
Re: Help for LISP beginner
« Reply #2 on: November 19, 2014, 03:08:58 PM »
Thanks for the reply Keith.

I tried the command again with the variable name corrected to "SLT", but it still fails when I pick the base point for rotation.  Do I have something wrong in the syntax for the GETPOINT command?


Thanks for the help,
rus7755

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Help for LISP beginner
« Reply #3 on: November 19, 2014, 03:11:21 PM »
Also don't forget to localize variables ( set them to nothing )


Code - Auto/Visual Lisp: [Select]
  1. (defun c:90 (/ pnt slt);; <-- Localized variables after /
  2.   (if (and (setq slt (ssget)) (setq pnt (getpoint "\nBASE POINT ")))
  3.     (command "ROTATE" slt "" pnt "90")
  4.   )
  5.   (princ)
  6. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: Help for LISP beginner
« Reply #4 on: November 19, 2014, 03:14:41 PM »
... Or simply:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:90 (/ ss)
  2.   (if (setq ss (ssget "_:L"))
  3.     (command "._rotate" ss "" pause "90")
  4.   )
  5.   (princ)
  6. )
  7.  
"How we think determines what we do, and what we do determines what we get."

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Help for LISP beginner
« Reply #5 on: November 19, 2014, 03:16:38 PM »
Its also a good idea to provide readable command names, like PICKANDROTATE90.  Calling a command "90" isn't descriptive of the function and isn't very unique (every command must be a unique name).  If you want shorter commands, use the PGP file to assign a shortcut e.g. R90,    *PICKANDROTATE90
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

rus7755

  • Guest
Re: Help for LISP beginner
« Reply #6 on: November 19, 2014, 03:27:57 PM »
It still crashes when I pick the base point...

??????????


Thanks,
rus7755

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Help for LISP beginner
« Reply #7 on: November 19, 2014, 03:52:39 PM »
Strange indeed ... I don't have AutoCAD installed at work so I cannot test your code, but it certainly appears correct.

I would verify that the code in your file is exactly as provided. Also, you do realize that you will need to reload the lisp each time you editing it.
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

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Help for LISP beginner
« Reply #8 on: November 19, 2014, 04:13:47 PM »
It still crashes when I pick the base point...

 :? :? :? ?


Thanks,
rus7755
The one I posted works for me.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ChrisCarlson

  • Guest
Re: Help for LISP beginner
« Reply #9 on: November 19, 2014, 04:17:04 PM »
BlackBox's assumes the item to be rotated was the last created entity.

But what is the error or crash message?

BlackBox

  • King Gator
  • Posts: 3770
Re: Help for LISP beginner
« Reply #10 on: November 19, 2014, 04:20:38 PM »
BlackBox's assumes the [user only wanted to rotate entities on unlocked layers].

FTFY :angel:
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Help for LISP beginner
« Reply #11 on: November 19, 2014, 04:27:50 PM »
Close enough to post for a quick mod...

Code: [Select]
(defun c:RR (/ ss pt)
  ;; Rotate selected object(s) 180°
  ;; Alan J. Thompson
  (if (and (princ "\nSelect object(s) to rotate 180°: ")
           (setq ss (ssget "_:L"))
           (setq pt (getpoint "\nSpecify rotation base point: "))
      )
    (command "_.rotate" ss "" "_non" pt 180.)
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

rus7755

  • Guest
Re: Help for LISP beginner
« Reply #12 on: November 19, 2014, 04:47:43 PM »
alanjt,

I've been reloading my lisp routines through APPLOAD.  I'm assuming this brings in a fresh copy of the routine each time.  Is this true?

I ran the routine and it still behaved the same way  - bombing out after the base point is selected - started thinking it might not be loading the newest version of the routine.  Just not sure.

Also, can you explain this line:   ssget "_:L"

thanks,
rus7755

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Help for LISP beginner
« Reply #13 on: November 19, 2014, 05:00:01 PM »
What version are you running?

the "_:L" tells ssget to ignore objects on locked layers.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

rus7755

  • Guest
Re: Help for LISP beginner
« Reply #14 on: November 19, 2014, 05:09:33 PM »
We're running AutoCAD 2014.