;;;This LISP routine is designed to project rectangles to intersect with a line.
(vl-load-com)
(defun c:PJR (/ )
(defun vpt (n) (vlax-curve-getPointAtParam Rectangle n))
(defun vptln (n) (vlax-curve-getPointAtParam UpperRectangle n))
(defun lrptr () ;find top right vertice
(setq TestPoint (list 2000000 2000000 0))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 1) TestPoint))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 2) TestPoint)) ; then if
(if (< (distance (vpt 0) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq TopRightVertice 0) ;then vertice 0 is it
(setq TopRightVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq TopRightVertice 2) ;then vertice 2 is it
(setq TopRightVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 2) TestPoint)) ; else if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq TopRightVertice 1) ;then vertice 1 is it
(setq TopRightVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq TopRightVertice 2) ;then vertice 2 is it
(setq TopRightVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
) ; end if
) ; defun lrptr
(defun lrptl () ;find top left vertice
(setq TestPoint (list -2000000 2000000 0))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 1) TestPoint))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 2) TestPoint)) ; then if
(if (< (distance (vpt 0) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq TopLeftVertice 0) ;then vertice 0 is it
(setq TopLeftVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq TopLeftVertice 2) ;then vertice 2 is it
(setq TopLeftVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 2) TestPoint)) ; else if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq TopLeftVertice 1) ;then vertice 1 is it
(setq TopLeftVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq TopLeftVertice 2) ;then vertice 2 is it
(setq TopLeftVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
) ; end if
) ; defun lrptl
(defun lrpbr () ;find bottom right vertice
(setq TestPoint (list 2000000 -2000000 0))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 1) TestPoint))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 2) TestPoint)) ; then if
(if (< (distance (vpt 0) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq BottomRightVertice 0) ;then vertice 0 is it
(setq BottomRightVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq BottomRightVertice 2) ;then vertice 2 is it
(setq BottomRightVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 2) TestPoint)) ; else if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq BottomRightVertice 1) ;then vertice 1 is it
(setq BottomRightVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq BottomRightVertice 2) ;then vertice 2 is it
(setq BottomRightVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
) ; end if
) ; defun lrpbr
(defun lrpbl () ;find bottom left vertice
(setq TestPoint (list -2000000 -2000000 0))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 1) TestPoint))
(if (< (distance (vpt 0) TestPoint) (distance (vpt 2) TestPoint)) ; then if
(if (< (distance (vpt 0) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq BottomLeftVertice 0) ;then vertice 0 is it
(setq BottomLeftVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq BottomLeftVertice 2) ;then vertice 2 is it
(setq BottomLeftVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 2) TestPoint)) ; else if
(if (< (distance (vpt 1) TestPoint) (distance (vpt 3) TestPoint)) ; then if
(setq BottomLeftVertice 1) ;then vertice 1 is it
(setq BottomLeftVertice 3) ;else vertice 3 is it
) ;end if
(if (< (distance (vpt 2) TestPoint) (distance (vpt 3) TestPoint)) ; else if
(setq BottomLeftVertice 2) ;then vertice 2 is it
(setq BottomLeftVertice 3) ;else vertice 3 is it
) ;end if
) ; end if
) ; end if
) ; defun lrpbl
(defun fndint () ;find intersection
(setq RectanglePointPlus (list (car RectanglePoint) (+ (cadr RectanglePoint) 1) (caddr RectanglePoint)))
(setq Temp (inters (vptln BottomLeftVerticeSet) (vptln BottomRightVerticeSet) (list (car RectanglePoint) (cadr RectanglePoint) (caddr RectanglePoint)) (list (car RectanglePointPlus) (cadr RectanglePointPlus) (caddr RectanglePointPlus)) nil))
(list (car Temp) (cadr Temp))
) ; defun
(defun swpcoords ();swapping the coordinates
(cond
((= TopLeftVertice 0)
(setq Coords (list (car TopLeftIntersection) (cadr TopLeftIntersection) (nth 2 Coords) (nth 3 Coords) (nth 4 Coords) (nth 5 Coords) (nth 6 Coords) (nth 7 Coords))))
((= TopLeftVertice 1)
(setq Coords (list (nth 0 Coords) (nth 1 Coords) (car TopLeftIntersection) (cadr TopLeftIntersection) (nth 4 Coords) (nth 5 Coords) (nth 6 Coords) (nth 7 Coords))))
((= TopLeftVertice 2)
(setq Coords (list (nth 0 Coords) (nth 1 Coords) (nth 2 Coords) (nth 3 Coords) (car TopLeftIntersection) (cadr TopLeftIntersection) (nth 6 Coords) (nth 7 Coords))))
((= TopLeftVertice 3)
(setq Coords (list (nth 0 Coords) (nth 1 Coords) (nth 2 Coords) (nth 3 Coords) (nth 4 Coords) (nth 5 Coords) (car TopLeftIntersection) (cadr TopLeftIntersection)))))
(cond
((= TopRightVertice 0)
(setq Coords (list (car TopRightIntersection) (cadr TopRightIntersection) (nth 2 Coords) (nth 3 Coords) (nth 4 Coords) (nth 5 Coords) (nth 6 Coords) (nth 7 Coords))))
((= TopRightVertice 1)
(setq Coords (list (nth 0 Coords) (nth 1 Coords) (car TopRightIntersection) (cadr TopRightIntersection) (nth 4 Coords) (nth 5 Coords) (nth 6 Coords) (nth 7 Coords))))
((= TopRightVertice 2)
(setq Coords (list (nth 0 Coords) (nth 1 Coords) (nth 2 Coords) (nth 3 Coords) (car TopRightIntersection) (cadr TopRightIntersection) (nth 6 Coords) (nth 7 Coords))))
((= TopRightVertice 3)
(setq Coords (list (nth 0 Coords) (nth 1 Coords) (nth 2 Coords) (nth 3 Coords) (nth 4 Coords) (nth 5 Coords) (car TopRightIntersection) (cadr TopRightIntersection)))))
) ; defun
(defun fndtopunit ();finding which top unit is right above bottom unit
(setq TempListLength (sslength AllTopRectangles))
(setq TempCounter 0)
(setq TempRectangle Rectangle)
(setq TempDistance 2000000)
(while (> TempListLength 0)
(setq TempListLength (- TempListLength 1))
(setq Rectangle (vlax-ename->vla-object (ssname AllTopRectangles Counter)))
(lrpbl) (lrpbr) (fndmiddlelineT)
(if (< (- LowerMiddlePointX UpperMiddlePointX) TempDistance) (progn
(setq TempDistance (- LowerMiddlePointX UpperMiddlePointX))
(setq UpperRectangle Rectangle)
(setq BottomLeftVerticeSet BottomLeftVertice)
(setq BottomRightVerticeSet BottomRightVertice)))
(setq TempCounter (+ TempCounter 1))
); end while
(setq Rectangle TempRectangle)
) ; defun
(defun fndmiddlelineB ();finding the center X value between two points on the bottom
(setq TempLeftX (car (vpt TopLeftVertice)))
(setq TempRightX (car (vpt TopRightVertice)))
(setq LowerMiddlePointX (/ (+ TempLeftX TempRightX) 2))
) ; defun
(defun fndmiddlelineT ();finding the center X value between two points on the top
(setq TempLeftX (car (vpt BottomLeftVertice)))
(setq TempRightX (car (vpt BottomRightVertice)))
(setq UpperMiddlePointX (/ (+ TempLeftX TempRightX) 2))
) ; defun
(princ "\nSelect all BOTTOM wall unit rectangles to project (type 'f' and use the fence option): ")
(setq AllRectangles (ssget))
(princ "\nSelect all TOP wall unit rectangles to project TO (type 'f' and use the fence option): ")
(setq AllTopRectangles (ssget))
(setq ListLength (sslength AllRectangles))
(setq Counter 0)
(while (> ListLength 0)
(setq ListLength (- ListLength 1))
(setq Rectangle (vlax-ename->vla-object (ssname AllRectangles Counter)))
(setq Coords (vlax-get Rectangle 'Coordinates))
(lrptl) (lrptr) (fndmiddlelineB) (fndtopunit)
(setq RectanglePoint (vpt TopLeftVertice))
(setq TopLeftIntersection (fndint))
(setq RectanglePoint (vpt TopRightVertice))
(setq TopRightIntersection (fndint))
(swpcoords)
(vlax-put Rectangle 'Coordinates Coords)
(setq Counter (+ Counter 1))
); end while
(princ)
)