明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 545|回复: 5

[讨论] 这个双向偏移代码,如何实现循环选择对像,谢谢

[复制链接]
发表于 2023-8-31 22:20 | 显示全部楼层 |阅读模式
本帖最后由 depgfdepgf 于 2023-8-31 22:24 编辑

(defun c:tt1 (/ ss)  
            ;(while ;加入这个循环为何不起作用
  •    (if (not dist) (setq dist 240))
  •        (setq newdist dist)
  •        (princ (strcat "\n当前偏移距离:" (rtos dist) " <空格或者回车设置新距离>"))
  •        (while (= ss nil)
  •        (setq ss (ssget ":s"))
  •        (if (= ss nil)
  •        (progn
  •        (setq newdist (getdist (strcat "\n设置新距离:" "<" (rtos dist) ">")))
  •        (if (= nil newdist)(setq newdist dist)(setq dist newdist))
  •          )
  •         )
  •        )
  •        (if (and newdist ss)
  •        (vlax-for ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
  •        (mapcar '(lambda (x)  (vla-offset ss x))(list newdist (- newdist)))
  •        )
  •        )
           ;);while
  • (princ)
  • )

发表于 2023-8-31 22:30 | 显示全部楼层
  1. ;;双向偏移 SNSJ 2004.3.8
  2. (defun c:OffsetBoth (/ getds obj lynm ptlay)
  3.   (defun ptlay (x y)
  4.     (foreach obj (vlax-safearray->list (vlax-variant-value x))
  5.       (vla-put-layer obj y)
  6.     )
  7.   )
  8.   (setq        getds
  9.          (getdist
  10.            (strcat "\n输入偏移距离<" (rtos (getvar "offsetdist")) ">:")
  11.          )
  12.   )
  13.   (or getds (setq getds (getvar "offsetdist")))
  14.   (setvar "offsetdist" getds)
  15.   (setq lynm (getvar "clayer"))
  16.   (while (ssget ":S" '((0 . "Arc,Circle,Ellipse,*Line")))
  17.     (vlax-for obj (vla-get-activeselectionset *doc*)
  18.       (ptlay (vla-offset obj getds) lynm)
  19.       (ptlay (vla-offset obj (* getds -1)) lynm)
  20.       (vlax-release-object obj)
  21.     )
  22.   )
  23.   (princ)
  24. )
发表于 2023-9-1 07:14 | 显示全部楼层
;(while ;加入这个循环为何不起作用
(while (= ss nil)
---------------
);while
;);while
好像是镶套循环的问题,我也遇到相同的问题,也想知道原因并解决问题,不知哪位大能解答一下,谢谢!
发表于 2023-9-1 07:39 | 显示全部楼层
试试这样
(defun c:NM (/ ss)  
        (if (not dist) (setq dist 240))
        (setq newdist dist)
        (princ (strcat "\n当前偏移距离:" (rtos dist) " <空格或者回车设置新距离>"))
        (while
                (or
                        (setq ss (ssget ":s"))
                        (if (= ss nil)
                                (progn
                                        (setq newdist (getdist (strcat "\n设置新距离:" "<" (rtos dist) ">")))
                                        (if (= nil newdist)(setq newdist dist)(setq dist newdist))
                                )
                        )       
                )       
                (if (= ss nil)
                        (progn
                                (setq ss (ssget ":s"))
                                (if (and newdist ss)
                                        (vlax-for ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                                                (mapcar '(lambda (x)  (vla-offset ss x))(list newdist (- newdist)))
                                        )
                                )
                        )
                )
        )
        (princ)
)
发表于 2023-9-3 02:23 | 显示全部楼层
发表于 2023-9-3 02:26 | 显示全部楼层
xj6019 发表于 2023-9-1 07:39
试试这样
(defun c:NM (/ ss)  
        (if (not dist) (setq dist 240))

能否设置成鼠标右键结束?现在得按ESC
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-13 19:00 , Processed in 0.133005 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表