我正在与奥托利什斗争,我找不到我正在寻找的答案。
我有一个空的列表,我用点坐标填充它,并把它转换成字符串。所产生的列表如下:
(12.5484,7.6054,0.0000 17.0626,8.1782,0.0000 17.5642,10.7199,0.0000 12.0110,11.4716,0.0000)
是否有可能使列表填充垂直并具有类似于以下内容的输出:
(12.5484 7.6054 0.0000)
17.0626 8.1782,0.0000
17.5642,10.7199,0.0000
12.0110,11.4716,0.0000)
我使用的代码是:
(setq lst()) ;create empty list named lst
(while
(setq a (getpoint "\nTick the Point")) ;select points
(setq x (rtos(car a))) ;get as X the x of a point (as string)
(setq y (rtos(cadr a))) ;get as Y the y of a point (as string)
(setq z (rtos(caddr a))) ;get as Z the z of a point (as string)
(setq pnt (strcat x "," y ","z))
(setq lst (cons pnt lst)) ;start filling the empty list with the coordinates of the points
)发布于 2014-09-02 06:57:08
我认为您所面临的问题仅仅是打印存储在列表中的值。存储的值是绝对好的。
因此,我认为您应该将这些行添加到现有代码中(如果您想要输出,如上面所示):
如果你面临其他问题,请告诉我。顺便说一句:我也是个初学者
发布于 2017-12-05 18:02:22
(setq ptlist '())
(mapcar '(lambda (pt)
(strcat (rtos (car pt)) "," (rtos (cadr pt)) "," (rtos (caddr pt))))
(reverse (while (setq pttemp(getpoint "Your point:"))
(if pttemp (cons pttemp ptlist))
))
)mapcar表达式将返回从点转换的字符串列表。如果需要将此列表转换为字符串,请使用该函数(应用'strcat (字符串列表))。
发布于 2022-05-17 19:21:12
我同意戈文达对这个问题的回答。更改代码打印列表的方式可以向您展示您想要实现的目标。
如果您在理解列表方面遇到困难,那么下面的代码可以轻松地阅读列表是如何构建的。代码将打印嵌套列表或原始列表,具体取决于“返回变量”下未注释的列表。
;; Printing Results via Command Line
(defun C:PrintResults(/ lResults DataPoint)
;; Calling Function
(setq lResults (CreateList))
;; Printing List
(princ "\n \n")
(princ "List : ")(princ lResults)
(princ "\n \n")
;; Printing List Contents - New line per data point
(foreach DataPoint lResults
(princ DataPoint)(terpri)
);foreach
(princ)
);defun C:PrintResults
;; Original
(defun CreateList(/ NestedList MasterList lst a x y z)
(setq NestedList nil)
(setq MasterList nil)
(setq lst nil) ;create empty list named lst
(while
(setq a (getpoint "\nTick the Point")) ;select points
(terpri)
(setq x (rtos(car a))) ;get as X the x of a point (as string)
(setq y (rtos(cadr a))) ;get as Y the y of a point (as string)
(setq z (rtos(caddr a))) ;get as Z the z of a point (as string)
;; A nested list setup
(setq NestedList (list x y z))
(setq MasterList (append MasterList (list NestedList)))
(princ "List 1 : ")(princ MasterList)(terpri)
;; Original Setup
(setq pnt (strcat x "," y ","z))
(setq lst (cons pnt lst)) ;start filling the empty list with the coordinates of the points
(princ "List 2 : ")(princ lst)(terpri)
);while
;; Returned variable
;MasterList
(reverse lst); Making the first entry the first item in the list
);defun EmptyListhttps://stackoverflow.com/questions/23497055
复制相似问题