乐筑天下

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

[编程交流] 转换列表

[复制链接]
mit

13

主题

33

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 18:28:22 | 显示全部楼层 |阅读模式
大家好
云你能帮帮我吗?
我在转换以下列表坐标时遇到一些问题:
 
("102.614364152051,17.95733901085014,0" "102.6148784682264,17.95771822280192,0" "102.6142663942859,17.95835128371222,0" "102.6141224420007,17.95824935570436,0" "102.6137704879814,17.95798561968717,0" "102.614364152051,17.95733901085014,0")
 
我想转换为
 
((102.614364152051,17.95733901085014,0) (102.6148784682264,17.95771822280192,0) (102.6142663942859,17.95835128371222,0) (102.6141224420007,17.95824935570436,0) (102.6137704879814,17.95798561968717,0) (102.614364152051,17.95733901085014,0))
 

麻省理工学院
回复

使用道具 举报

20

主题

338

帖子

323

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-5 18:38:58 | 显示全部楼层
您可能需要考虑下载Dos_Lib。
 
http://wiki.mcneel.com/developer/doslib
 
免费下载。它包含一个名为“Dos\u strokens”的lisp函数
 
dos\u Strokens公司
将令牌字符串转换为列表。
 
 
--------------------------------------------------------------------------------
 
语法
(dos\u strokens字符串令牌[T])
 
参数
一串
 
一根绳子。
 
代币
 
解释为一组分隔符的字符串。
 
T
 
如果指定,结果与strtok C/C++运行时库函数兼容。
 
退换商品
字符串列表(如果成功)。
 
无错误。
 
实例
指挥:(dos_strtokens)“曲棍球是最好的。”" ")
 
(“曲棍球”是“最好的”)
 
 
命令:(dos\u strokens“一个字符串\tof,,令牌\n和一些其他令牌”“,\t\n”t)
 
(“token”和“some”“more”“token”的“string”)
 
 
命令:(dos\u strokens“0,0,,0,0”“))
 
("0" "0" "" "0" "0")
 
 
命令:(dos\u strokens“0,0,0”,“0,0”,“t)
 
("0" "0" "0" "0")
回复

使用道具 举报

55

主题

402

帖子

357

银币

后起之秀

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

铜币
274
发表于 2022-7-5 18:44:44 | 显示全部楼层
这是我的做法。。。
 
对于
((102.614 17.9573 0)
(102.615 17.9577 0)
(102.614 17.9584 0)
(102.614 17.9582 0)
(102.614 17.958 0)
(102.614 17.9573 0)
)
  1. (mapcar        '(lambda (x)
  2.    (read (strcat "("
  3.                  (vl-string-translate "," " " x)
  4.                  ")"
  5.          )
  6.    )
  7. )
  8. list
  9. )
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 18:50:13 | 显示全部楼层
另一个
  1. (setq lst (list "102.614364152051,17.95733901085014,0" "102.6148784682264,17.95771822280192,0" "102.6142663942859,17.95835128371222,0" "102.6141224420007,17.95824935570436,0" ))
  2. (setq num (length lst))
  3. (setq y num)
  4. (repeat num (setq newlst (cons (list (nth (setq y (- y 1)) lst )) newlst)))
回复

使用道具 举报

mit

13

主题

33

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 18:57:43 | 显示全部楼层
首先
谢谢Hippe013、satishrajdev和BIGAL
我对我的问题感到抱歉,它不清楚,而且它出了问题
 
