TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: velasquez on May 13, 2011, 06:16:22 PM

Title: The pick point returned by entsel
Post by: velasquez on May 13, 2011, 06:16:22 PM
"The pick point returned by entsel does not represent a point that lies on the selected object. The point returned is the location of the crosshairs at the time of selection. The relationship between the pick point and the object will vary depending on the size of the pickbox and the current zoom scale."

How to convert this point to get on the selected entity?
Eg. I will always select a block.

Thanks


Title: Re: The pick point returned by entsel
Post by: Lee Mac on May 13, 2011, 06:19:52 PM
If you need a point on the entity, perhaps use vlax-curve-getclosestpointto

Lee

Title: Re: The pick point returned by entsel
Post by: CAB on May 13, 2011, 06:41:55 PM
What he said.
Code: [Select]
;;  CAB 07/29/06
;;  Get an entity with the point on the object.
(defun c:myentsel (/ ent obj pt)
  (vl-load-com)
  (if (setq ent (entsel "\nSelect entity: "))
    (list (car ent)
          (trans (vlax-curve-getclosestpointto (car ent) (trans (cadr ent) 1 0)) 0 1)
    )
  )
)
Title: Re: The pick point returned by entsel
Post by: CAB on May 13, 2011, 06:50:55 PM
Don't forget osnap.
Code: [Select]
(setq lst (entsel "\nPick me."))
(setq p (osnap (cadr lst) "nea"))
Title: Re: The pick point returned by entsel
Post by: alanjt on May 13, 2011, 07:26:25 PM
or vlax-curve-getClosestPointToProjection
Man that was a lot to type. (http://www.theswamp.org/lilly_pond/alanjt/whew.gif)
Title: Re: The pick point returned by entsel
Post by: gile on May 14, 2011, 03:24:57 AM
vlax-curve-getClosestPointTo will work while the current view plane is parallel to the selected object plane.

osnap and vlax-curve-getClosestPointToProjection would work whatever the view direction, but...

... we noticed some strange behaviors with polylines (according to the polyline type).

Code: [Select]
(setq ent (entsel))
These two expressions would return the WCS coordinates of the picked point on the polyline:

Code: [Select]
(trans (osnap (cadr ent) "_nea") 1 0)
Code: [Select]
(vlax-curve-getClosestPointToProjection
  (car ent)
  (trans (cadr ent) 1 0)
  (mapcar '-
  (trans (getvar "VIEWDIR") 1 0)
  (trans '(0 0 0) 1 0)
  )
)

But, the first one may return wrong results with 'old style' 2d polylines and the second one wrong results with 3d polylines.
Both work with lwpolylines.
Title: Re: The pick point returned by entsel
Post by: Jeff H on May 14, 2011, 03:46:26 AM
I do not know enough about AuotLisp if this is a dumb question or not but would checking PLINETYPE help in getting correct result?
Title: Re: The pick point returned by entsel
Post by: CAB on May 14, 2011, 07:12:40 AM
Thanks for that information gile. 8-)
Title: Re: The pick point returned by entsel
Post by: velasquez on May 14, 2011, 07:47:57 AM
Thank you all for your help.

The bject of my selection will always be a block.
The option to use OSNAP "nea"is working well.