Tested in 2007 and my friend has tested it in 2014 and it works without error.
(defun c:cpyala ( / *error* vector v*s vect_dot v+ v- vect_mod create_value_vector unit_vect asin acos old hor p1 p2 v1 side v2 dis ang across sp dis a b pa uv i ss) ;
(defun *error* ()
(setvar 'osmode old)
(setvar 'cmdecho 1)
(princ)
)
(defun vector (p1 p2) (mapcar '- p2 p1))
(defun v*s (v s)(mapcar '* v (create_value_vector (length v) s)))
(defun vect_dot (v1 v2)(apply '+ (mapcar '* v1 v2)))
(defun vect_mod (v)(sqrt(vect_dot v v)))
(defun create_value_vector (n val / r ) (repeat n (setq r (cons val r))) r)
(defun unit_vect (v)(mapcar '* v (create_value_vector (length v) (/ 1 (vect_mod v)))))
(defun asin (x)
(cond
((and(> x -1.0)(< x 1.0)) (atan (/ x (sqrt (- 1.0 (* x x))))))
((= x -1.0) (* -1.0 (/ pi 2)))
((= x 1) (/ pi 2))
)
)
(defun acos (x)(cond ((and(>= x -1.0)(<= x 1.0)) (-(* pi 0.5) (asin x)))))
(defun vectorSide (v1 v2 p / r *fuzz*)
(setq r (- (* (-(car v2)(car v1))(-(cadr p)(cadr v1)))
(* (-(cadr v2)(cadr v1))(-(car p)(car v1)))
)
*fuzz* 1e-10
)
(cond ((equal r 0.0 *fuzz*) 0) (t (fix (/ (abs r) r))))
)
(setq old (getvar 'osmode))
(setq hor (getreal "\nHorizontal distance (rectangle width + gap >"))
(setq
p1(getpoint "\nSelect first point on bounding polygon segment >")
p2(getpoint "\nSelect second point on bounding polygon segment >")
v1 (vector p1 p2)
side (vectorSide p1 (list (car p1) (+ (cadr p1) 100)) p2)
dis (distance p1 p2)
)
(if (= side 1)
(setq v2 (vector p1 (list (- (car p1) 100) (cadr p1))))
(setq v2 (vector p1 (list (+ (car p1) 100) (cadr p1))))
)
(setq ang (acos (/ (vect_dot v1 v2) (* ( vect_mod v1)(vect_mod v2)))))
(setq across (abs(/ hor (cos ang))))
(setvar 'osmode 2561)
(setvar 'cmdecho 0)
(setq sp (getpoint "\n Select starting point on bounding polygon >"))
(setq dis (- dis (distance sp p1)) i 0)
(princ "\nSelect objects to align across polygon segment >")
(setq a (getpoint "\nSelect first point of selection window >"))
(setq b (getcorner a "\nSelect second point of selection window >"))
(setq ss (ssget "W" a b))
(setvar "osmode" 1)
(setq pa (getpoint "\nSelect a rectangle corner point to align across segment >"))
(setq uv (unit_vect v1) delvect (v*s uv across))
(while (< i dis)
(command "_.copy" ss "" "none" pa "none" sp)
(setq sp (mapcar '+ sp delvect))
(setq i (+ i across))
)
(setvar 'osmode old)
(setvar 'cmdecho 1)
(princ)
)
(princ "\nType CPYALA to run command!"
(princ)
Procedure:
1) Horizontal distance (rectangle width + gap) > enter value
2) Select first point on bounding polygon segment > Click on oneend of a polygon segment
3 ) Click on end point of polygon segment
Move from polygon left to right or opposite over segments that are at placed up and horizontaly
4)Select starting point on bounding polygon
Osmode changes so that you can pick either starting point or nearest point or intersection somewhere inside range from p1 to p2
5)Select objects to align across polygon segment> You have vertical column of rectangles placed somewhere aside, select them by picking left or right
6) Select a rectangle corner point to align across segment > Pick corner point of rectangle that has to be set on segment between start point (point you selected inside segment range at distance 0 or what applicable to retain horizontal sequence. This is a point on rectangle in temporary column of topmost rectangle or one on the bottom.
Then loop starts and copies from a starting point and in sequence copies temp column to a start point that in every iteration moves from start to end for a vector distance that is a value of horizontal spacing divided with cosine of a angle between horizontal and vector from start point to end point of polygon segment.
Code use functions that are all tested in many occasions, only place where error can emerge is in a command sequence. But it works in a version that is older and newer to 2012. Code needs some polishing but it can be used even it this form.







If this finally start to work on your side, and when we polish code to do some stuff automatically final function will bi written that collects all rectangles outside bounding polygon and those that he intersects with. There is a option to update this script to find most appropriate angle to place max number of rectangles, as I stated in my first post .
Miljenko Hatlak

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.