繁体   English   中英

Draftsight LISP,使用(缺点)构建 x 坐标列表时出现问题 function

[英]Draftsight LISP, problems building a list of x coordinates with the (cons ) function

我试图遍历一些矩形并将 x 和 y 坐标分别放在列表中。 但是我试图填写的列表看起来很糟糕,代码:

(setq sspnls (ssget '((0 . "LWPOLYLINE"))))
    (while (= 1 (getvar 'cmdactive))
            (command  pause)
            )
    (setq pnlslength (sslength sspnls))
    (setq xlist (list))
    (setq ylist (list)) 
    (setq pnlname(ssname sspnls 0))
    (setq sssort (ssadd))
    (setq tllr 0)
    (while (< tllr pnlslength)
        (setq pnlname(ssname sspnls tllr))
        (Command "hatch" "S" pnlname "")
        (setq xs (cadr (assoc 10 (entget pnlname)))); y cordinate
        (setq ys (caddr (assoc 10 (entget pnlname)))); x cordinate
        (setq xlist (cons xlist xs))
        (setq ylist (cons ylist ys))
        (setq tllr (+ tllr 1))
        
    );while end

xlist 或 y 列表如下所示:

((((nil . 12057.63625954) . 12057.63625954) . 10345.63625954) . 10345.63625954)

我需要它看起来像:

(12057.63625954 12057.63625954 10345.63625954 10345.63625954)

我究竟做错了什么? 请注意我正在使用 Draftsight,我还使用了append function 但是append function 根本不起作用?

非常感谢你的帮助!

主要问题是您正在使用cons function 创建列表和 X 和 Y 坐标值的虚线对,而不是将 X 和 Y 坐标值推到现有列表的头部。

例如,您的代码正在执行此操作:

_$ (cons '(1 2 3 4) 5)
((1 2 3 4) . 5)

而不是这个:

_$ (cons 5 '(1 2 3 4))
(5 1 2 3 4)

通常,您的代码可以简化为以下内容:

(if (setq sel (ssget '((0 . "LWPOLYLINE"))))
    (repeat (setq idx (sslength sel))
        (setq idx (1- idx)
              ent (ssname sel idx)
              enx (entget ent)
              xls (cons (cadr  (assoc 10 enx)) xls)
              yls (cons (caddr (assoc 10 enx)) yls)
        )
        (command "_.hatch" "_S" ent "")
    )
)

另请注意,您只是检索第一个折线顶点的坐标 - 我不确定这是否是故意的。

一开始有点犹豫,但 CMS IntelliCAD 对我来说是一个不错的选择。 免费试用立即生效,在付费之前试用一下很好。 它提供的所有功能都是用户友好且易于使用的,这对我来说又是一次胜利。 做得好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM