I need to move lots of planar splines to elevation zero. I have written a simple LISP routine to do this but the loop for some reason seems to stop after 3 iterations without doing anything.
(defun c:FlatSp()
(setq eset (ssget "X" (list(cons 0 "SPLINE"))))
(setq cntr 0)
(setq p1 (list 0 0 0))
(while (< cntr (sslength eset))
(setq en (ssname eset cntr))
(setq enlist (entget en))
(setq entCntrlZ (nth 2 (cdr(assoc 10 enlist))))
;move the object if elevation is not zero
(if (/= entCntrlZ 0)
(setq p2 (list 0 0 (- entCntrlZ)))
(command "_MOVE" en "" p1 p2)
)
(setq cntr (+ cntr 1))
)
)
Please help!
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by dbroad. Go to Solution.
You were close. You missed wrapping the two statements in the if with a progn to make them both execute. I localized the variables and eliminated the need to use p1. You could also just save the selection set length for use in the while rather than to get it each time through the loop. It did not seem to stop after 3 iterations anyway.
(DEFUN c:flatsp (/ eset cntr en enlist entctrlz p2) (SETQ eset (SSGET "X" (LIST (CONS 0 "SPLINE")))) (SETQ cntr 0) ;;(setq p1 (list 0 0 0)) (WHILE (< cntr (SSLENGTH eset)) (SETQ en (SSNAME eset cntr)) (SETQ enlist (ENTGET en)) (SETQ entcntrlz (NTH 2 (CDR (ASSOC 10 enlist)))) ;move the object if elevation is not zero (IF (/= entcntrlz 0) (PROGN (SETQ p2 (LIST 0 0 (- entcntrlz))) (COMMAND "_MOVE" en "" ;|p1|; p2 "") ) ) (SETQ cntr (+ cntr 1)) ) )
Keep lisping.
@Anonymous wrote:
I need to move lots of planar splines to elevation zero. I have written a simple LISP routine to do this but the loop for some reason seems to stop after 3 iterations without doing anything.
(defun c:FlatSp()
(setq eset (ssget "X" (list(cons 0 "SPLINE"))))
(setq cntr 0)
(setq p1 (list 0 0 0))(while (< cntr (sslength eset))
(setq en (ssname eset cntr))
(setq enlist (entget en))
(setq entCntrlZ (nth 2 (cdr(assoc 10 enlist))))
;move the object if elevation is not zero
(if (/= entCntrlZ 0)
(setq p2 (list 0 0 (- entCntrlZ)))
(command "_MOVE" en "" p1 p2)
)
(setq cntr (+ cntr 1))
)
)
Please help!
I'm not sure it will address the 3-iterations issue, but there's something you need to fix. Try this way:
(defun c:FlatSp ()
(setq eset (ssget "X" (list (cons 0 "SPLINE"))))
(setq cntr 0)
(setq p1 (list 0 0 0))
(while (< cntr (sslength eset))
(setq en (ssname eset cntr))
(setq enlist (entget en))
(setq entCntrlZ (nth 2 (cdr (assoc 10 enlist))))
;move the object if elevation is not zero
(if (/= entCntrlZ 0)
(progn ; then
(setq p2 (list 0 0 (- entCntrlZ)))
(command "_MOVE" en "" p1 p2)
); progn
)
(setq cntr (+ cntr 1))
)
)
You need to "wrap" the setting of p2 and Moving of the Spline into one 'then' argument for the (if) function, with (progn) being the wrapper. As you have it, if the Spline doesn't start at 0 elevation it will set p2 [the 'then' argument] but not Move it, but if it does start at 0 elevation it will not set p2 but will try to Move it [the 'else' argument], and for the first one, won't be able to, because there's no p2, and for any later ones, will be able to but using p2 based on some other Spline's start point.