zilong136 发表于 2024-3-13 01:32:48

关于矩形阵列的问题?

本帖最后由 zilong136 于 2024-3-13 03:45 编辑


[*]以下两个代码都存在列间距错误的问题,要求列间距是相领两列之间的距离,求大佬帮忙解决一下。
[*](defun c:qw1 ()
[*](defun a( / P)
[*]    (initget "Y N")
[*]    (setq P (getkword "是否关联?[是(Y)/否(N)]<Y>:"))
[*]    (if (= P nil) (setq P "Y"))
[*]    P
[*])
[*](command "arrayrect" (ssget) "" "col" (getint "\n列数:") (getdist "\n每列间距:") "r" (getint "\n行数:") (getdist "\n每行间距:") 0 "AS" (a) "")
[*]) ;;;1.矩形阵列【qw1】
[*]
[*]
[*](defun c:qw2 (/ n)
[*](command "arrayrect"(ssget) "" "as" (cond ((initget "Y N"))((getkword "是否关联?[是(Y)/否(N)]<Y>:"))("Y")) "col" (setq n (getint "\n列数:")) (* n (getdist "\n列数间距:"))   "r" (getint "\n行数:") (getdist "\n行数间距:") """")
[*])

ssyfeng 发表于 2024-3-13 08:56:24

用command函数首先要对CAD命令执行顺序了解清楚,不同版本CAD命令操作可能有区别,这种自己尝试多几次应该就可以了。我CAD2012没有那个col的关键字

ssyfeng 发表于 2024-3-13 09:49:03

本帖最后由 ssyfeng 于 2024-3-13 09:57 编辑

找了个CAD2022看了一下,lisp执行那个命令时操作顺序跟手动操作顺序不一样。
这个试试:
(defun c:qw1 ()
(defun a( / P)
    (initget "Y N")
    (setq P (getkword "是否关联?[是(Y)/否(N)]<Y>:"))
    (if (= P nil) (setq P "Y"))
    P
)
(command "arrayrect" (ssget) "" "c" (getint "\n行数:") (getint "\n列数:") "s" (getdist "\n每行间距:") (getdist "\n每列间距:") "AS" (a) "")
)

zilong136 发表于 2024-3-13 09:55:23

ssyfeng 发表于 2024-3-13 08:56
用command函数首先要对CAD命令执行顺序了解清楚,不同版本CAD命令操作可能有区别,这种自己尝试多几次应该 ...我2022CAD跟2024CAD都是同样问题:
两个代码就是列间距有问题,第一个默认是首尾列间距,第二个是相领列间距,但计算时又是首尾列间距/(列数-1),搞不懂它的机制,我就想要相领两列间距。有这么难吗?

ssyfeng 发表于 2024-3-13 09:58:19

这种其实就是看命令行提示就可以了,看着来修改就行了

zilong136 发表于 2024-3-13 10:12:12

ssyfeng 发表于 2024-3-13 09:49
找了个CAD2022看了一下,lisp执行那个命令时操作顺序跟手动操作顺序不一样。
这个试试:

2022CAD有个问题,就是这关联始终是关联的,不管是选Y或是N,其它的正常,2024CAD正常。

ssyfeng 发表于 2024-3-13 10:18:35

本帖最后由 ssyfeng 于 2024-3-13 10:46 编辑

那个函数写的有问题,或者直接不要那个a函数

(defun c:qw1 (/ a)
(defun a( / P)
    (initget "Y N")
    (setq P (getkword "是否关联?[是(Y)/否(N)]<Y>:"))
    (if (or (equal p "Y") (= P nil)) (setq P "Y") (setq p "N"))
)
(command "arrayrect" (ssget) "" "c" (getint "\n行数:") (getint "\n列数:") "s" (getdist "\n每行间距:") (getdist "\n每列间距:") "AS" (a) "")
(princ)
)
(defun c:qw1 ()
(command "arrayrect" (ssget) "" "c" (getint "\n行数:") (getint "\n列数:") "s" (getdist "\n每行间距:") (getdist "\n每列间距:") "AS")
(princ)
)

zilong136 发表于 2024-3-13 10:44:31

本帖最后由 zilong136 于 2024-3-13 11:21 编辑

ssyfeng 发表于 2024-3-13 10:18
那个函数写的有问题,或者直接不要那个a函数
下面那个函数怎么改?
页: [1]
查看完整版本: 关于矩形阵列的问题?