Though it seems a lot more work this way than with Osnapping for centers, still, a few comments....
For avoiding endless loops and to eliminate confusion about indexing and the difference between closed and open Polylines:
You want to check for the bulge factor at the parameter at the beginning of every segment. The last one of those is one less than the end parameter, whether the Polyline is open or closed. I would be inclined to skip the comparison of the Parameter value to the End value in that (while) loop [also thereby eliminating the need for the End variable], and just tell it explicitly how many times to do it all, since you can determine the number of iterations needed, as you do with stepping through the selection set with a (repeat). I'd replace this much:
(setq Param 0 End (vlax-curve-getendparam Obj))
(while (<= Param End)
(and
(princ (strcat "\nParam=" (itoa Param)))
(setq P1 (vlax-curve-getpointatparam Obj Param))
(setq Bulge (vla-getbulge Obj Param))
(setq Param (1+ Param))
(if (> Param End)(setq Param 0) 1)
(not (zerop Bulge))
(setq P2 (vlax-curve-getpointatparam Obj Param))
with something like this [which works backwards from the end]:
(repeat (1- (setq Param (fix (vlax-curve-getendparam Obj))))
(and
(setq P2 (vlax-curve-getpointatparam Obj Param)); moved earlier, before stepping Param value down
(princ (strcat "\nParam=" (itoa (setq Param (1- Param))))); previous Parameter to use in following 2 variables
(setq P1 (vlax-curve-getpointatparam Obj Param))
(setq Bulge (vla-getbulge Obj Param))
(not (zerop Bulge))
Another thought -- here's a more concise way to define the (SignOf) function, returning the 1.0 or -1.0 value directly without the need for a test and different returns depending on the test result:
(defun SignOf (#)
(/ # (abs #))
)
Kent Cooper, AIA