TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: vincent.r on June 26, 2020, 05:23:41 AM

Title: Coordinate based selection
Post by: vincent.r on June 26, 2020, 05:23:41 AM
Hi,

I trying to select a line based on given coordinates. Took help from Lee's website and modified code as -

(ssget '((0 . "LINE") (-4 . "=,=,=") (11 13.0767 17.0213 0.0)))

but not able get to select line. Don't know where am I mistaking. Drawing attached.

Tried this also -

(setq pt1 (list 13.0767 17.0213 0.0))
(SETQ A (ssget pt1 '((0 . "LINE") )))

Any help will be highly appreciable.

Thanks
Title: Re: Coordinate based selection
Post by: ribarm on June 26, 2020, 07:25:17 AM
Coordinates of each point in ACAD are stored as real numbers with precision up to 15 decimal places... So to get LINE, you must specify exact coordinates with all decimals and I suggest that you use this variant :

Code: [Select]
(ssget "_C" pt pt '((0 . "LINE")))

Note you can get pt with exact coordinates by : (setq pt (cdr (assoc 11 (entget (car (entsel "\nPick LINE..."))))))

Now to check precision : (prompt "\nPOINT : ") (princ (rtos (car pt) 2 20)) (prompt ",") (princ (rtos (cadr pt) 2 20)) (prompt ",") (princ (rtos (caddr pt) 2 20))
If you have(get) those data with precision up to 15 decimal places, you can try :

Code: [Select]
(ssget (list '(0 . "LINE") '(-4 . "=,=,=") '(11 Xcoord Ycoord Zcoord)))
Title: Re: Coordinate based selection
Post by: vincent.r on June 26, 2020, 07:46:35 AM
Coordinates of each point in ACAD are stored as real numbers with precision up to 15 decimal places... So to get LINE, you must specify exact coordinates with all decimals and I suggest that you use this variant :

Code: [Select]
(ssget "_C" pt pt '((0 . "LINE")))

Note you can get pt with exact coordinates by : (setq pt (cdr (assoc 11 (entget (car (entsel "\nPick LINE..."))))))

Now to check precision : (prompt "\nPOINT : ") (princ (rtos (car pt) 2 20)) (prompt ",") (princ (rtos (cadr pt) 2 20)) (prompt ",") (princ (rtos (caddr pt) 2 20))
If you have(get) those data with precision up to 15 decimal places, you can try :

Code: [Select]
(ssget (list '(0 . "LINE") '(-4 . "=,=,=") '(11 Xcoord Ycoord Zcoord)))


It works ribarm! I was not aware of precision system.

Thank you very much. You made my day.

Cheers.
Title: Re: Coordinate based selection
Post by: Lee Mac on June 26, 2020, 01:13:10 PM
An easier way to perform the selection, without needing to specify the coordinate values to the exact limit of double-floating-point precision is to use some tolerance around the values, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (setq p '(13.0767 17.0213 0.0) ;; Approximate point
  2.       f  1e-4 ;; Tolerance
  3. )
  4.     (list
  5.        '(0 . "LINE")
  6.        '(-4 . ">=,>=,>=")
  7.         (cons 11 (mapcar '- p (list f f f)))
  8.        '(-4 . "<=,<=,<=")
  9.         (cons 11 (mapcar '+ p (list f f f)))
  10.     )
  11. )
Title: Re: Coordinate based selection
Post by: vincent.r on July 14, 2020, 03:08:17 AM
Thanks Lee !