Lisp writing crash coarse
1. In windows explorer create a new text file and call it "string-count.lsp"
2. Open string-count.lsp in your text editor, VSCode, or the VLIDE, or...
3. Copy the first three functions from this post:
"GETK"
"get1"
"sel2lst"
and paste them into the string-count.lsp
4. Open a copy of TCountV1-1.lsp and find the routines (copy and paste them into string-count.lsp).
"LM:AddTable"
"_startundo"
"_endundo"
5. Save the string-count.lsp
6. At the bottom of the string-count.lsp file create start a new function:
NOTE: Type--DO NOT COPY AND PASTE--the following:
(defun c:stringcount
( / ) *acdocumentspace*
*acdocument*
'Paperspace
'Modelspace
) ;_if
) ;_vlax-get-property
) ;_setq
(_StartUndo *acdocument*)
;;
(_EndUndo *acdocument*)
) ;_defun
7. We now--technically--have a working lisp file so it is time to start documenting our code. At the top of the file create the following:
;;;===================================================================
;;; string-count
;;;-------------------------------------------------------------------
;;; Date: 2021.12.08
;;; Author: ancrayzy
;;;-------------------------------------------------------------------
;;; This will count strings in the drawing and create a table showing
;;; the text string and the layer the text resides on.
;;;
;;; Inspiration and code has been taken from:
;;; Vladimir Neterovsky
;;; LeeMac
;;;===================================================================
8. Save the file.
9. Back to our stringcount function at the bottom. In between the start and end undo lines add the following (type do not copy/paste).
(getk '(1 8)
(sel2lst
(ssget"X" '
((0 .
"TEXT,MTEXT"))))) ) ;_getk
) ;_setq
(cons (list "String" "Layer") textkeylist
)) )
(LM:AddTable
*acdocumentspace*
"STRING COUNT"
textkeylist
)
10. On the first line of our function we need to localize our variables. we do that by typing the variable names after a forward slash.
(defun c:stringcount
( / *acdocument
* *acdocumentspace
* textkeylist point )
11. Our lisp is done but you can add a prompt to the bottom of the lisp to inform us the command to issue when we load the file.
(princ "\nstring count lisp loaded. Type [stringcount] to begin.")
12. Post your version of the "c:stringcount" function when you are done.
13. Ask questions!