I suppose using the pick set if more than one entity as the "to be moved" set is too confusing?
Here is the single object version:
;;;=======================[ AlignAll.lsp ]==============================
;;; Author: Copyright© 2009 Charles Alan Butler aka CAB
;;; Contact @ www.TheSwamp.org
;;;
;;; Version: 1.1 beta Feb. 2, 2009
;;; Purpose: Align objects to a primary object or point using the
;;; Top, bottom, left, right edges OR align using the Center of the
;;; primary object OR Center Vertically or Center Horizontally based
;;; on the primary object.
;;;
;;; http://www.theswamp.org/index.php?topic=18116.0
;;;=====================================================================
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED ;
;;; WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR ;
;;; PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED. ;
;;; ;
;;; You are hereby granted permission to use, copy and modify this ;
;;; software without charge, provided you do so exclusively for ;
;;; your own use or for use by others in your organization in the ;
;;; performance of their normal duties, and provided further that ;
;;; the above copyright notice appears in all copies and both that ;
;;; copyright notice and the limited warranty and restricted rights ;
;;; notice below appear in all supporting documentation. ;
;;;=====================================================================
(defun c:AlignAll (/ e1 target box ss side from to ent pt ss:first)
(vl-load-com)
;; expects an ename, returns list or nil
(defun GetBB (obj / ll ur err)
(setq obj (vlax-ename->vla-object obj))
(setq err (vl-catch-all-apply
'vla-getboundingbox (list obj 'll 'ur))
)
(if (not (vl-catch-all-error-p err))
(list (vlax-safearray->list ll) (vlax-safearray->list ur))
)
)
;;======================================
;; get anything already selected, if only one object use it as the alignment item
(cond
((and (setq ss:first (cadr(ssgetfirst)))
(= (sslength ss:first) 1)
(setq target (GetBB (ssname ss:first 0))))
(sssetfirst nil)
)
(t ; no single ent so get one from the user
(sssetfirst nil) ; de-select
(setvar "errno" 0) ; must pre set the errno to 0
(while ; loop until nil is returned from the cond
(cond
((= (getvar "errno") 52) (prompt "\nUser quit.")) ; exit loop
((and pt (listp pt)) nil)
((or (initget "P")
(null (setq e1 (entsel "\nSelect alignment entity, or P to pick point."))))
(princ "\nNothing selected, try again."))
((= e1 "P")(initget 1)(setq pt (getpoint "\nPick alignment point")))
((setq target (GetBB (car e1))) ; got a good BB
nil )
(e1 (princ "\nError - Can not use that object."))
)
)
)
)
(if
(and (or target pt)
(princ "\nvvvvvvvvvvvvvvvvvvvvvvvvv")
(princ "\nSelect all other entities to align.")
(setq ss (ssget))
(not (initget 1 "Top Bottom Left Right Center mVert mHorz"))
(setq side (getkword "\nSide to align? [Top/Bottom/Left/Right/Center/mVert/mHorz]"))
)
(progn
(vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-StartUndoMark (vla-get-activedocument (vlax-get-acad-object)))
(cond
(pt (setq target pt))
((member side '("Top" "Right"))(setq target(cadr target)))
((member side '("Bottom" "Left"))(setq target (car target)))
((member side '("Center" "mVert" "mHorz"))
(setq target (mapcar '(lambda (a b) (/ (+ a b) 2.0)) (car target)(cadr target))))
)
(foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
(if (setq box (GetBB ent))
(progn
(cond
((= side "Top")
(setq from (cadr box))
(setq to (list (car from) (cadr target) (caddr from))))
((= side "Bottom")
(setq from (car box))
(setq to (list (car from) (cadr target) (caddr from))))
((= side "Left")
(setq from (car box))
(setq to (list (car target) (cadr from) (caddr from))))
((= side "Right")
(setq from (cadr box))
(setq to (list (car target) (cadr from) (caddr from))))
((member side '("Center" "mVert" "mHorz"))
(setq from (mapcar '(lambda (a b) (/ (+ a b) 2.0))
(car box)(cadr box)))
(cond
((= side "Center")
(setq to target))
((= side "mVert")
(setq to (list (car target) (cadr from) (caddr from))))
((= side "mHorz")
(setq to (list (car from) (cadr target) (caddr from))))
)
)
)
(vl-catch-all-apply
'vlax-invoke-method
(list (vlax-ename->vla-object ent) 'move
(vlax-3d-point from) (vlax-3d-point to))
)
)
)
)
(vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
)
)
(princ)
)
(prompt "\nAlign All Lisp loaded, enter AlignAll to run.")
(princ)