找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 595|回复: 4

[每日一码] 曲线(LINE,POLYLINE,SPLINE...)反向

[复制链接]

已领礼包: 20个

财富等级: 恭喜发财

发表于 2021-1-20 04:35:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
ReverseLines.gif

non-constant.PNG



  1. ;;; ------------------------------------------------------------------------
  2. ;;;        ReverseLines.lsp v1.1
  3. ;;;
  4. ;;;        Copyright?03.18.10
  5. ;;;        Alan J. Thompson (alanjt)
  6. ;;;        a l a n j t AT g m a i l DOT c o m
  7. ;;;
  8. ;;;        Permission to use, copy, modify, and distribute this software
  9. ;;;        for any purpose and without fee is hereby granted, provided
  10. ;;;        that the above copyright notice appears in all copies and
  11. ;;;        that both that copyright notice and the limited warranty and
  12. ;;;        restricted rights notice below appear in all supporting
  13. ;;;        documentation.
  14. ;;;
  15. ;;;        The following program(s) are provided "as is" and with all faults.
  16. ;;;        Alan J. Thompson DOES NOT warrant that the operation of the program(s)
  17. ;;;        will be uninterrupted and/or error free.
  18. ;;;
  19. ;;;        Allows user to reverse direction of selected LWPolyline, Line and
  20. ;;;        Spline objects.
  21. ;;;
  22. ;;;        Revision History:
  23. ;;;
  24. ;;;        v1.1 (03.19.10) 1. Went with entmod for LWPolyline instead of recreating (stupid).
  25. ;;;                           Thanks for the example Gile.
  26. ;;;                        2. Switched from vla to entmod for Lines.
  27. ;;;
  28. ;;; ------------------------------------------------------------------------

  29. (defun c:RL (/) (c:ReverseLines))
  30. (defun c:ReverseLines (/ *error* _RevLWP #SS #Ent #Inc)

  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  34. ;;; error handler
  35.   (defun *error* (#Message)
  36.     (and *AcadDoc* (vla-endundomark *AcadDoc*))
  37.     (and #Message
  38.          (not (wcmatch (strcase #Message) "*BREAK*,*CANCEL*,*QUIT*"))
  39.          (princ (strcat "\nError: " #Message))
  40.     ) ;_ and
  41.   ) ;_ defun

  42.   (setq _RevLWP (lambda (o / e l n)
  43.                   (foreach x (setq e (entget o))
  44.                     (if (vl-position (car x) '(10 40 41 42))
  45.                       (setq l (cons x l))
  46.                       (or (eq 210 (car x)) (setq n (cons x n)))
  47.                     ) ;_ if
  48.                   ) ;_ foreach
  49.                   (setq l (append (cdddr l) (list (car l) (cadr l) (caddr l)))
  50.                         n (reverse n)
  51.                   ) ;_ setq
  52.                   (while l
  53.                     (setq n (append n
  54.                                     (list (assoc 10 l)
  55.                                           (cons 40 (cdr (assoc 41 l)))
  56.                                           (cons 41 (cdr (assoc 40 l)))
  57.                                           (cons 42 (- (cdr (assoc 42 l))))
  58.                                     ) ;_ list
  59.                             ) ;_ append
  60.                           l (cddddr l)
  61.                     ) ;_ setq
  62.                   ) ;_ while
  63.                   (entmod (append n (list (assoc 210 e))))
  64.                 ) ;_ lambda
  65.   ) ;_ setq

  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN ROUTINE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  68. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

  69.   (vl-load-com)

  70.   (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
  71.   (vla-startundomark *AcadDoc*)

  72.   (and (setq #SS (ssget "_:L" '((0 . "LINE,LWPOLYLINE,SPLINE"))))
  73.        (setq #Inc -1)
  74.        (while (setq #Ent (ssname #SS (setq #Inc (1+ #Inc))))
  75.          (cond
  76.            ;; Line
  77.            ((eq "LINE" (cdr (assoc 0 (entget #Ent))))
  78.             (entmod (mapcar '(lambda (x)
  79.                                (cond ((eq 10 (car x)) (cons 11 (cdr x)))
  80.                                      ((eq 11 (car x)) (cons 10 (cdr x)))
  81.                                      (T x)
  82.                                ) ;_ cond
  83.                              ) ;_ lambda
  84.                             (entget #Ent)
  85.                     ) ;_ mapcar
  86.             ) ;_ entmod
  87.            )
  88.            ;; LWPolyline
  89.            ((eq "LWPOLYLINE" (cdr (assoc 0 (entget #Ent)))) (_RevLWP #Ent))
  90.            ;; SPLINE
  91.            ((eq "SPLINE" (cdr (assoc 0 (entget #Ent)))) (vla-reverse (vlax-ename->vla-object #Ent)))
  92.          ) ;_ cond
  93.        ) ;_ foreach
  94.   ) ;_ and
  95.   (*error* nil)
  96.   (princ)
  97. ) ;_ defun



论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 4365个

财富等级: 富可敌国

发表于 2021-1-20 08:20:29 | 显示全部楼层
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

发表于 2021-1-21 10:33:54 | 显示全部楼层
跟大神学习学习!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 104个

财富等级: 日进斗金

发表于 2021-1-21 19:33:06 | 显示全部楼层
好东西,要好好的收藏了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1个

财富等级: 恭喜发财

发表于 2021-4-4 13:34:05 | 显示全部楼层
你知道的太晚了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-25 13:22 , Processed in 0.173409 second(s), 39 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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