明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3429|回复: 12

[求助]求一次性偏移多个不同距离图元的LISP,并且每个偏移的图元要在不同的层上?

  [复制链接]
发表于 2009-9-23 19:23:00 | 显示全部楼层 |阅读模式

各位好,求一LISP程序,如下图示,白色线条为原图,然后一次性偏移多个不同距离(距离可以在程序中定,不用提示输入数值),且偏移出来的不同距离的图元要分别在不同的图层上,如图偏移1MM,这时图元就在LP图层上,偏移2MM,图元就在LS图层上,偏移3.5MM,图元就在LU图层上,(图层名也可以在程序中定,不用提示输入图层名,用其它图层名时自己改就好了),不知道我有没有表达清楚,大家帮帮忙,谢谢!

 

 

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2009-9-26 07:59:00 | 显示全部楼层
本帖最后由 作者 于 2009-9-26 12:15:24 编辑

[code]

;;By Lucas
(defun C:OFFSET_LAI ()
  (OFFSET_LAI
    '(("LP" 1 "CONTINUOUS")
      ("LS" 3 "CONTINUOUS")
      ("LU" 6 "CONTINUOUS")
     )
    '((1 . "LP") (2 . "LS") (3.5 . "LU"))
  )
)

;;使用(OFFSET_LAI LAYER_LST OFFSET_LST)
(defun OFFSET_LAI (LAYER_LST OFFSET_LST / ENT PT HOLDECHO)
  (setq HOLDECHO (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (NEW_LAYER LAYER_LST)
  (if (and (setq ENT (entsel "\n選取要偏移的物件: "))
    (setq PT (getpoint "\n指定要在那一側偏移的點: "))
      )
    (foreach LST OFFSET_LST
      (command "_.OFFSET" (car LST) ENT "non" PT "")
      (command "_.change" "l" "" "p" "la" (cdr LST) "")
    )
  )
  (setvar "CMDECHO" HOLDECHO)
  (princ)
)

;;一次性建立多個層
;;(NEW_LAYER LAYER_LST)
(defun NEW_LAYER (LST / X DOC)
  (vl-load-com)
  (setq DOC (vla-get-activedocument (vlax-get-acad-object)))
  (mapcar
    '(lambda (X)
       (if (not (tblsearch "ltype" (nth 2 X)))
  (vla-load (vla-get-linetypes DOC)
     (nth 2 X)
     (if (= (vlax-variant-value
       (vla-getvariable DOC "measureinit")
     )
     0
         )
       "acad.lin"
       "acadiso.lin"
     )
  )
       )
       (entmake
  (list '(0 . "LAYER")
        '(100 . "AcDbSymbolTableRecord")
        '(100 . "AcDbLayerTableRecord")
        (cons 2 (nth 0 X))
        '(70 . 0)
        (cons 62 (nth 1 X))
        (cons 6 (nth 2 X))
  )
       )
     )
    LST
  )
  (vlax-release-object DOC)
  (princ)
)

[\code]

回复 支持 1 反对 0

使用道具 举报

发表于 2016-10-7 10:51:03 | 显示全部楼层
龙龙仔 发表于 2009-9-26 07:59
本帖最后由 作者 于 2009-9-26 12:15:24 编辑  [code];;By Lucas(defun C:OFFSET_LAI ()  (OFFSET_LA ...

版主您好,您这个程序能否帮忙优化下,图形偏移到其他层的时候,咋样把图形变成,偏移层的颜色呀!
发表于 2016-10-7 22:32:09 | 显示全部楼层
谢谢楼上的各位,这个lsp很适合冲模绘图用
 楼主| 发表于 2009-9-24 18:36:00 | 显示全部楼层
大家帮帮忙啊,谢谢!
发表于 2009-9-24 22:02:00 | 显示全部楼层
呵呵,又是一个五金模设计的来了,看我的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2009-9-25 19:07:00 | 显示全部楼层
谢谢AMTONNY兄,下了试用了一下,有个问题提一下,比如我原图形是O层,我执行命令后发现O层的图元变为DD图层上了,但是要求O图层上的图元是不变的是,只偏移三个就好,最后能不能教一下怎样添加其它图层及设置偏移数,再次谢谢AMTONNY的关注!
发表于 2009-9-26 09:15:00 | 显示全部楼层

楼主是做冲模的吧,给你这个看看,我也是在网上看到别人的

hyjxlayer:dialog {  label = "放大多义线复制到对应的层";
    :row{
    :boxed_row{
         :column{spacer_0;
         :toggle{ key="mb1";label=  "盖板        (001)"; }
         :toggle{ key="mb2";label=  "上模板      (002)"; }
         :toggle{ key="mb3";label=  "凸模固定板座(003)"; }
         :toggle{ key="mb4";label=  "凸模固定板  (004)"; }
         :toggle{ key="mb5";label=  "卸料板座    (005)"; }
         :toggle{ key="mb6";label=  "卸料板      (006)"; }
         :toggle{ key="mb7";label=  "凹模板      (007)"; }
         :toggle{ key="mb8";label=  "凹模板座    (008)"; }
         :toggle{ key="mb9";label=  "下模座      (009)"; }
         :toggle{ key="mb10";label= "导料板      (010)"; }
         :toggle{ key="mb11";label= "凹模        (Die)"; }
         :toggle{ key="mb12";label= "凸模      (Punch)"; }
         }
     // spacer_1;
        :column{
        :edit_box{label="偏侈距离:";key="dis1";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis2";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis3";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis4";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis5";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis6";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis7";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis8";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis9";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis10";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis11";edit_width=6;}
        :edit_box{label="偏侈距离:";key="dis12";edit_width=6;}
        //spacer_0;
        }}}
         :row{spacer_1;
         :toggle{label = "全选/清除";key="setall";fixed_width=true;}
         //:toggle{label = "反选";key="vice";fixed_width=true;}
         spacer_1;  spacer_1;spacer_1;spacer_1;spacer_1;
         :toggle{label = "值清空";key="clear";fixed_width=true;}
         :toggle{label = "缺省";key="setold";fixed_width=true;}
             }
      ok_cancel;
}           

(defun hy_jxlayer() 
   (setq dcl_id (load_dialog "hy_dcl.dcl"))
   (if (< dcl_id 0) (exit))
   (if(not (new_dialog "hyjxlayer" dcl_id)) (exit))
   (mode_tile "dis1" 0)(SET_TILE "dis1" "1.0")
   (mode_tile "dis2" 0)(SET_TILE "dis2" "0.5")
   (mode_tile "dis3" 0)(SET_TILE "dis3" "0.5")
   (mode_tile "dis4" 0)(SET_TILE "dis4" "0.02")
   (mode_tile "dis5" 0)(SET_TILE "dis5" "0.6")
   (mode_tile "dis6" 0)(SET_TILE "dis6" "0.002")
   (mode_tile "dis7" 0)(SET_TILE "dis7" "0.03")
   (mode_tile "dis8" 0)(SET_TILE "dis8" "0.5")
   (mode_tile "dis9" 0)(SET_TILE "dis9" "1.5")
   (mode_tile "dis10" 0)(SET_TILE "dis10" "0.5")
   (mode_tile "dis11" 0)(SET_TILE "dis11" "0.1")
   (mode_tile "dis12" 0)(SET_TILE "dis12" "0.1")
   (mode_tile "dis13" 0)(SET_TILE "dis13" "0.5")
   (mode_tile "dis14" 0)(SET_TILE "dis14" "0.5")
   (mode_tile "dis15" 0)(SET_TILE "dis15" "0.5")
  
   (set_tile "mb5" "1")

   (action_tile "mb1" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb2" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb3" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb4" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb5" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb6" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb7" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb8" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb9" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb10" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb11" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb12" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb13" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb14" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "mb15" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "setall" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "clear" "(setq x (get_tile $key)) (hyficha $key x)")
   (action_tile "setold" "(setq x (get_tile $key)) (hyficha $key x)")

   (action_tile "setall" "(qc-qx $value)")
   (action_tile "vice" "(qc-fx $value)")

   (action_tile "dis1" "(hyfichcheck \"dis1\")")
   (action_tile "dis2" "(hyfichcheck \"dis2\")")
   (action_tile "dis3" "(hyfichcheck \"dis3\")")
   (action_tile "dis4" "(hyfichcheck \"dis4\")")
   (action_tile "dis5" "(hyfichcheck \"dis5\")")
   (action_tile "dis6" "(hyfichcheck \"dis6\")")
   (action_tile "dis7" "(hyfichcheck \"dis7\")")
   (action_tile "dis8" "(hyfichcheck \"dis8\")")
   (action_tile "dis9" "(hyfichcheck \"dis9\")")
   (action_tile "dis10" "(hyfichcheck \"dis10\")")
   (action_tile "dis11" "(hyfichcheck \"dis11\")")
   (action_tile "dis12" "(hyfichcheck \"dis12\")")
   (action_tile "dis13" "(hyfichcheck \"dis13\")")
   (action_tile "dis14" "(hyfichcheck \"dis14\")")
   (action_tile "dis15" "(hyfichcheck \"dis15\")")


   ;(action_tile "mb1" "(setq mb1 (get_tile \"mb1\"))(hy_savedat)")
   ;(ACTION_TILE "setall" "(MODE_TILE "mb1" 0)")        

   ;(action_tile "setall" "(setq dd 2)") 
   ;(action_tile "clear1" "(setq dd 3)")

   (action_tile "accept" "(hyfichb)")
   (setq dd (start_dialog))
   ;(unload_dialog dcl_id)
   ;|(cond
      ((= dd 2)(ok_all))
      ((= dd 3)(ok_clear))
     )|;

   (if (= dd 1) (hyfichc)
    )

 )

(defun qc-qx(b)
(set_tile "mb1" b)
(set_tile "mb2" b)
(set_tile "mb3" b)
(set_tile "mb4" b)
(set_tile "mb5" b)
(set_tile "mb6" b)
(set_tile "mb7" b)
(set_tile "mb8" b)
(set_tile "mb9" b)
(set_tile "mb10" b)
(set_tile "mb11" b)
(set_tile "mb12" b)
)
(defun qc-fx(a)
(setq m1 (get_tile "mb1"))
(if (= m1 "0") (set_tile "mb1" 1))
)

(defun ok_all()
  (set_tile "mb1" "1")(set_tile "mb2" "1")(set_tile "mb3" "1")(set_tile "mb4" "1"))


(defun hyficha(key x)
 (cond
  ((= key "mb1") (if (= x "1") (progn (mode_tile "dis1" 0)(mode_tile "dis1" 2)(SET_TILE "dis1" "1.0"))
                  (mode_tile "dis1" 1)))
  ((= key "mb2") (if (= x "1") (progn (mode_tile "dis2" 0) (mode_tile "dis2" 2)(SET_TILE "dis2" "0.5"))
                  (mode_tile "dis2" 1)))
  ((= key "mb3") (if (= x "1") (progn (mode_tile "dis3" 0) (mode_tile "dis3" 2)(SET_TILE "dis3" "0.5"))
                  (mode_tile "dis3" 1)))
  ((= key "mb4") (if (= x "1") (progn (mode_tile "dis4" 0) (mode_tile "dis4" 2)(SET_TILE "dis4" "0.02"))
                   (mode_tile "dis4" 1)))
  ((= key "mb5") (if (= x "1") (progn (mode_tile "dis5" 0) (mode_tile "dis5" 2)(SET_TILE "dis5" "0.6"))
                  (mode_tile "dis5" 1)))
  ((= key "mb6") (if (= x "1") (progn (mode_tile "dis6" 0) (mode_tile "dis6" 2)(SET_TILE "dis6" "0.002"))
                  (mode_tile "dis6" 1)))
  ((= key "mb7") (if (= x "1") (progn (mode_tile "dis7" 0) (mode_tile "dis7" 2)(SET_TILE "dis7" "0.03"))
                  (mode_tile "dis7" 1)))
  ((= key "mb8") (if (= x "1") (progn (mode_tile "dis8" 0) (mode_tile "dis8" 2)(SET_TILE "dis8" "0.5"))
                  (mode_tile "dis8" 1)))
  ((= key "mb9") (if (= x "1") (progn (mode_tile "dis9" 0) (mode_tile "dis9" 2)(SET_TILE "dis9" "1.5"))
                  (mode_tile "dis9" 1)))
 ((= key "mb10") (if (= x "1") (progn (mode_tile "dis10" 0) (mode_tile "dis10" 2)(SET_TILE "dis10" "0.5"))
                  (mode_tile "dis10" 1)))
 ((= key "mb11") (if (= x "1") (progn (mode_tile "dis11" 0) (mode_tile "dis11" 2)(SET_TILE "dis11" "0.1"))
                  (mode_tile "dis11" 1)))
 ((= key "mb12") (if (= x "1") (progn (mode_tile "dis12" 0) (mode_tile "dis12" 2)(SET_TILE "dis12" "0.1"))
                  (mode_tile "dis12" 1)))
 ((= key "mb13") (if (= x "1") (progn (mode_tile "dis13" 0) (mode_tile "dis13" 2))
                  (mode_tile "dis13" 1)))
 ((= key "mb14") (if (= x "1") (progn (mode_tile "dis14" 0) (mode_tile "dis14" 2))
                  (mode_tile "dis14" 1)))
 ((= key "mb15") (if (= x "1") (progn (mode_tile "dis15" 0) (mode_tile "dis15" 2))
                  (mode_tile "dis15" 1)))

 ((= key "clear") (if (= x "1") (progn (set_tile "dis1" "0")(set_tile "dis2" "0")(set_tile "dis3" "0")(set_tile "dis4" "0")
                                        (set_tile "dis5" "0")(set_tile "dis6" "0")(set_tile "dis7" "0")(set_tile "dis8" "0")
                                        (set_tile "dis9" "0")(set_tile "dis10" "0")(set_tile "dis11" "0")(set_tile "dis12" "0")
                                        (set_tile "setold" "0"))))
 ((= key "setold") (if (= x "1") (progn (SET_TILE "dis1" "1.0")(SET_TILE "dis2" "0.5")(SET_TILE "dis3" "0.5")(SET_TILE "dis4" "0.02")
                                        (SET_TILE "dis5" "0.6")(SET_TILE "dis6" "0.002")(SET_TILE "dis7" "0.03")(SET_TILE "dis8" "0.5")
                                        (SET_TILE "dis9" "1.5")(SET_TILE "dis10" "0.5")(SET_TILE "dis11" "0.1")(SET_TILE "dis12" "0.1")
                                        (set_tile "clear" "0"))))
 )
)

(defun hyfichb()
   (setq i 0)
   (setq list1 '())
   (setq list2 '())
  
    (if (= (get_tile "mb1") "1")
          (progn
           (setq list1 (cons (get_tile "dis1") list1))
           (setq list2 (cons "001" list2))
         )
     ) 
     (if (= (get_tile "mb2") "1")
         (progn
           (setq list1 (cons (get_tile "dis2") list1))
           (setq list2 (cons "002" list2))
         )
     ) 
     (if (= (get_tile "mb3") "1")
         (progn
           (setq list1 (cons (get_tile "dis3") list1))
           (setq list2 (cons "003" list2))
         )
     ) 
      (if (= (get_tile "mb4") "1")
          (progn
            (setq list1 (cons (get_tile "dis4") list1))
            (setq list2 (cons "004" list2))
          )
      )
      (if (= (get_tile "mb5") "1")
         (progn
           (setq list1 (cons (get_tile "dis5") list1))
           (setq list2 (cons "005" list2))
         )
      )  
      (if (= (get_tile "mb6") "1")
         (progn
           (setq list1 (cons (get_tile "dis6") list1))
           (setq list2 (cons "006" list2))
         )
      ) 
       (if (= (get_tile "mb7") "1")
         (progn
           (setq list1 (cons (get_tile "dis7") list1))
           (setq list2 (cons "007" list2))
         )
       ) 
      (if (= (get_tile "mb8") "1")
          (progn
            (setq list1 (cons (get_tile "dis8") list1))
            (setq list2 (cons "008" list2))
         )
      ) 
       (if (= (get_tile "mb9") "1")
          (progn
            (setq list1 (cons (get_tile "dis9") list1))
            (setq list2 (cons "009" list2))
           )
      ) 
       (if (= (get_tile "mb10") "1")
          (progn
            (setq list1 (cons (get_tile "dis10") list1))
            (setq list2 (cons "010" list2))
         )
      )
       (if (= (get_tile "mb11") "1")
          (progn
            (setq list1 (cons (get_tile "dis11") list1))
            (setq list2 (cons "die" list2))
         )
      )      
       (if (= (get_tile "mb12") "1")
          (progn
            (setq list1 (cons (get_tile "dis12") list1))
            (setq list2 (cons "punch" list2))
         )
       )
        (if (= (get_tile "mb13") "1")
          (progn
            (setq list1 (cons (get_tile "dis13") list1))
            (setq list2 (cons "dd" list2))
            (setq i (+ i 1))
         )
       )  
       (if (= (get_tile "mb14") "1")
          (progn
            (setq list1 (cons (get_tile "dis14") list1))
            (setq list2 (cons "cc" list2))
         )
      ) 
       (if (= (get_tile "mb15") "1")
          (progn
            (setq list1 (cons (get_tile "dis15") list1))
            (setq list2 (cons "dh" list2))
         )
      ) 
  
 (done_dialog 1)

(defun hyfichc()   ;;将list1 list2中的数据取去
(setvar "cmdecho" 0)
    (setq ss (ssget))  ;;选择物体
    (setq j 0)
    (setq k (sslength ss))
    (repeat (length list1)
       (setq dis (atof (nth j list1))) ;; 将表list1中的第j个原素取去
       (setq lyname (nth j list2))
         (setq j (+ j 1))
         (setq n 0)
         (setq pt (list 99999999 99999999))
        (repeat k
          (setq e (entget (setq e1 (ssname ss n)))) ;;取去实体中的一个原子
          (setq n (1+ n))
         (cond
           ((= "LWPOLYLINE" (cdr (assoc 0 e)))
             (progn
                (if (= dis 0)
                  (command "copy" e1 "" pt pt )
                  (command "offset" dis e1 pt "")
                )
               (setq e (entget (entlast)))
              (setq e (subst (cons 8 lyname) (assoc 8 e) e))
              (entmod e)
            )
          )
          ((= "CIRCLE" (cdr (assoc 0 e)))
            (progn
               (if (= dis 0)
                   (command "copy" e1 "" pt pt)
                   (command "offset" dis e1 pt "")
                )
              (setq e (entget (entlast)))
              (setq e (subst (cons 8 lyname) (assoc 8 e) e))
              (entmod e)
           )
         )
         ((= "INSERT" (cdr (assoc 0 e)))
            (progn
              (command "copy" e1 "" pt (polar pt (* pi 0.25) (* dis 1.414)))
              (setq e (entget (entlast)))
              (setq e (subst (cons 8 (STRCAT lyname "mark")) (assoc 8 e) e))
              (entmod e)
              (setq e1 (entlast))
              (setq e2 (entnext e1))
              (if(/= e2 nil)  ;将长宽更正
                 (progn
                   (setq ed2 (entget e2))
                   (while (= (cdr (assoc 0 ed2)) "ATTRIB")
                     (cond
                        ((= (strcase (cdr (assoc 2 ed2))) "CH")
                          (PROGN
                            (SETQ len1 (cdr (assoc 1 ed2)))
                            (IF(or (> (STRLEN len1) 1) (/= (substr len1 1 1) " "))
                               (setq len1 (rtos (+ (atof len1) dis dis) 2 5))
                            )
                            (SETQ ED2 (SUBST (CONS 1 len1) (assoc 1 ed2) ed2))
                            (entmod ed2)
                            (entupd e2)
                          )  
                        )
                        ((= (strcase (cdr (assoc 2 ed2))) "KUAN")
                           (PROGN
                            (SETQ len1 (cdr (assoc 1 ed2)))
                            (IF(or (> (STRLEN len1) 1) (/= (substr len1 1 1) " "))
                               (setq len1 (rtos (+ (atof len1) dis dis) 2 5))
                            )
                            (SETQ ED2 (SUBST (CONS 1 len1) (assoc 1 ed2) ed2))
                            (entmod ed2)
                            (entupd e2)
                          )  
                       )
                     )
                     (setq e2 (entnext e2))
                     (setq ed2 (entget e2))
                   )  ;while
              )  )    ;if
            )
         )
        ) ;;;end cond
       )  ;;end repeat

     
    )  ;;end repeat
(princ)
)

(defun hyfichcheck(key)
   (setq x (atof (get_tile key)))
   (if (>= x 0)
      (progn
       (set_tile "error" "")
       )
      (progn
         (set_tile "error" (strcat (strcase key) "的值不能为负数!"))
         (mode_tile key 2)
         (mode_tile key 3)
         nil
       )
     )
)

 楼主| 发表于 2009-9-26 18:57:00 | 显示全部楼层
再次谢谢,AMTONNY,龙龙仔版主,hbllw  !!!
发表于 2009-9-26 19:19:00 | 显示全部楼层

呵呵,你打开后找到这里

(defun EAZ()
(command "chprop" en "" "la" "DD" "")  在(command...:)前加上;,如;(command...),O层就不会就了哦

设置偏移量是这里            (command "offset"  1  en  po1 "") 面的数字 1

      设置图层是这里      (command "chprop" (entlast) "" "la" "dx" "") dx  即为图层名

添加图层如下:            (command "offset"   偏移距离   en po1 "")
            (command "chprop" (entlast) "" "la" "图层名" "")加在相同位置下一行保存就可以了

 楼主| 发表于 2009-9-27 18:58:00 | 显示全部楼层

呵呵,今天研究了一下,搞定了,真的是要谢谢AMTONNY,有好几次都耐心相助,相信有你们,我们的工作会更加高效,谢谢!

发表于 2009-9-27 23:09:00 | 显示全部楼层
我刚接触的有点看不懂,希望大家以后能指导指导小弟,谢谢了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-20 06:44 , Processed in 0.207907 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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