Try this:
(defun C:ABP (/ ss n blk ins pathss path); = Align Block(s) to Path(s)
(if (setq ss (ssget '((0 . "INSERT"))))
(repeat (setq n (sslength ss)); then
(setq
blk (vlax-ename->vla-object (ssname ss (setq n (1- n))))
ins (vlax-get blk 'InsertionPoint)
); setq
(if (setq pathss (ssget "_C" (polar ins 0 1) (polar ins pi 1) '((0 . "*LINE"))))
(progn ; then
(setq path (ssname pathss 0))
(vla-put-Rotation blk
(angle
'(0 0 0)
(vlax-curve-getFirstDeriv path
(vlax-curve-getParamAtPoint path
(vlax-curve-getClosestPointTo path ins)
); ...getParam...
); ...FirstDeriv
); angle
); ...put...
); progn
); if
); repeat
); if
); defun
I don't really like the Crossing-window selection of the path, because depending on the scale of things, it could find more than one path. But when I used simply the insertion point as the pick point, it worked on only one Block in your sample drawing, and I couldn't figure out why. It wasn't "seeing" the path for any Blocks but the one, even when I forced Block insertion points to ensure they were truly on the path. I tried several variant approaches without success. And it's not like somehow doing the first one spoiled anything for subsequent ones, because the one it worked on isn't the first or last one in the selection. I even wondered whether the fact that the Block has an Alignment parameter could be the reason, but if so, it shouldn't have worked for any of them.
In case anyone has any bright ideas as to what the problem could be, what I originally had in place of this:
(if (setq pathss (ssget "_C" (polar ins 0 1) (polar ins pi 1) '((0 . "*LINE"))))
was this:
(if (setq pathss (ssget ins '((0 . "*LINE"))))
which did the trick for one Block [so it must have some kind of validity], but not for the rest.
I even tried adding the ":E" mode in, both before and after the 'ins', but got a too-many-arguments error. And I tried that omitting the entity-type filter, intending to remove the Block from the resulting selection, but got a bad-point-argument error. I guess I don't really get what the ":E" mode does, or how it relates to other arguments, and Help doesn't include any examples of its use.
By the way, for other kinds of path objects, you can replace that (ssget) filter list with:
'((0 . "*LINE,CIRCLE,ARC,ELLIPSE,RAY"))
[and, if necessary, do some checking later to avoid MLINEs, which such a selection would accept but which can't be aligned with using (vlax-curve...) methods].
Kent Cooper, AIA