OK gang, here's today's conundrum.
I've got this lisp that draws a ramp tag and it works great:
Code:
(defun c:ramp (/ arrow slopetext slopeorigin layorig usersnaps p1 p2 x1 x2 dist ang p3 angdeg)
(setq arrow "slopearrow.dwg")
(setq slopetext "slopevalue.dwg")
(setq slopeorigin "slopeorigin.dwg")
(setq layorig (getvar "clayer"))
(setq p1 (getpoint "\npick high point of ramp: "))
(setq p2 (getpoint "\npick low point of ramp: "))
(setq x1 (car p1))
(setq x2 (car p2))
(setq dist (distance P1 P2))
(setq ang (angle P1 P2))
(setq p3 (POLAR P1 ANG (/ DIST 2)))
(setq angdeg (* (/ ang pi) 180.0))
(command "-layer" "Make" "L-GR-TEXT" "Color" "3" "L-GR-TEXT" "Ltype" "CONTINUOUS" "" "")(princ)
(command "line" p1 p2 "")
(command "-insert" slopeorigin P1 "1" "1" angdeg)
(command "-insert" arrow p2 "1" "1" angdeg)
(command "-insert" slopetext p3 "1" "1" angdeg)
(if (> x1 x2) (command "rotate" "L" "" p3 "180")
)
(setvar "clayer" layorig)
(princ)
)
Now I've been asked to have the routine to make an unnamed group from the objects it creates. So I have cobbled this together (added code in red):
Code:
(defun c:ramp ( / arrow slopetext slopeorigin layorig usersnaps p1 p2 x1 x2 dist ang p3 angdeg ss lastEnt en)
(setq arrow "slopearrow.dwg")
(setq slopetext "slopevalue.dwg")
(setq slopeorigin "slopeorigin.dwg")
(setq layorig (getvar "clayer"))
(setq lastEnt (entlast))
(setq p1 (getpoint "\npick high point of ramp: "))
(setq p2 (getpoint "\npick low point of ramp: "))
(setq x1 (car p1))
(setq x2 (car p2))
(setq dist (distance P1 P2))
(setq ang (angle P1 P2))
(setq p3 (POLAR P1 ANG (/ DIST 2)))
(setq angdeg (* (/ ang pi) 180.0))
(command "-layer" "Make" "L-GR-TEXT" "Color" "3" "L-GR-TEXT" "Ltype" "CONTINUOUS" "" "")(princ)
(command "line" p1 p2 "")
(command "-insert" slopeorigin P1 "1" "1" angdeg)
(command "-insert" arrow p2 "1" "1" angdeg)
(command "-insert" slopetext p3 "1" "1" angdeg)
(if (> x1 x2) (command "rotate" "L" "" p3 "180")
)
(setq ss (ssadd))
(if (setq en (entnext LastEnt)) ;Check if there's a new entity created sinse the last one
(while en ;Step through all new entities
(ssadd en ss) ;Add it to the selection set
(setq en (entnext en)) ;Get the next entity
)
)
(command "_.-group" "c" "*" "*" ss "")
(setvar "clayer" layorig)
(princ)
)
It does what it should the first time, it makes a group form the objects created in the routine.
However, during subsequent runs, it makes a group of the objects created in the routine AND the last group created in the previous run. Obviously it should EXCLUDE the previous group and make the new group from only objects created SINCE last object was created.
I'm missing something. Thanks for your help.
I can't seem to upload files at the moment but Slopeorigin.dwg is just a circle, slopearrow.dwg is just an arrow made from 2 lines and slopevalue.dwg is just an atribute. You should be able substitue your own blocks easily. I'll keep trying.