Results 1 to 3 of 3

Thread: entsel point

  1. #1
    Member
    Join Date
    2013-03
    Posts
    38
    Login to Give a bone
    0

    Default entsel point

    Hi all,
    I have below a simple instructions to get the perpendicular distance from a LINE/XLINE to a point. The user selects the line or xline and I use the "selection point" from entsel in the calculations in the program. The problem is, the program works great whenever I use a "snap" like "near" or "endpoint" when using entsel. If I just select the entity (line or xline) the number I get is slightly off. Any suggestions?

    Thanks

    PS
    I'm sure there is a much fancier/simpler way of doing what I'm doing but this is what I got

    Code:
    (defun *error* (msg)
      (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
          (princ (strcat "\n; error: " msg))
      )
    )
    
    
    (setq ent (entsel))
    (setq entPt (cadr ent))
    (setq entDef (entget (car ent)))
    (setq ent (car ent))
    ;check ent is line or xline
    (cond
      (
       (or (= (cdr (assoc 0 entDef)) "LINE")
           (= (cdr (assoc 0 entDef)) "XLINE")
       )
       (setq lPt1 (cdr (assoc 10 entDef))
         lPt2 (cdr (assoc 11 entDef))
       )
       (if (= (cdr (assoc 0 entDef)) "XLINE")
         (setq beta (angle lPt1 (mapcar '+ lPt1 lPt2)))
         (setq beta (angle lPt1 lPt2))
       )
      )
    
    
      (T
       (princ "Entity must be 'XLINE' or 'LINE'")
       (exit)
      )
    )
    
    
    (setq toPt (getpoint "\nto point"))
    (setq L (distance toPt entPt))                
    (setq theta (angle entPt toPt))
    (setq alpha (- theta beta))
    (setq a (abs (* L (sin alpha))))
    
    
    (princ a) ; 'a' is perpendicular distance to point selected with 'entsel' and 'toPt'

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: entsel point

    Without complete code or a better description of what you're doing couldn't you simply snap to Perpendicular using 'DIST?

  3. #3
    Member
    Join Date
    2013-03
    Posts
    38
    Login to Give a bone
    0

    Default Re: entsel point

    Quote Originally Posted by Tom Beauford View Post
    Without complete code or a better description of what you're doing couldn't you simply snap to Perpendicular using 'DIST?
    That is something I'm going to try out. Thanks for the response. Also, the code below is what I ended up with (with the help of various CAD forums ). It does what I need.

    Code:
    (defun c:rsk (/	      ent     entPt   entDef  lPt1    lPt2    beta
    	      toPt    L	      theta   alpha   dist    offset  *error*
    	     )
      (defun *error* (msg)
        (or	(wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
    	(princ (strcat "\n; error: " msg))
        )
      )
    
      (setvar 'errno 0)
      (setq ent (entsel "\nFrom point:"))
      (while (= (getvar 'errno) 7)
        (setvar 'errno 0)
        (setq ent (entsel "\nSelect a point on a line or xline"))
      )
    
      (setq	entPt
    	 (osnap (cadr ent) "_nea")
      )
      (setq entDef (entget (car ent)))
      (setq ent (car ent))
      
    ;check ent is line or xline
      (cond
        (
         (or (= (cdr (assoc 0 entDef)) "LINE")
    	 (= (cdr (assoc 0 entDef)) "XLINE")
         )
         (setq lPt1	(cdr (assoc 10 entDef))
    	   lPt2	(cdr (assoc 11 entDef))
         )
         (if (= (cdr (assoc 0 entDef)) "XLINE")
           (setq beta (angle lPt1 (mapcar '+ lPt1 lPt2)))
           (setq beta (angle lPt1 lPt2))
         )
        )
    
        (T
         (princ "Entity must be 'XLINE' or 'LINE'")
         (exit)
        )
      )
    
      (setq toPt (getpoint "\nTo point:"))
      (setq L (abs (distance toPt entPt)))
      (setq theta (angle entPt toPt))
      (setq alpha (- theta beta))
      (setq dist (abs (* L (sin alpha))))
      (setq offset (getreal "\n\nEnter offset:\n"))
      (setq dist (+ dist offset))
      (setq dist (distof (rtos dist 5 4) 2)) ;rkmcswain - AUGI forum
      (command "_offset" dist ent toPt "")
    
    )

Similar Threads

  1. CV104-1P: One Point, Two Point, Red Point, Blue Point
    By Autodesk University in forum Civil Infrastructure
    Replies: 0
    Last Post: 2013-05-05, 03:17 AM
  2. CV12-4: One Point, Two Point, Red Point, Blue Point
    By Autodesk University in forum Civil Infrastructure
    Replies: 0
    Last Post: 2013-04-17, 04:50 AM
  3. Help with using entsel or nentselp
    By MWKINCAID1 in forum AutoLISP
    Replies: 3
    Last Post: 2007-03-10, 12:10 AM
  4. Point from entsel
    By wommack in forum AutoLISP
    Replies: 10
    Last Post: 2006-12-15, 06:01 PM
  5. Entsel
    By fletch97 in forum AutoLISP
    Replies: 3
    Last Post: 2005-07-07, 04:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •