*Alex wrote:
My goal is to draw a line with polar tracking on set to various bend angles.
as each angle is formed it will insert the appropriate bend. for some
reason this way sporadiacally inserts the bends and often a ways down the
run it quits putting in bends altogether....
....
(command "line" pause)(setq pt1 (getvar "lastpoint"))
(command pause)(setq pt2 (getvar "lastpoint"))
(while (= nil nothing)
....(setq myang (r2d (dotp pt1 pt2 pt2 pt3)) RANG 0.0)
....(if (eq myang 90.0) (progn (command "" "insert" "90 BEND" PT2 BPS BPS RANG "line" pt3 )))
....
;dotp.lsp pass 4 points containing the x y z vals of the 2 vectors.
(defun dotp (tpt1 tpt2 tpt3 tpt4)
(IF (= 2 (LENGTH TPT1)) (PROGN (SETQ TPT1 (LIST (CAR TPT1) (CADR TPT1)
0 ) ) ))
....
I'm guessing that maybe you need a fuzz factor in your check on the value of 'myang', something like:
(if (equal myang 90.0 1e-6)....
A couple of other things I noticed:
You have a lot of (progn) functions that you don't need. They're only needed where a 'then' or 'else' argument to an (if) function requires running more than one function, but yours all seem to call for only single (command) or (setq) functions, so they don't need the (progn) wrappers.
A simpler way to get something to run repeatedly until the User hits Escape is:
(while T
....
I don't think you need that (if (= 2 (length tpt1))... part about adding a Z component to two-component point lists. That may be appropriate in other applications, but it looks like in this one all your arguments are coming from (getvar "lastpoint") functions, which return 3-component point lists.
And I expect the determination of the bend angles could be a lot simpler with an approach something like:
(setq bend
(rem
(- (angle pt2 pt3) (angle pt1 pt2))
(/ pi 2)
)
)
That should give you a radian value from which you can get the bend angle [0 for 90 degrees], for determination of which Block to insert. And depending on the way your Blocks are constructed, one of those (angle) functions should give you the rotation angle directly [in radians]. Even adding some compensation for the possibility of crossing the zero-degree direction and something to determine whether the bend was to the left or right, I expect it could still be simpler than the (dotp)/(sq)/(acos) family of functions.