我使用了Lee Mac的转换代码http://www.lee-mac.com/stringtolist.html
我的第一个清单是:
 
  1. (defun c:coordformat ()
  2. (setq coords   '("102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0"))
  3. ;and when I used this function
  4. (setq coords (LM:str->lst coords " "))   ;It was not convert to list coordinate format
  5. )
  6. (defun LM:str->lst ( str del / len lst pos )
  7.    (setq len (1+ (strlen del)))
  8.    (while (setq pos (vl-string-search del str))
  9.        (setq lst (cons (substr str 1 pos) lst)
  10.              str (substr str (+ pos len))
  11.        )
  12.    )
  13.    (reverse (cons str lst))
  14. )

 
当我使用这段代码时,它并没有将列表转换为坐标格式。它是:
 
("102.614364152051,17.95733901085014,0" "102.6148784682264,17.95771822280192,0" "102.6142663942859,17.95835128371222,0" "102.6141224420007,17.95824935570436,0" "102.6137704879814,17.95798561968717,0" "102.614364152051,17.95733901085014,0")
 
坐标列表格式应为:
 
((102.614364152051 17.95733901085014 0) (102.6148784682264 17.95771822280192 0) (102.6142663942859 17.95835128371222 0) (102.6141224420007 17.95824935570436 0) (102.6137704879814 17.95798561968717 0) (102.614364152051 17.95733901085014 0))
 
或者应该是:
 
((102.614364152051 17.95733901085014) (102.6148784682264 17.95771822280192) (102.6142663942859 17.95835128371222) (102.6141224420007 17.95824935570436) (102.6137704879814 17.95798561968717) (102.614364152051 17.95733901085014))
 
如果你还有别的事
请帮帮我
 
麻省理工学院
回复

使用道具 举报

55

主题

402

帖子

357

银币

后起之秀

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

铜币
274
发表于 2022-7-5 19:07:15 | 显示全部楼层
 
为此,请阅读我的帖子。。。但小数有变化。我不知道原因。明天会设法解决的
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:12:55 | 显示全部楼层
由于您的数据已经是文字字符串格式,我将遵循与上面文章中Satish相同的方法,使用读取表达式将值转换为AutoLISP数据类型,例如:
  1. _$ ([color=BLUE]setq[/color] coords [color=MAROON]"102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0"[/color])
  2. [color=MAROON]"102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0"[/color]
  3. _$ ([color=BLUE]while[/color] ([color=BLUE]/=[/color] coords ([color=BLUE]setq[/color] coords ([color=BLUE]vl-string-subst[/color] [color=MAROON]")("[/color] [color=MAROON]" "[/color] coords))))
  4. [color=BLUE]nil[/color]
  5. _$ ([color=BLUE]read[/color] ([color=BLUE]strcat[/color] [color=MAROON]"(("[/color] ([color=BLUE]vl-string-translate[/color] [color=MAROON]","[/color] [color=MAROON]" "[/color] coords) [color=MAROON]"))"[/color]))
  6. ((102.614 17.9573 0) (102.615 17.9577 0) (102.614 17.9584 0) (102.614 17.9582 0) (102.614 17.958 0) (102.614 17.9573 0))

请注意,控制台的输出不会丢失精度-坐标值仍以最高可用精度存储在内存中,但是,为了可读性,打印的值会被截断。
回复

使用道具 举报

mit

13

主题

33

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-5 19:18:20 | 显示全部楼层
呼!很抱歉误码了
代码应与Lee Mac相同:
 
  1. (defun c:coordformat ()
  2. (setq coords "102.614364152051,17.95733901085014,0 102.6148784682264,17.95771822280192,0 102.6142663942859,17.95835128371222,0 102.6141224420007,17.95824935570436,0 102.6137704879814,17.95798561968717,0 102.614364152051,17.95733901085014,0)
  3. ;and when I used this function
  4. (setq coords (LM:str->lst coords " "))   ;It was not convert to list coordinate format
  5. )
  6. (defun LM:str->lst ( str del / len lst pos )
  7.    (setq len (1+ (strlen del)))
  8.    (while (setq pos (vl-string-search del str))
  9.        (setq lst (cons (substr str 1 pos) lst)
  10.              str (substr str (+ pos len))
  11.        )
  12.    )
  13.    (reverse (cons str lst))
  14. )

 
 
非常感谢satishrajdev
 
谢谢你两次给李·麦克
回复

使用道具 举报

55

主题

402

帖子

357

银币

后起之秀

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

铜币
274
发表于 2022-7-5 19:26:13 | 显示全部楼层
 
著名的
 
欢迎:)
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 19:31:10 | 显示全部楼层
 
请注意,我的LM:str->lst函数的执行完全如所述:使用给定的分隔符将字符串分隔为项目列表,例如:
  1. _$ (LM:str->lst "1,2,3 4,5,6 7,8,9" " ")
  2. ("1,2,3" "4,5,6" "7,8,9")

然而,上述格式不是AutoLISP解释器识别为三维点列表的格式-点列表必须是2或3个数值的列表,而上述只是字符串列表。
 
为了将来的参考,如果您能保留我网站上发布的函数附带的代码头,我将不胜感激。
 
 
不客气
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 19:59 , Processed in 0.563927 second(s), 72 queries .

© 2020-2025 乐筑天下

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