Hi,
The position of the gizmo is the center of the extents (bounding-box) of the selected entity(ies).
Here're some routines to get the extents of an entity or a list of entities and to compute the mid point of two points.
;; Gets the extents of the supplied entity or vla-object.
;; Returns a list containing the lower left and upper right coordinates.
(defun getExtents (entity / ll ur)
(vl-load-com)
(or (= (type entity) 'vla-object)
(setq entity (vlax-ename->vla-object entity))
)
(vla-GetBoundingBox entity 'll 'ur)
(list
(vlax-safearray->list ll)
(vlax-safearray->list ur)
)
)
;; Gets the global extents of the supplied entities or vla-objects.
;; Returns a list containing the lower left and upper right coordinates.
(defun getMExtents (entities)
((lambda (l)
(list
(apply 'mapcar (cons 'min (mapcar 'car l)))
(apply 'mapcar (cons 'max (mapcar 'cadr l)))
)
)
(mapcar 'getExtents entities)
)
)
;; Gets the middle of the supplied points.
;; Returns the middle point coordiantes.
(defun getMidPoint (p1 p2)
(mapcar
(function (lambda (x1 x2) (/ (+ x1 x2) 2.0)))
p1
p2
)
)
Testing commands:
(defun c:test1 (/ ent)
(and
(setq ent (car (entsel)))
(entmake
(list (cons 0 "POINT")
(cons 10 (apply 'getMidPoint (getExtents ent)))
)
)
)
(princ)
)
(defun c:test2 (/ ss i lst pt)
(and
(setq ss (ssget))
(repeat (setq i (sslength ss))
(setq lst (cons (ssname ss (setq i (1- i))) lst))
)
(entmake
(list (cons 0 "POINT") (cons 10 (apply 'getMidPoint (getMExtents lst))))
)
)
(princ)
)