明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1427|回复: 7

批量偏移并置为当前图层

[复制链接]
发表于 2019-7-5 12:24 | 显示全部楼层 |阅读模式
;;;批量偏移
;;;ago9999,梨胡鸟编写(QQ17137646)
(defun c:py (/ en offd pt py_fs offd dx_ss dx_ss dx_n pt pt0 n)
  (command "undo" "be")                        ; 定义返回点
  (setvar "cmdecho" 0)                        ; 关闭命令提示

  (if (or (= py_fs0 nil) (eq py_fs0 ""))
    (setq py_fs0 "Z")
  )
  (princ "\n请输入偏移方式[正向(Z)/反向(F)/双向(S)/通过(T)]<")
  (princ py_fs0)                        ;输入偏移方式
  (princ ">:")
  (setq py_fs (getstring))
  (if (or (= py_fs nil) (eq py_fs ""))
    (setq py_fs py_fs0)
    (setq py_fs0 py_fs)
  )

  (if (or (eq py_fs "t") (eq py_fs "T"))
    (princ "\n采用通过点偏移方式")
    (progn
      (if (= offd0 nil)
        (setq offd0 "0")
      )
      (princ "\n请输入偏移距离(")
      (princ offd0)
      (princ ")")                        ;输入偏移距离
      (setq offd (getdist))
      (if (= offd nil)
        (setq offd offd0)
        (setq offd0 offd)
      )
    )
  )

  (princ "\n请选择线段,弧,圆,多段线:")
  (setq dx_ss (ssget))
  (if (or (eq py_fs "s") (eq py_fs "S"))
    (setq pt (list 0 0))
    (setq pt (getpoint "\n请选择基点"))
  )                                        ;输入偏移基点

  (setq n 0)
  (while (< n (sslength dx_ss))
    (setq dx_n (ssname dx_ss n))
    (if
      (or (eq py_fs "t") (eq py_fs "T"))
       (command "OFFSET" "t" dx_n pt "")
       (progn
         (cond
           ((or        (eq "LINE" (cdr (assoc '0 (entget dx_n))))
                (eq "LWPOLYLINE" (cdr (assoc '0 (entget dx_n))))
            )
            (command "OFFSET" offd dx_n pt "") ;正向偏移
            (setq ptst (cdr (assoc '10 (entget dx_n))))
            (setq pten (cdr (assoc '10 (entget (entlast)))))

            (if        (or (eq py_fs "f") (eq py_fs "F")) ;正向偏移删除
              (command "ERASE" "l" "")
            )
            (if        (or (eq py_fs "f")
                    (eq py_fs "F")
                    (eq py_fs "s")
                    (eq py_fs "S")
                )                        ;反向偏移
              (progn
                (setq pt0 (list        (- (* 2 (nth 0 ptst)) (nth 0 pten))
                                (- (* 2 (nth 1 ptst)) (nth 1 pten))
                          )
                )
                (command "OFFSET" offd dx_n pt0 "")
              )
            )
           )
           ((or        (eq "ARC" (cdr (assoc '0 (entget dx_n))))
                (eq "CIRCLE" (cdr (assoc '0 (entget dx_n))))
            )
            (command "OFFSET" offd dx_n pt "") ;正向偏移
            (setq rst (cdr (assoc '40 (entget dx_n))))
            (setq ren (cdr (assoc '40 (entget (entlast)))))

            (if        (or (eq py_fs "s") (eq py_fs "S")) ;正向偏移复制
              (command "copy" "l" "" "0,0,0" "0,0,0")
            )
            (if        (or (eq py_fs "f")
                    (eq py_fs "F")
                    (eq py_fs "s")
                    (eq py_fs "S")
                )                        ;反向偏移
              (progn
                (setq r0 (- (* 2 rst) ren))
                (if (<= r0 0)
                  (command "ERASE" "l" "") ;正向偏移删除
                  (progn
                    (setq dx_n0 (entget (entlast)))
                    (setq dx_n0
                           (subst (cons '40 r0) (assoc '40 dx_n0) dx_n0)
                    )
                    (entmod dx_n0)
                  )                        ;正向偏移更改
                )
              )
            )
           )
         )

       )
    )
    (setq n (1+ n))
  )
   (command "Chprop" (entlast) "" "La" (Getvar 'Clayer) "")   ;偏移的对象只有1根置为当前,求指正!!
  (command "undo" "e")                        ; 定义返点
  (setvar "cmdecho" 1)                        ; 打开命令提示
  (princ)
)

发表于 2019-7-6 12:50 | 显示全部楼层

Returns the name of the last nondeleted main object (entity) in the drawing

(entlast)
The entlast function is frequently used to obtain the name of a new entity that has just been added with the command function. To be selected, the entity need not be on the screen or on a thawed layer.

============

您的情况应先建立空的选集 (setq Ofst_ss (ssadd))
在回圈内加入 (entlast)

==>
(command "Chprop" Ofst_ss "" "La" (Getvar 'Clayer) "")

 楼主| 发表于 2019-7-5 12:25 | 显示全部楼层
   (command "Chprop" (entlast) "" "La" (Getvar 'Clayer) "")   ;偏移的对象只有1根置为当前,求指正!!
发表于 2019-7-6 23:04 | 显示全部楼层
学习一下,谢谢
 楼主| 发表于 2019-7-8 16:06 | 显示全部楼层
Andyhon 发表于 2019-7-6 12:50
Returns the name of the last nondeleted main object (entity) in the drawing

(entlast)

感谢大师指点~!
发表于 2019-8-19 11:23 | 显示全部楼层
感谢分享辛苦了
发表于 2019-10-21 10:24 | 显示全部楼层
你好能否改一个完整的版本
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-20 01:10 , Processed in 0.394260 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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