TheyCallMeJohn 发表于 2022-7-5 23:40:03

将三维点附加到列表

我尝试了几个组合,浏览了大约100篇帖子,但我不知道我做错了什么。
 
我正在过滤对象并从数据库中提取三维坐标。然后我将其转化为一个3点列表(x y z)。然后,我想创建这些点的列表,并将其添加到现有列表中,因为程序会过滤选择集中的其余对象。
 

(progn
(setq unitpoint_orig (vl-string-right-trim ";" (substr (vlax-get entvla 'points) 12)))                       
(if (and(or (= Z_pref "Y")(= Z_pref "y"))(/= Z_height nil))
        (progn
                (setq unitpoint_mod (comma_pull unitpoint_orig "REAL_NUM"))
                (setq unitpoint (list (car unitpoint_mod) (cadr unitpoint_mod) (caddr Z_height)))
        )
        (setq unitpoint (comma_pull unitpoint_orig "REAL_NUM"))
)
(setq unitpoint_lst (append unitpoint_lst 'unitpoint))

;(command "insert" pl_block unitpoint "1" "1" "0")
)

 
当前结果:(105.13 3165.22 0.0 105.13 3194.65 0.0 105.13 3142.5 0.0)
 
期望结果:((105.13 3165.22 0.0)(105.13 3194.65 0.0)(105.13 3142.5 0.0))
 
一旦这部分开始工作,我就计划使用李-麦克的子程序过滤重复项。然后根据这些点插入。

ymg3 发表于 2022-7-5 23:50:36

他们叫我约翰。
 
你可以在清单上使用这个小程序。
 

(defun tupl3 (l) (if l (cons (list (car l) (cadr l) (caddr l))(tupl3 (cdddr l)))))

 
例如:

(tupl3 '(105.13 3165.22 0.0 105.13 3194.65 0.0 105.13 3142.5 0.0))

((105.13 3165.22 0.0) (105.13 3194.65 0.0) (105.13 3142.5 0.0))
_$

 
或者改变
 

(setq unitpoint_lst (append unitpoint_lst 'unitpoint))

to

(setq unitpoint_lst (append unitpoint_lst (list unitpoint)))

TheyCallMeJohn 发表于 2022-7-6 00:04:31

正是我需要的。。。(我发誓我也厌倦了用“'”而不是“list”,但我想我犯了一个错误,
 

David Bethel 发表于 2022-7-6 00:07:26

小列表没什么大不了的,但是(cons)比(append)快很多。
 
你基本上(cons-pt-list),然后如果列表的顺序很重要(反向lst)
 
如果你使用30000个原子,它会产生很大的不同-大卫
 
-大卫

ymg3 发表于 2022-7-6 00:16:07

他们叫我约翰,
 
大卫说得很对,我倾向于远离他。
 
在您的情况下,您可以简单地:

(setq unitpoint_lst (cons unitpoint unitpoint_lst))

; and if necessary at the end :

(setq unitpoint_lst (reverse unitpoint_lst))

 
此外,不完全必要,但我通常会设置列表
在开始建造之前将其设置为零。这是特别的
在调试阶段非常有用
您尚未声明变量,并且
运行测试。
 
ymg公司

TheyCallMeJohn 发表于 2022-7-6 00:23:50

 
 
David和Ymg,
谢谢你的建议。我会试试看是否可行。我也把它设置为nil,我只是把它放在defun下,这样当我调试完代码后,就可以更容易地使必要的变量成为局部变量。
 
 
更新:
所以它试着替换这个:
(setq unitpoint_lst (cons unitpoint_lst (list unitpoint)))
 
为此:
(setq unitpoint_lst (append unitpoint_lst (list unitpoint)))
 
但它不起作用,还有什么我需要改变的吗?

ymg3 发表于 2022-7-6 00:33:03

他们叫我约翰,
 
下面是一个使用Gilles Chanteau的解析例程的小示例。
我已经设置了一个要分析的字符串的虚拟列表:
 

(defun test ()
(setq datalist '(";;;1.0, 2.0, 3.0,       weerertttretqrt"";;;4.0, 5.0, 6.0,       weerertttretqrt"    ";;;7.0, 8.0,9.0,       weerertttretqrt"))
(setq parsedlist nil)
(foreach item datalist
      (setq parsedlist (cons (str2lst (vl-string-left-trim ";" item) ",") parsedlist))
)
(setq coordlist nil)
(foreach str parsedlist
      (setq coordlist (cons (list (atof (car str)) (atof (cadr str)) (atof (caddr str))) coordlist))
)

(princ)
)      


;; str2lst   by Gilles Chanteau                                             ;
;; Transform a string with separator into a list of strings.                  ;
;;                                                                            ;
;; Arguments:                                                               ;
;; str : string of characters                                                 ;
;; sep : separator characters                                                 ;

(defun str2lst (str sep / len lst)
(setq len (strlen sep))
(while (setq pos (vl-string-search sep str))
   (setq lst (cons (substr str 1 pos) lst)
str (substr str (+ len pos 1))
   )
)
(reverse (cons (substr str 1 pos) lst))
)         

 
下面是跑步后的reult:
 

_$ (test)
_$ parsedlist
(("7.0" " 8.0" "9.0" "       weerertttretqrt") ("4.0" " 5.0" " 6.0" "       weerertttretqrt") ("1.0" " 2.0" " 3.0" "       weerertttretqrt"))
_$ coordlist
((1.0 2.0 3.0) (4.0 5.0 6.0) (7.0 8.0 9.0))
_$

 
正如您在完成第一个foreach循环时所看到的,您的结果是
第一个位置的最后一项。
 
现在,我们运行另一个foreach循环来遍历坐标列表,结果是
列表顺序正确。
 
假设我们不必进行第二个循环,但您仍然希望您的列表处于正确的位置
顺序您将发布(反向列表)。
 
我们告诉你使用cons的唯一原因是它比append快十倍
特别是在长名单上。在你的情况下,你不必这样做,但它仍然是你需要的
我想知道。
 
现在,如果您发布由(vlax get entvla’points)返回的典型数据行,
也许我们可以提出建议,让你的任务更容易。
 
ymg公司

ymg3 发表于 2022-7-6 00:40:29

他们叫我约翰,
 
在回答帖子#6时,你需要的是:
 
(setq unitpoint_lst (cons unitpointunitpoint_list))
 
ymg公司
页: [1]
查看完整版本: 将三维点附加到列表