Jump to content

Entsel returns wrong pick point


meinfilel

Recommended Posts

Hello everyone, I was trying some things and found this little problem: to exhibit the wrong behavior I create one line and one polyline that spans from a point and to a direction perpendicular to the X axis so I can easily check if the point returned by entsel is on the line (I upload a simple dwg containing these entities). I check the output of (cadr (entsel)); while the second coordinate of the point should have been exactly 14.0 results vary from 13.95 to 14.05. Why is this happening? Doesn't (entsel) shouldn't returns points that are *on* the entity and not just very close?

 

Thanks in advance.cadtut_entsel.dwg

cadtut_entsel.dwg

Link to comment
Share on other sites

From AutoCAD help https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-9D4CF74D-8B8B-4D66-A952-564AFBA254E7

entsel (AutoLISP)

Prompts the user to select a single object (entity) by specifying a point

Supported Platforms: Windows and Mac OS

Signature

(entsel [msg])

msg

Type: String

A prompt string to be displayed to users. If omitted, entsel prompts with the message, "Select object."

Return Values

Type: List or nil

A list whose first element is the entity name of the chosen object and whose second element is the coordinates (in terms of the current UCS) of the point used to pick the object.

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.

 

You could check the distance between endpoints or vertices of the object you select and that pick point to find the point you want.

 

Example: 

;| Change the Length of a Line|;
; BY: Tom Beauford
; BeaufordT@LeonCountyFL.gov
; Leon County Public Works Engineering
;(or C:chl (load "ChgLen.lsp"));chl
; (load "ChgLen.lsp") chl
;=======================================================
(defun C:chl (/ ActDoc A pick B etype pt1 pt pt2 pt3 pt4 distold dist1 ang1 z1)
  (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
  (vla-StartUndoMark ActDoc)
  (setq A (entsel "\nSelect Entity: ")
     pick (osnap (cadr A) "endp")
        B (entget (car A))
    etype (cdr(assoc 0 B))
  ); setq
  (princ "\netype = ")
  (princ etype)
  (cond
    ((eq etype "LINE")
      (progn
        (setq pt1 (cdr (assoc 10 B)) pt2 (cdr (assoc 11 B)))
        (if (>(distance pt1 pick)(distance pick pt2))
         (setq pt pt1 pt1 pt2 pt2 pt)
        )
        (setq pt3 (list (car pt1)(cadr pt1)) pt4 (list (car pt2)(cadr pt2))
                  distold (distance pt3 pt4)
                  ang1 (angle pt2 pt1)
        )
        (princ "\nOld Distance=")
        (princ distold)
        (initget "Lengthen Shorten Total Elevation Percent Ratio")
        (if(= ¦¦global¦¦ nil)(setq ¦¦global¦¦ "Total"))
        (if(setq ¦¦notnil¦¦ (getkword (strcat " [Lengthen/Shorten/Total/Elevation/Percent/Ratio] <" ¦¦global¦¦ ">: ")))(setq ¦¦global¦¦ ¦¦notnil¦¦))
        (setvar "cmdecho" 0)

    (cond
      ((= ¦¦global¦¦ "Lengthen")
        (setq dist1 (+ distold (getreal "\nEnter Distance: "))
                  z1 (+(caddr pt2)(*(/ dist1 distold)(-(caddr pt1)(caddr pt2))))
        )
      ); Lengthen
      ((= ¦¦global¦¦ "Shorten")
        (setq dist1 (- distold (getreal "\nEnter Distance: "))
                  z1 (+(caddr pt2)(*(/ dist1 distold)(-(caddr pt1)(caddr pt2))))
        )
      ); Shorten
      ((= ¦¦global¦¦ "Total")
        (setq dist1 (getreal "\nEnter New Length: ")
                  z1 (+(caddr pt2)(*(/ dist1 distold)(-(caddr pt1)(caddr pt2))))
        )
      ); Total
      ((= ¦¦global¦¦ "Elevation")
        (setq z1 (getreal "\nEnter Elevation to Trim/Extend: ")
                  dist1 (*(/ distold (-(caddr pt1)(caddr pt2)))(- z1 (caddr pt2)))
          )
      ); Elevation
      ((= ¦¦global¦¦ "Percent")
        (setq z1 (+(caddr pt2)(* distold(getreal "\nEnter Slope in %: ")0.01))
                  dist1 distold
        )
      ); Percent
      ((= ¦¦global¦¦ "Ratio")
        (setq z1 (+(caddr pt2)(/ distold(getreal "\nEnter Run/Rise: ")))
                  dist1 distold
        )
      ); Ratio
    ); cond

        (setq pt1 (polar pt2 ang1 dist1)
                  pt1 (list (car pt1)(cadr pt1) z1)
        )
        (if pt (setq pt pt1 pt1 pt2 pt2 pt))
        (setq B (subst(cons 10 pt1)(assoc 10 B) B)
              B (subst(cons 11 pt2)(assoc 11 B) B)
        )
        (entmod B)
        (princ "\nOld Distance=")
        (princ distold)
        (princ ", New Distance=")
        (princ dist1)
      ); progn
    ); line
    ((or(eq etype "ARC")(eq etype "POLYLINE")(eq etype "LWPOLYLINE"))
      (progn
        (command "lengthen" pick)
      ); progn
    ); ARC, POLYLINE or LWPOLYLINE
  ); cond
  (vla-EndUndoMark ActDoc)
  (princ)
)

 

Link to comment
Share on other sites

Thanks!

 

So it turns out I have misunterstood the return of the command.

I think I'm going to be able to use this small subfunction to achieve my goal.

 

(defun onpoint ( / data pt name )
(vl-load-com)

;returns the point *ON* curve

(setq data (entsel)
      pt (cadr data)
      name (car data))

(vlax-curve-getclosestpointto (vlax-ename->vla-object name) pt)

)	;defun ONpoint

 

Link to comment
Share on other sites

Without bothering with vla-vlax functions, you can also use this:

(setq sel (entsel "\nSelect entity: ")
      P1 (osnap (cadr sel) "_nea")
)

 

If you also want the name of the entity:

(setq ent (car sel))

 

Edited by confutatis
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...