Hi,
(car (nentsel)) or (car (nentselp)) returns the ename of the entity in the block definition, not in the block reference (insert).
Here's a way, which:
- copies the the nested entity from the bloc definition to the model space,
- transforms it with the nentselp transformation matrix (the reference have to be uniformly scaled),
- get the closest point,
- delete the entity copy.
;; GetClosestPointToNestedCurve
;; Returns the closest point to a nested curve (WCS coordinates)
;;
;; Arguments
;; nent = a list as returned by nentselp
;; pt =: a point (WCS coordinates)
(defun GetClosestPointToNestedCurve (nent pt / closestPoint)
(setq tmp
(car
(vlax-invoke
*acdoc*
'CopyObjects
(list (vlax-ename->vla-object (car nent)))
(vla-get-ModelSpace *acdoc*)
)
)
)
(vla-TransformBy tmp (vlax-tmatrix (caddr nent)))
(setq closestPoint
(vlax-curve-getClosestPointTo tmp pt)
)
(vla-Delete tmp)
closestPoint
)
;; Tesing function
(defun c:test (/ pt nent closest)
(vl-load-com)
(or *acdoc*
(setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
)
(if
(and
(setq pt (getpoint "\nSpecify a point: "))
(setq nent (nentselp "\nSelect nested entity: "))
(vlax-curve-getendParam (car nent))
)
(progn
(setq closest
(GetClosestPointToNestedCurve nent (trans pt 1 0))
)
(vla-addCircle
(vla-get-ModelSpace *acdoc*)
(vlax-3d-point closest)
1.0
)
)
)
(princ)
)