乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 17|回复: 6

[编程交流] compare values of (assoc 10)

[复制链接]

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-6 06:58:40 | 显示全部楼层 |阅读模式
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't  is done
 
 
  1. (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)"
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:18:12 | 显示全部楼层
Use the equal function with a small tolerance when comparing doubles or point lists, e.g.:
  1. (equal   1e-
回复

使用道具 举报

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-6 07:19:35 | 显示全部楼层
Lee, did not work
 
Change the code to this
  1. (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 in  top  ;(
 
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.
回复

使用道具 举报

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-6 07:30:45 | 显示全部楼层
http://www.cadtutor.net/forum/showthread.php?48990-list-convert-to-string-help
 
 
Using commando vl-princ-to-string  to convert to String
回复

使用道具 举报

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-6 07:45:53 | 显示全部楼层
The final code is
 
  1. (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)))
回复

使用道具 举报

57

主题

183

帖子

126

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
285
发表于 2022-7-6 07:50:55 | 显示全部楼层
Thanks to all
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 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)
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-1 10:48 , Processed in 0.896441 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表