Gizmo Coordinates

Gizmo Coordinates

saitoib
Advocate Advocate
500 Views
4 Replies
Message 1 of 5

Gizmo Coordinates

saitoib
Advocate
Advocate
Hi all.
 
When I select an object with the display style set to 3D, a gizmo appears at the center point.
Is it possible to get the coordinate values of this gizmo in Lisp?
 
Thank you.
Saitoib
0 Likes
Accepted solutions (1)
501 Views
4 Replies
Replies (4)
Message 2 of 5

Sea-Haven
Mentor
Mentor

Getpoint should return XYZ need correct setting of osnaps including 3d.

0 Likes
Message 3 of 5

_gile
Consultant
Consultant
Accepted solution

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)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 5

saitoib
Advocate
Advocate

@_gile 

 

This is awesome!
It is possible to get even the z-axis of the selected area.
Thank you very much.

Saitoib
0 Likes
Message 5 of 5

_gile
Consultant
Consultant

@saitoib  a écrit :

It is possible to get even the z-axis of the selected area.


I'am not sure to undertand what you mean. The 'BoundingBox' is always aligned to the WCS axis.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes