明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3198|回复: 10

[讨论] ET中已知函数的整理

[复制链接]
发表于 2013-9-2 13:28 | 显示全部楼层 |阅读模式
ET中已知函数的整理
1 aly1004在破解ET中fas文件,这很好,可供大家学习。
2 前段时间,ll_j提出了类(apply ''((a b) (+ a b)) '(101 102))的写法供大家讨论

其实ET中提供了一些已知的函数,大家可以临摹。只不过,在没有仔细读完之前,我们并不知道这些已知函数怎么使用。换言之,这些

已经函数需要输入什么,最后输出什么,尽管有英文说明,哪有中文亲切呢。下面我整理了两个,有示例,这样理解就容易多了。
有兴趣的,把自己学习整理的已知函数ET贴出来,大家相互学习提高。
前段时间,ll_j提出了类(apply ''((a b) (+ a b)) '(101 102))的写法供大家讨论,今天我在ET的已知函数中看到了类似的写法。
  1. ;;(setq lst (list (getpoint)(getpoint)(getpoint)(getpoint)));(wipeout_clipit nil lst)
  2. (defun wipeout_clipit (na lst / A LA N NA2)
  3.   (if na
  4.     (entdel na)
  5.   )                                                  
  6.   (if (setq la (acet-layer-locked (getvar "clayer")))
  7.     (command "_.layer" "_un" (getvar "clayer") "")
  8.   )
  9.   (command "_.pline")
  10.   (setq n 0)
  11.   (repeat (length lst)
  12.     (setq a (nth n lst))                          ;setq
  13.     (command a)
  14.     (setq n (+ n 1))                                  ;setq
  15.   )                                                  ;repeat
  16.   (command "")

  17.   (setq na2 (entlast))
  18.   (command "_.pedit" na2 "_cl" "_x")
  19.   (command "_.wipeout" "_n" na2 "_y")
  20.   (if la
  21.     (command "_.layer" "_lock" (getvar "clayer") "")
  22.   )                                                  
  23. )                                                  

  24. ;;take a list of point ans removes duplicated points and unneeded points
  25. ;;as a result of no angle change.
  26. ;;去除相邻重复点,并形成封闭(plist_optimize '((1 2)(1 2)(3 4)(3 4)));((1 2) (3 4) (1 2))
  27. (defun plist_optimize (lst / A B C D LST2 N)
  28.   (if (not (equal (car lst) (last lst) 0.00001))
  29.     (setq lst (append lst (list (car lst))))          
  30.   )                                                  
  31.   (setq n 0)
  32.   (repeat (max 0 (- (length lst) 1))
  33.     (setq a (nth n lst)
  34.           b (nth (+ n 1) lst)
  35.     )                                                  
  36.     (if        (equal n 0)
  37.       (setq lst2 (list a b))
  38.     )                                                  
  39.     (setq c (nth (max (- (length lst2) 2) 0) lst2)
  40.           d (last lst2)
  41.     )                                                  
  42.     (if        (equal (angle a b)
  43.                (angle c d)
  44.                0.000001
  45.         )                                          
  46.       (setq lst2 (reverse (cdr (reverse lst2))))  
  47.     )                                                  
  48.     (if        (not (equal b (last lst2)))
  49.       (setq lst2 (append lst2 (list b)))          
  50.     )                                                  
  51.     (setq n (+ n 1))                                  
  52.   )                                                  
  53.   (if (and (>= (length lst2) 4)
  54.            (equal (angle (car lst2) (cadr lst2))
  55.                   (angle (nth (- (length lst2) 2) lst2) (last lst2))
  56.                   0.000001
  57.            )                                          
  58.       )                                                  
  59.     (setq lst2 (cdr lst2)
  60.           lst2 (reverse (cdr (reverse lst2)))
  61.     )                                                  
  62.   )                                                  
  63.   lst2
  64. )
  65. ;;层是否处理锁定状态
  66. ;;(acet-layer-locked (getvar "clayer"))
  67. (defun acet-layer-locked (layer)
  68.   (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" layer)))))
  69.     layer
  70.   )
  71. )

评分

参与人数 2明经币 +2 收起 理由
张和平 + 1 好主题
dz-2011 + 1 大师的贴子就是好!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2013-9-2 15:18 | 显示全部楼层
继续啊
 楼主| 发表于 2013-9-2 15:29 | 显示全部楼层
vlisp2012 发表于 2013-9-2 15:18
继续啊

你也整点3

;; Pline width change
;;改多段线 线宽(chgplwidths (ssget '((0 . "*POLYLINE"))) 50)
(defun chgplwidths (plines newWidth / count ent subEntity currVertex)
  (setq count 0)
  (while (< count (sslength plines))
    (setq ent (entget (ssname plines count)))
    (if        (= (cdr (assoc 0 ent)) "LWPOLYLINE")
      (command "_.pedit"
               (ssname plines count)
               "_width"
               newWidth
               "_exit"
      )
      (progn                                          ;polylines
        (setq subEntity (entnext (ssname plines count)))
        (setq currVertex (entget subEntity))
        (while (not (equal "SEQEND" (cdr (assoc 0 currVertex))))
          (setq        currVertex
                 (subst (cons 40 NewWidth) (assoc 40 currVertex) currVertex)
          )
          (setq        currVertex
                 (subst (cons 41 NewWidth) (assoc 41 currVertex) currVertex)
          )
          (entmod currVertex)
          (setq subEntity (entnext (cdr (assoc -1 currVertex))))
          (setq currVertex (entget subEntity))
        )                                          ;while
        (entupd (ssname plines count))
      )                                                  ;progn
    )                                                  ;if
    (setq count (1+ count))
  )                                                  ;while
)

;; Pline modification to close
;;使多段线闭合(chgplclose (ssget '((0 . "*POLYLINE"))))
(defun chgplclose (plines / count)
  (setq count 0)
  (while (< count (sslength plines))
    (command "_.pedit" (ssname plines count) "_close" "_exit")
    (setq count (1+ count))
  )
)

;; Pline modification to open
;;闭合多段线开(chgplopen (ssget '((0 . "*POLYLINE"))))
(defun chgplopen (plines / count)
  (setq count 0)
  (while (< count (sslength plines))
    (command "_.pedit" (ssname plines count) "_open" "_exit")
    (setq count (1+ count))
  )
)

;; Pline vertex linetype generation switch
;;1 = Extra vertex created by curve-fitting
;;2 = Curve-fit tangent defined for this vertex. A curve-fit tangent direction of 0 may be omitted from DXF output but is significant if this bit is set
;;4 = Not used
;;8 = Spline vertex created by spline-fitting
;;16 = Spline frame control point
;;32 = 3D polyline vertex
;;64 = 3D polygon mesh
;;128 = Polyface mesh vertex
;;(chgltgen (ssget '((0 . "*POLYLINE"))))
(defun chgltgen        (plines / count new70 opt ent)
  (setq count 0)
  (initget 0 "ON OFF eXit _ON OFF eXit")
  (setq opt (getkword "Full PLINE linetype? [ON/OFF/eXit] <eXit>: "))
  (if opt
    opt
    "eXit"
  )
  (if (= opt "ON")
    (while (< count (sslength plines))
      (setq ent (entget (ssname plines count)))
      (setq new70 (cons 70 (logior 128 (cdr (assoc 70 ent)))))
      (setq ent (subst new70 (assoc 70 ent) ent))
      (entmod ent)
      (setq count (1+ count))
    )                                                  ;while
  )                                                  ;if on
  (if (= opt "OFF")
    (while (< count (sslength plines))
      (setq ent (entget (ssname plines count)))
      (setq new70 (cons 70 (boole 6 128 (cdr (assoc 70 ent)))))
      (setq ent (subst new70 (assoc 70 ent) ent))
      (entmod ent)
      (setq count (1+ count))
    )                                                  ;while
  )                                                  ;if off
)
(setq plines (ssget))

;; Pline decurve
;;多段线中弧线变直(chgdecurve (ssget '((0 . "*POLYLINE"))))
(defun chgdecurve (plines / count)
  (setq count 0)
  (while (< count (sslength plines))
    (command "_.pedit" (ssname plines count) "_decurve" "_exit")
    (setq count (1+ count))
  )                                                  ;while
)

;; Pline curve fit
;;多段线拟合(chgfit (ssget '((0 . "*POLYLINE"))))
(defun chgfit (plines / count)
  (setq count 0)
  (while (< count (sslength plines))
    (command "_.pedit" (ssname plines count) "_fit" "_exit")
    (setq count (1+ count))
  )                                                  ;while
)

;; Pline spline fit
;;多段线变成spline进行拟合(chgspline (ssget))
(defun chgspline (plines / count)
  (setq count 0)
  (while (< count (sslength plines))
    (command "_.pedit" (ssname plines count) "_spline" "_exit")
    (setq count (1+ count))
  )                                                  ;while
)

;; Convert arcs and lines to polylines
;; ss is retained as a duplicate of the plines selection set because
;; after conversion, new handles are assigned to what were arcs and lines
;;线、弧转换成轻多段线(convert (ssget '((0 . "LINE,ARC"))))
(defun convert (plines / ss count opt)
  (if (> (sslength plines) 0)
    (progn
      (initget 0 "Yes No _Yes No")
      (setq opt        (getkword
                  "Convert Lines and Arcs to polylines? [Yes/No] <Yes>: "
                )
      )
    )                                                  ;progn then
  )                                                  ;if
  (if (not opt)
    (setq opt "Yes")
  )
  (if (and (= opt "Yes")
           (> (sslength plines) 0)
      )                                                  ;and
    (progn                                          ;if yes -- convert lines and arcs to polylines
      (setq ss (ssadd))
      (setq count 0)
      (while (< count (sslength plines))
        (if (or        (equal (assoc 0 (entget (ssname plines count)))
                       '(0 . "ARC")
                )
                (equal (assoc 0 (entget (ssname plines count)))
                       '(0 . "LINE")
                )
            )                                          ;or
          (progn
            (command "_.pedit" (ssname plines count) "_yes" "_exit")
            (ssadd (entlast) ss)
          )                                          ;progn true
          (ssadd (ssname plines count) ss)
        )                                          ;if
        (setq count (1+ count))
      )                                                  ;while
    )                                                  ;progn yes
    (progn                                          ;if no -- do not convert
      (setq ss plines)
      (setq count 0)
      (while (< count (sslength ss))
        (if (or        (equal (assoc 0 (entget (ssname ss count))) '(0 . "ARC"))
                (equal (assoc 0 (entget (ssname ss count))) '(0 . "LINE"))
            )                                          ;or
          (progn
            (ssdel (ssname ss count) ss)
            (setq count (1- count))
          )                                          ;progn true
        )                                          ;if
        (setq count (1+ count))
      )                                                  ;while
    )                                                  ;progn no
  )                                                  ;if
  (if (and ss
           (equal (type ss) 'PICKSET)
           (equal 0 (sslength ss))
      )                                                  ;and
    (setq ss nil)
  )                                                  ;if
  ss
)
 楼主| 发表于 2013-9-2 16:23 | 显示全部楼层
本帖最后由 自贡黄明儒 于 2013-9-2 16:24 编辑

从选择集中分离出指定类型的选择集
  1. ;;从选择集中分离出指定类型的选择集
  2. ;;(acet-pljoin-ss-flt (ssget "X") (list(cons 0 "CIRCLE")))
  3. (defun acet-pljoin-ss-flt (ss flt )
  4.   (if (and ss
  5.            (> (sslength ss) 0)
  6.       )                                                  
  7.     (progn
  8.       (command "_.select" ss "")
  9.       (setq ss (ssget "_p" flt))
  10.     )                                                  
  11.     (setq ss nil)
  12.   )
  13.   ss
  14. )
发表于 2013-9-2 20:33 | 显示全部楼层
前排支持,大师真牛!
 楼主| 发表于 2013-9-3 12:12 | 显示全部楼层
  1. ;;;    TEXTFIT.LSP
  2. (defun c:textfit (/ ename textent newend tmp start newpt val ltc_% ss txtsz)
  3.   (acet-error-init
  4.     (list
  5.       (list "cmdecho" 0 "snapang" 0 "limcheck" 0 "orthomode" 1)
  6.       T                                                  ;flag. True means use undo for error clean up.
  7.     )
  8.   )
  9.   (if (not (and
  10.              (setq ss (ssget "_i"))
  11.              (= (sslength ss) 1)
  12.              (setq ename (ssname ss 0)
  13.              )
  14.            )
  15.       )
  16.     (setq ename (car (entsel "\nSelect Text to stretch or shrink:")))
  17.   )


  18.   (cond
  19.     ((not (setq        textent        (if ename
  20.                           (entget ename)
  21.                         )
  22.           )
  23.      )
  24.      (princ "\nNo object selected!")
  25.     )
  26.     ((/= (acet-dxf 0 textent) "TEXT")
  27.      (princ "\nSelected object is not Text!")
  28.     )
  29.     ((acet-layer-locked (acet-dxf 8 textent))
  30.      (princ "\nSelected object is on a locked layer!")
  31.     )
  32.     (t
  33.      (setq txtsz (textbox textent))
  34.      ;;文字宽度newend
  35.      (setq newend (distance
  36.                     (list
  37.                       (caadr txtsz)                  ;upper right x coord
  38.                       (cadar txtsz)                  ;lower left y coord
  39.                     )
  40.                     (car txtsz)
  41.                     ;; ll xyz
  42.                   )
  43.      )
  44.      ;;set snap along text entity
  45.      (setvar "snapang"
  46.              (angtof (angtos (acet-dxf 50 textent) 0 8) 0)
  47.      )
  48.      (initget 0 "Start _Start")
  49.      (setq
  50.        tmp (getpoint (acet-dxf 10 textent)
  51.                      "\nSpecify end point or [Start point]: "
  52.            )
  53.      )
  54.      (setvar "snapang" 0)
  55.      (cond
  56.        ((= (type tmp) 'STR)
  57.         ;;new starting point to be selected
  58.         (setq start (getpoint "\nSpecify new starting point: "))
  59.         (if start
  60.           (progn
  61.             (command "_.UCS" "_E" (acet-dxf -1 textent))
  62.             (setvar "orthomode" 1);正交
  63.             (setq newpt
  64.                    (if start
  65.                      (getpoint (trans start 0 1) " ending point: ")
  66.                      nil
  67.                    )                                  ;if
  68.             )                                          ;setq
  69.             (if        newpt
  70.               (setq newpt (trans newpt 1 0))
  71.             )
  72.             (setvar "orthomode" 0)
  73.             (command "_.UCS" "_W");世界坐标系
  74.           )                                          
  75.         )
  76.         if
  77.        )
  78.        ((not (null tmp))
  79.         ;;new ending point selected
  80.         (setq start (acet-dxf 10 textent)
  81.               newpt tmp
  82.         )
  83.        )
  84.        (t
  85.         (setq start nil
  86.               newpt nil
  87.         )
  88.        )
  89.      )                                                  ;cond
  90.      (if (and start newpt)
  91.        (progn
  92.          (setq val     (assoc 41 textent)
  93.                ;;current width factor
  94.                val     (if val
  95.                          (cdr val)
  96.                          1.0
  97.                        )
  98.                ltc_%   (* (/ (distance start newpt) newend) val)
  99.                textent (subst (cons 41 ltc_%)
  100.                               (assoc 41 textent)
  101.                               textent
  102.                        )
  103.                textent (subst (cons 10 start)
  104.                               (assoc 10 textent)
  105.                               textent
  106.                        )
  107.                textent (subst (cons 11 newpt)
  108.                               (assoc 11 textent)
  109.                               textent
  110.                        )
  111.          )                                          ;setq
  112.          (entmod textent)
  113.          (entupd (acet-dxf -1 textent))
  114.        )
  115.      )
  116.      ;;end of points check
  117.     )
  118.   )                                                  ;cond
  119.   (acet-error-restore)
  120.   (princ)
  121. )                                                  ;end defun




  122. (defun c:TFHELP        (/)
  123.   (prompt
  124.     " TEXTFIT will change the width factor of the selected text, \n"
  125.   )
  126.   (prompt " to fit within the user specified points.\n")
  127.   (prompt "\n")
  128.   (prompt
  129.     " TEXTFIT will prompt:  Select Text to stretch/shrink:\n"
  130.   )
  131.   (prompt " The user is expected to select the text.\n")
  132.   (prompt "\n")
  133.   (prompt
  134.     " TEXTFIT will then prompt:  Specify starting Point/<select new ending point>: \n"
  135.   )
  136.   (prompt
  137.     " At which time the user can specify a new ending point \n"
  138.   )
  139.   (prompt "                          or\n")
  140.   (prompt
  141.     " The user can provide the letter \"S\" for a new starting point\n"
  142.   )
  143.   (prompt
  144.     " to which TEXTFIT will prompt:  Specify new starting point:  \n"
  145.   )
  146.   (prompt " and:  ending point: \n")
  147.   (textscr)
  148.   (princ)
  149. )

  150. (defun ACET-DXF        (CODE E1)
  151.   (CDR (ASSOC CODE E1))
  152. )
  153. (defun acet-layer-locked (layer)
  154.   (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "LAYER" layer)))))
  155.     layer
  156.   )
  157. )
发表于 2013-9-3 15:04 | 显示全部楼层
前排支持,大师真牛!
发表于 2013-9-3 15:08 | 显示全部楼层
,整理出来就一系列函数集了,相当于lisp增加了新函数

点评

如果你装了ET,这些是有的。  发表于 2013-9-3 16:51
发表于 2013-9-3 18:36 | 显示全部楼层
顶下,这个确实很好,前面想提出它的layer 相关命令,搞半天,搞不定,不知道缺了什么东东
发表于 2013-9-3 19:08 | 显示全部楼层
我想,LAYER可能不是用lisp写的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-20 06:29 , Processed in 0.268369 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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