Author Topic: favorite autolisp functions  (Read 4238 times)

0 Members and 2 Guests are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
favorite autolisp functions
« on: January 04, 2005, 07:37:17 AM »
What are your two favorite autolisp functions and why?
TheSwamp.org  (serving the CAD community since 2003)

Ron Heigh

  • Guest
favorite autolisp functions
« Reply #1 on: January 04, 2005, 08:36:09 AM »
My 2 favorite are:

1. DWG+-
-this routine only works in Single Drawing Mode
-it opens the next drawing in the directory if you press +
-it opens the previous drawing in the directory if you press -
-it saves if you edit
-it doesn't save if you zoom, pan or just look around
-this routine saves lots of time when scrubbing drawings that the checker has marked changes on.

2. ZoomLimits
-this routine will zoom to the current drawing limits
-this is good when you actually use limits to their potential
-allows you to save you layouts and notes outside the printable limits area.
-zooms to what will actually be printed for reference.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
favorite autolisp functions
« Reply #2 on: January 04, 2005, 09:31:22 AM »
Sorry Ron, I meant built-in functions. i.e. ssget, getreal, etc. But that DWG+- sounds really useful.
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10652
favorite autolisp functions
« Reply #3 on: January 04, 2005, 09:39:56 AM »
"defun"

*lamo!* If i were going to be serious, i would prolly say: "mapcar" and "while".

Cause lists are everything in lisp.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
favorite autolisp functions
« Reply #4 on: January 04, 2005, 10:14:06 AM »
DEFUN and COND

Why? Because you said to only pick two :)

whdjr

  • Guest
favorite autolisp functions
« Reply #5 on: January 04, 2005, 10:16:36 AM »
Once I learned how to use mapcar (which I'm still learning) it beacame my favorite.  Also its ActiveX similar vlax-map-collection.

JohnK

  • Administrator
  • Seagull
  • Posts: 10652
favorite autolisp functions
« Reply #6 on: January 04, 2005, 10:22:57 AM »
Ohhh, Good one Stig! I wanna change one of my favorite to "cond" as well. (*sniff* I love that 'lil guy.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
favorite autolisp functions
« Reply #7 on: January 04, 2005, 11:39:03 AM »
I'd have to say

SET and READ
Code: [Select]

(setq count 0)
(repeat 10
  (setq temp (getstring "\nEnter string: "))
  (set (read (strcat "string[" (rtos count 2 0) "]")) temp)
  (setq count (1+ count))
)
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

CADaver

  • Guest
favorite autolisp functions
« Reply #8 on: January 04, 2005, 12:40:06 PM »
COND
WHILE

David Bethel

  • Swamp Rat
  • Posts: 656
favorite autolisp functions
« Reply #9 on: January 04, 2005, 01:21:30 PM »
(cond)
(foreach)
(tblnext) & (tblsearch)

-David
R12 Dos - A2K

dubb

  • Swamp Rat
  • Posts: 1105
favorite autolisp functions
« Reply #10 on: January 04, 2005, 02:12:49 PM »
IM A NOOOB

I use i know SETQ and SETVAR and /n

whdjr

  • Guest
favorite autolisp functions
« Reply #11 on: January 04, 2005, 03:49:04 PM »
Quote from: Keith

Code: [Select]

(repeat 10
  (setq count 0)
  (setq temp (getstring "\nEnter string: "))
  (set (read (strcat "string[" (rtos count 2 0) "]")) temp)
  (setq count (1+ count))
)


I might be missing something, but is this example right.  What's it supposed to do.  The set statement doesn't change the temp variable. :?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
favorite autolisp functions
« Reply #12 on: January 04, 2005, 04:54:36 PM »
What it does is emulate a C-style variable name in lisp and creates a pseudo array ...

In the above example, you will be prompted for 10 text entries, each one will be saved in a variable named string[0] through string[9] ..... of course there IS a problem I just noticed ... I corrected it in my example ....
Try pasting it into AutoCAD and test the value of string[0] though string[9]
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

whdjr

  • Guest
favorite autolisp functions
« Reply #13 on: January 04, 2005, 05:32:52 PM »
Ok.  I get it now.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
favorite autolisp functions
« Reply #14 on: January 05, 2005, 09:16:18 AM »
Well I have to say IF and MAPCAR are my favorite two functions. To test my theory I looked at all the .lsp files in my 'working' dir. These are files that may or may not make it into production but I think a good idea of how I write my autolisp code.

These are the commands I used.

first we get a number of all the .lsp files

dir /b *.lsp | wc -l
    375 <-- output

then I use grep and a regex to seek out lines that contain '(if'

grep -e "^.*(if\>" *.lsp |wc -l
   3140 <-- output

That equates to an average 8 lines of '(if' per file.

'mapcar' isn't quite as abundant.

grep -e "^.*(mapcar\>" *.lsp |wc -l
    362 <-- output

But none the less that is still an average of 1 per .lsp file.
TheSwamp.org  (serving the CAD community since 2003)