Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP to move planar splines to elevation zero.

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
rvaish
1189 Views, 2 Replies

LISP to move planar splines to elevation zero.

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!

2 REPLIES 2
Message 2 of 3
dbroad
in reply to: rvaish

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.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 3
Kent1Cooper
in reply to: rvaish


@rvaish 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.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost