OK Here is a function that works for your purposes.
It has a lot of room to be enhanced.
Select the text to move and select the last piece of text above it for alignment.
The complexity comes from finding the insertion point of the top of group of text, various sorting steps need to happen
Then it is relatively straight forward.
(This post and attachments has been revised)
P=
Code:
;___________________________________________________________________________________________________________|
;
; Written By: Peter Jamtgaard C.E., P.E., S.E. copyright 2020 All Rights Reserved
;___________________________________________________________________________________________________________|
;
; Any use by unauthorized person or business is strictly prohibited.
;___________________________________________________________________________________________________________|
;
; Command Line Function Header List
;___________________________________________________________________________________________
; Function and Description
;* C:OQ
;* C:OffsetQuestion
;* Command Line Function to move selected group of text under another selected text
;___________________________________________________________________________________________________________|
;
; General Function Header List
;___________________________________________________________________________________________________________|
;* (ListofSublistsSortbyAnItem lstOfSublists intItem)
;* Function to sort list of sublists by item
;* (ObjectInsertionPointSublist objText)
;* Function to create a sublist of x,y,z coordinates, height and vla-object of a vla-object
;* (SelectionSetToListOfObjects ssSelections)
;* Function to convert selection set into list of vla-objects
;* (TopLineOfTextInsertionPoint ssSelections)
;* Function to get insertion point of top line of Text
;$ Header End
;___________________________________________________________________________________________________________|
;
; Command Line Function to move selected group of text under another selected text
;___________________________________________________________________________________________________________|
(defun C:OQ ()(C:OffsetQuestion))
(defun C:OffsetQuestion (/ lstInsertion1 lstInsertion2 lstObject1 lstObjects objSelection
sngHeight ssSelection1 ssSelections)
(if (and (princ "\nSelect Text To Move: ")
(setq ssSelections (ssget (list (cons 0 "text"))))
(setq lstObjects (SelectionSetToListOfObjects ssSelections))
(princ "\nSelect Text for Alignment: ")
(setq ssSelection1 (ssget ":S:E" (list (cons 0 "text"))))
(setq lstObject1 (SelectionSetToListOfObjects ssSelection1))
(setq objSelection (car lstObject1))
(setq lstInsertion1 (vlax-get objSelection "insertionPoint"))
(setq sngHeight (vlax-get objSelection "height"))
(setq lstInsertion1 (mapcar '+ (list 0.0 (* -3.213 sngHeight) 0.0) lstInsertion1)); For Romans.shx
(prinx 'lstInsertion1)
(setq lstInsertion2 (TopLineOfTextInsertionPoint ssSelections))
(prinx 'lstInsertion2)
)
(vl-cmdf "move" ssSelections "" lstInsertion2 lstInsertion1)
)
)
;___________________________________________________________________________________________________________|
;
; Function to sort list of sublists by item
;___________________________________________________________________________________________________________|
(defun ListofSublistsSortbyAnItem (lstOfSublists intItem)
(vl-sort lstOfSublists '(lambda (X Y) (< (nth intItem X) (nth intItem Y))))
)
;___________________________________________________________________________________________________________|
;
; Function to create a sublist of x,y,z coordinates, height and vla-object of a vla-object
;___________________________________________________________________________________________________________|
(defun ObjectInsertionPointSublist (objText)
(append (list objText)
(vlax-get objText "insertionpoint")
)
)
;___________________________________________________________________________________________________________|
;
; Function to convert selection set into list of vla-objects
;___________________________________________________________________________________________________________|
(defun SelectionSetToListOfObjects (ssSelections / entSelection intCount lstObjects objSelection)
(repeat (setq intCount (sslength ssSelections))
(and
(setq intCount (1- intCount))
(setq entSelection (ssname ssSelections intCount))
(setq objSelection (vlax-ename->vla-object entSelection))
(setq lstObjects (cons objSelection lstObjects))
)
)
lstObjects
)
;___________________________________________________________________________________________________________|
;
; Function to get insertion point of top left of Text
;___________________________________________________________________________________________________________|
(defun TopLineOfTextInsertionPoint (ssSelections / lstObjects lstOfObjects
lstCoordinatesX lstCoordinatesY lstCoordinateX lstCoordinateY )
(if (and (setq lstObjects (SelectionSetToListOfObjects ssSelections))
(setq lstOfSublists (mapcar 'ObjectInsertionPointSublist lstObjects))
(setq lstCoordinatesX (mapcar 'cadr lstOfSublists))
(setq lstCoordinatesY (mapcar 'caddr lstOfSublists))
(setq sngCoordinateX (apply 'min lstCoordinatesX))
(setq sngCoordinateY (apply 'max lstCoordinatesY))
)
(list sngCoordinateX sngCoordinateY 0.0)
)
)
(vl-load-com)