多功能复制、移动、旋转
本帖最后由 baoxiaozhong 于 2019-9-3 12:17 编辑(defun c:cx ( / *error* c cmde s ang )
(defun *error* (msg)
(if c (setvar 'COPYMODE c))
(if cmde (setvar 'CMDECHO cmde))
(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
(princ (strcat "\n错误: " msg))
)
)
(if (setq cmde (getvar 'CMDECHO)) (setvar 'CMDECHO 0))
(if (setq c (getvar 'COPYMODE)) (setvar 'COPYMODE 1))
(defun do_C nil
(prompt "\n下一点:")
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.copy" s "" "_non" (getvar 'LASTPOINT) "_non" (getvar 'LASTPOINT))
(command "_.move" s "" "_non" (if llp (setq lp llp) (setq lp (getvar 'LASTPOINT))) pause)
(setq lllp (mapcar '- (setq llp (getvar 'LASTPOINT)) lp))
)
(defun do_CC nil
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.copy" s "" "_non" (getvar 'LASTPOINT) "_non" (getvar 'LASTPOINT))
(command "_.move" s "" "_non" (if llp llp (setq lp (getvar 'LASTPOINT))) "_non" (if llp (setq llp (mapcar '+ llp lllp)) lp))
)
(defun do_CCC ( / n k kk pt d )
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(initget 7)
(setq n (getint "\n输入数组数量<结束按空格键>"))
(command "_.copy" s "" "_non" (getvar 'LASTPOINT) "_non" (getvar 'LASTPOINT))
(command "_.move" s "" "_non" (if llp (setq lp llp) (setq lp (getvar 'LASTPOINT))) pause)
(setq lllp (mapcar '- (setq llp (getvar 'LASTPOINT)) lp))
(setq k (float n))
(setq d (/ (distance lllp '(0.0 0.0 0.0)) k))
(prompt "\n设定总距离") (princ (rtos d 2 8)) (prompt "\t ENTER 继续")
(command pause)
(setq kk 0.0)
(repeat (- n 1)
(setq pt (mapcar '- lp (mapcar '* (list (* (setq kk (1+ kk)) (/ 1.0 k)) (* kk (/ 1.0 k)) (* kk (/ 1.0 k))) lllp)))
(command "_.copy" s "" "_non" lp "_non" pt)
)
(setvar 'LASTPOINT llp)
)
(defun do_M nil
(prompt "\n下一点:")
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.move" s "" "_non" (if llp (setq lp llp) (setq lp (getvar 'LASTPOINT))) pause)
(setq lllp (mapcar '- (setq llp (getvar 'LASTPOINT)) lp))
)
(defun do_MM nil
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.move" s "" "_non" (if llp llp (setq lp (getvar 'LASTPOINT))) "_non" (if llp (setq llp (mapcar '+ llp lllp)) lp))
)
(defun do_R ( / lo g )
(setq lo T)
(while lo
(prompt "\n按鼠标左键<鼠标输入>; 鼠标右键<键盘输入>")
(setq g (grread nil 14 0))
(cond
((eq (car g) 3) (do_RM))
((or (eq (car g) 25) (eq (car g) 11)) (do_RK))
)
)
)
(defun do_RM ( / pt osm pola )
(setq osm (getvar 'OSMODE))
(setvar 'OSMODE 0)
(setq pola (getvar 'POLARANG))
(setvar 'POLARANG 0.0)
(prompt "\n输入角度<鼠标输入> : ")
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) pause)
(command "_.line" "_non" pt "_non" (cadr (grread 1)) "")
(setq ang (atof (rtos (cvunit (getvar 'LASTANGLE) "radians" "degrees"))))
(setvar 'LASTPOINT pt)
(setvar 'OSMODE osm)
(setvar 'POLARANG pola)
(entdel (entlast))
(setq lo nil)
)
(defun do_RK ( / pt osm pola )
(setq osm (getvar 'OSMODE))
(setvar 'OSMODE 0)
(setq pola (getvar 'POLARANG))
(setvar 'POLARANG 0.0)
(initget 3)
(setq ang (getreal "\n输入角度"))
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) ang)
(setvar 'LASTPOINT pt)
(setvar 'OSMODE osm)
(setvar 'POLARANG pola)
(setq lo nil)
)
(defun do_RT nil
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.rotate" s "" "_non" (if llp llp (getvar 'LASTPOINT)) 90)
)
(defun do_RR nil
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.rotate" s "" "_non" (if llp llp (getvar 'LASTPOINT)) "")
)
(defun do_RRR nil
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.rotate" s "" "_non" (if llp llp (getvar 'LASTPOINT)) (if ang (setq ang (- ang)) 0))
)
(defun do_RRRR ( / lo g )
(setq lo T)
(while lo
(prompt "按鼠标左键<鼠标输入>; 鼠标右键<键盘输入>")
(setq g (grread nil 14 0))
(cond
((eq (car g) 3) (do_RRRRM))
((or (eq (car g) 25) (eq (car g) 11)) (do_RRRRK))
)
)
)
(defun do_RRRRM ( / loo g pt osm pola ss entl n k kk d )
(setq osm (getvar 'OSMODE))
(setvar 'OSMODE 0)
(setq pola (getvar 'POLARANG))
(setvar 'POLARANG 0.0)
(prompt "\n输入角度<鼠标输入> : ")
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.copy" s "" "_non" "@" "_non" "@")
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) pause)
(command "_.line" "_non" pt "_non" (cadr (grread 1)) "")
(setvar 'LASTPOINT pt)
(setq ang (atof (rtos (cvunit (getvar 'LASTANGLE) "radians" "degrees"))))
(entdel (entlast))
(setq loo T)
(while loo
(prompt "\n鼠标左键控制角度小于180度;鼠标右键控制角度大于180度")
(setq g (grread nil 14 0))
(cond
((eq (car g) 3) (setq loo nil))
((or (eq (car g) 25) (eq (car g) 11)) (if (not (minusp ang)) (setq ang (- ang 360.0)) (setq ang (+ ang 360.0))) (setq loo nil))
)
)
(setq ss (ssadd))
(initget 6)
(setq n (getint "\n输入数组数量<结束按空格键><ENTER旋转一次>"))
(if (not (null n))
(progn
(setq k (float n))
(setq d (/ ang k))
(prompt "\n设定角度输入单位") (princ (rtos d 2 8)) (prompt "\t ENTER 继续")
(command pause)
(setq kk 0)
(repeat (- n 1)
(setq kk (1+ kk))
(if (= kk 1)
(progn
(setq entl (entlast))
(command "_.copy" s "" "_non" "@" "_non" "@")
(while (setq entl (entnext entl))
(ssadd entl ss)
)
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) (* (* (- 1.0) (/ 1.0 k)) ang))
)
(progn
(command "_.copy" s "" "_non" "@" "_non" "@")
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) (* (* (- 1.0) (/ 1.0 k)) ang))
)
)
)
)
)
(if (/= (sslength ss) 0) (setq s ss))
(setvar 'LASTPOINT pt)
(setvar 'OSMODE osm)
(setvar 'POLARANG pola)
(setq lo nil)
)
(defun do_RRRRK ( / pt osm pola ss entl n k kk d )
(setq osm (getvar 'OSMODE))
(setvar 'OSMODE 0)
(setq pola (getvar 'POLARANG))
(setvar 'POLARANG 0.0)
(initget 3)
(setq ang (getreal "\n键盘输入角度"))
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.copy" s "" "_non" "@" "_non" "@")
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) ang)
(setq ss (ssadd))
(initget 6)
(setq n (getint "\n输入数组数量<结束按空格键><ENTER旋转一次>"))
(if (not (null n))
(progn
(setq k (float n))
(setq d (/ ang k))
(prompt "\n设定角度输入单位:") (princ (rtos d 2 8)) (prompt "\t ENTER 继续")
(command pause)
(setq kk 0)
(repeat (- n 1)
(setq kk (1+ kk))
(if (= kk 1)
(progn
(setq entl (entlast))
(command "_.copy" s "" "_non" "@" "_non" "@")
(while (setq entl (entnext entl))
(ssadd entl ss)
)
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) (* (* (- 1.0) (/ 1.0 k)) ang))
)
(progn
(command "_.copy" s "" "_non" "@" "_non" "@")
(command "_.rotate" s "" "_non" (setq pt (if llp llp (getvar 'LASTPOINT))) (* (* (- 1.0) (/ 1.0 k)) ang))
)
)
)
)
)
(if (/= (sslength ss) 0) (setq s ss))
(setvar 'LASTPOINT pt)
(setvar 'OSMODE osm)
(setvar 'POLARANG pola)
(setq lo nil)
)
(defun do_U nil
(command "_.undo" "b")
(setq llp (car l))
(setq s (car sss))
(setvar 'LASTPOINT llp)
(setq l (cdr l))
(setq sss (cdr sss))
)
(defun mcr ( / loop gr sss l p lp llp lllp )
(setq loop T)
(if (not (eq s nil))
(while loop
(prompt "\n\S\选择对象 \P\重设基准点 \C\复制 \A\数组 \D\连续复制 \M\移动 \N\连续移动 \R\旋转 \T\连续旋转 \E\前次旋转 \Y\数组旋转 \TAB\旋转90度 \ U\复原 ESC键或鼠标右键结束")
(setq gr (grread nil 14 0))
(cond
((or (equal gr '(2 115)) (equal gr '(2 83))) (progn (setq s nil) (mcr)))
((or (equal gr '(2 112)) (equal gr '(2 80))) (progn (setq p (getpoint "\n选择基准点")) (setq llp nil) (setvar 'LASTPOINT p)))
((or (equal gr '(2 99)) (equal gr '(2 67))) (do_C))
((or (equal gr '(2 100)) (equal gr '(2 68))) (do_CC))
((or (equal gr '(2 97)) (equal gr '(2 65))) (do_CCC))
((or (equal gr '(2 109)) (equal gr '(2 77))) (do_M))
((or (equal gr '(2 110)) (equal gr '(2 78))) (do_MM))
((or (equal gr '(2 114)) (equal gr '(2 82))) (do_R))
((or (equal gr '(2 116)) (equal gr '(2 84))) (do_RR))
((or (equal gr '(2 101)) (equal gr '(2 69))) (do_RRR))
((or (equal gr '(2 121)) (equal gr '(2 89))) (do_RRRR))
((or (equal gr '(2 117)) (equal gr '(2 85))) (do_U))
((equal gr '(2 9)) (do_RT))
((or (equal gr '(2 27)) (eq (car gr) 25) (eq (car gr) 11)) (setq loop nil))
)
)
(progn
(setq s (ssget "_:L"))
(setq p (getpoint "\n选择基准点"))
(setvar 'LASTPOINT p)
(mcr)
)
)
)
(mcr)
(*error* nil)
(princ)
)
源码附件在六楼。
源码是类似mocoro,可以做复制、移动及旋转,但是尚缺镜像及比例放大缩小,是否可再帮忙新增镜像及比例放大缩小?
本帖最后由 baoxiaozhong 于 2019-9-3 11:40 编辑
mikewolf2k 发表于 2019-9-3 11:06
有些字符被当做格式替换了。源码请用插入代码功能。
非常感谢楼主的分享 我有一个画通信管道的插件 每次画出来井的角度和线的角度都不一样 试一下这个旋转功能什么效果 p-3-ianlcc 发表于 2020-6-3 07:03
cad的版本是2016
会不会是编码问题,附件是WORD档,你再自行转成纯文字的TXT试试,这个版本,我用2014 用了半年多了,没出现问题过。
好奇用了一下缺少参数 好奇用了一下缺少参数 love1030312 发表于 2019-9-3 08:31
好奇用了一下缺少参数
缺少什么参数,我这里使用是正常的。 有些字符被当做格式替换了。源码请用插入代码功能。 感谢分享啊 费这么大劲弄这个干啥
本帖最后由 baoxiaozhong 于 2019-9-8 18:55 编辑
((or (equal gr '(2 73)) (equal gr '(2 105))) (do_MIR))
目前是多设一个 I 键为镜像,
但是捕抓键盘的参数已经找到了,可是子参数的镜像,都试不出来,有好心人可以指导一下吗?
;;mirror
(defun do_MIR nil
(prompt "\n下一點:")
(command "_.point" "_non" "@")
(setq l (cons (trans (cdr (assoc 10 (entget (entlast)))) 0 1) l))
(setq sss (cons s sss))
(entdel (entlast))
(command "_.undo" "m")
(command "_.mirror" s "" "_non" (getvar 'LASTPOINT) "_non" (getvar 'LASTPOINT))
(command "_.move" s "" "_non" (if llp (setq lp llp) (setq lp (getvar 'LASTPOINT))) pause)
(setq lllp (mapcar '- (setq llp (getvar 'LASTPOINT)) lp))
)
页:
[1]
2