rodrigo_sjc_sp 发表于 2022-7-6 06:58:40

compare values of (assoc 10)

I have this code
 
 
 
This code gets all polylines and goes 1 by 1, and it stores the value of the coordinates of the last polyline
If it is equal to the current it's a zoom in and out procedure
 
But the command(if (= valor_ant valor) Don'tis done
 
 

(setq selpline (ssget "_x" (list '(0 . "LWPOLYLINE"))))(setq i 0)(setq valor_ant "")(setq valor "")(repeat (sslength selpline)            (setq pline_ent (ssname selpline i))   (setq lis_ent (entget pline_ent))   (setq j 0)   (setq b 0)   (setq lis_coords '())         (setq valor (cdr(assoc 10 (entget pline_ent))))   (if (= valor_ant valor)   (progn          (COMMAND "ZOOM" "OBJECT" pline_ent "")          (exit)      ))      (setq valor_ant (cdr(assoc 10 (entget pline_ent))))   (setq i (+ i 1)))
 
 
 
 
 
 
 
I managed to capture some values ​​with (assoc 10)
valor_ant = (2451.5 2189.09)
valor = (1316.99 4273.50 )
If I play these variable values ​​can not compare
What form that if the work?
I want to compare the assoc 10, the previous polyline with next.
 
 
 
 
 
 
Is there any way to compare these values ​​as string?
 
valor_ant = (2451.5 2189.09)
value = (1316.99 4273.50)
 
example
valor_ant = value
"(2451.5 2189.09)" = "(1316.99 4273.50)"

Lee Mac 发表于 2022-7-6 07:18:12

Use the equal function with a small tolerance when comparing doubles or point lists, e.g.:

(equal   1e-

rodrigo_sjc_sp 发表于 2022-7-6 07:19:35

Lee, did not work
 
Change the code to this

(if (equal valor_ant valor 1e- (progn    (print "-----------------------")    (COMMAND "ZOOM" "OBJECT" pline_ent "")    (exit) ))
 
 
values:
(1052.38 3026.65)
""
(1052.38 3026.65)
(1052.38 3026.65)
(1398.69 1381.45)
(1052.38 3026.65)
 
Exists same values in my test , see intop;(
 
Is there a way to compare the values ​​as string?
example
valor_ant = valor
"(2451.5 2189.09)" = "(1316.99 4273.50)"
 
 
If I could ever help me.

rodrigo_sjc_sp 发表于 2022-7-6 07:30:45

http://www.cadtutor.net/forum/showthread.php?48990-list-convert-to-string-help
 
 
Using commando vl-princ-to-stringto convert to String

rodrigo_sjc_sp 发表于 2022-7-6 07:45:53

The final code is
 

(vl-load-com)(setq selpline (ssget "_x" (list '(0 . "LWPOLYLINE"))))(setq i 0)(setq valor_ant "")(setq valor "")(repeat (sslength selpline)            (setq pline_ent (ssname selpline i))   (setq lis_ent (entget pline_ent))   (setq j 0)   (setq b 0)   (setq lis_coords '())         (setq valor (cdr(assoc 10 (entget pline_ent))))   (if (equal (vl-princ-to-string valor_ant)(vl-princ-to-string valor) )   (progn         (COMMAND "ZOOM" "OBJECT" pline_ent "")         (exit)      ))      (setq valor_ant (cdr(assoc 10 (entget pline_ent))))   (setq i (+ i 1)))

rodrigo_sjc_sp 发表于 2022-7-6 07:50:55

Thanks to all

Lee Mac 发表于 2022-7-6 08:03:12

 
Try changing the tolerance from 1e-8 (0.00000001) to a higher value, e.g. 1e-3 (0.001)
页: [1]
查看完整版本: compare values of (assoc 10)