Help in translating understanding a code example
Posted: Fri Apr 13, 2012 10:17 am
Hello, I'm very new to lisp and have been an assembly, C,C++ programmer embedded guy for most my life.
I'm struggling to diagram and add comments on how this utility(below) works as my learning point
then convert it to C. It's a "Clear Duplicates" utility from CAD programs that would be useful for my
cad drawings as I convert them to CNC paths.
Does anyone have some moments to spare to guide me on this? I appreciate it. -Lee
==========
I'm struggling to diagram and add comments on how this utility(below) works as my learning point
then convert it to C. It's a "Clear Duplicates" utility from CAD programs that would be useful for my
cad drawings as I convert them to CNC paths.
Does anyone have some moments to spare to guide me on this? I appreciate it. -Lee
==========
Code: Select all
; from http://www.eng-tips.com/viewthread.cfm?qid=152022
;Tip1744: CLEAR.LSP Clear duplicates (c)2001, ;Andrzej Gumula
;===================================================================================
(defun DXF (A) (cdr (assoc A (entget ONE)))) ;end dxf
(defun COMPLEX ()
(while (not (wcmatch (DXF 0) "*END*"))
(setq ONE (entnext ONE)
ELEM (append ELEM (list ONE)))
(CHECK)) ;end while
) ;end complex
(defun CORECT (A)
(cond ((= (type (cdr A)) 'list)
(cons (car A) (mapcar '(lambda (X) (atof (rtos X 2 8))) (cdr A))))
((member (type (cdr A)) (list 'INT 'REAL))
(cons (car A) (mapcar '(lambda (X) (atof (rtos X 2 8))) (list (cdr A)))))
(t A))) ;end corect
(defun CHECK ()
(foreach X (entget ONE)
(if (not (member (car X) '(-2 -1 5 6 8 62 100)))
(setq TEMP (cons (CORECT X) TEMP))))) ;end check
;(defun c:clear (/ CM LISTA NEW ONE TEMP OLD ZNACZNIK)
(defun C:CLEAR ()
(setq CM (getvar "cmdecho")
LISTA NIL
NEW NIL
ONE NIL
TEMP NIL
OLD (ssget "_X"))
(setvar "cmdecho" 0)
(cond
(OLD
(command "_-layer" "_u" "*" "")
(prompt "\nDrawing clearing. ")
(prompt "\nPlease wait... \n")
(while (cond (ONE (setq ONE (entnext ONE)))
(t (setq ONE (entnext))))
(setq ELEM (append ELEM (list ONE)))
(CHECK)
(if (or (and (= (DXF 0) "INSERT") (= (DXF 66) '1)) (= (DXF 0) "POLYLINE"))
(COMPLEX))
(if (member TEMP LISTA)
(foreach X ELEM (entdel X)))
(setq LISTA (cons TEMP LISTA)
TEMP NIL
ELEM NIL)
(cond (ZNACZNIK (setq ZNACZNIK NIL) (princ "\r\\"))
(t (setq ZNACZNIK (princ "\r/"))))) ;end while
(prompt (strcat "\nNumber of elements before clearing- " (itoa (sslength OLD))))
(prompt
(strcat "\nNumber of elements after clearing- " (itoa (sslength (ssget "_X"))))))
(t (prompt "\nFound zero elements. "))) ;end cond
(setvar "cmdecho" CM)
(princ)) ;end file
(prompt "\nLoaded new command CLEAR. ")
(princ)