乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 118|回复: 3

[编程交流] 帮助修改LISP(Break-Rou

[复制链接]

1

主题

4

帖子

4

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 17:29:02 | 显示全部楼层 |阅读模式
这是一个例程,我去掉了不必要的命令,然后我试图编辑它,但我的编辑似乎没有工作*我不是最好的,哈哈*。此例程允许您打断所有与选定对象相交的对象,效果很好,但我希望它打断这些对象,但以我可以选择的距离均匀偏移打断,而不是仅在点处打断。我正在使用autocad architectural desktop 2006。如果您还有什么需要知道的,请告诉我,我们将不胜感激
  1.   ;;;====[ BreakObjects.lsp ]====
  2. ;;; Author: Copyright© 2006,2007 Charles Alan Butler
  3. ;;; Contact   ***Had to delete in order to get past spam blocker
  4. ;;; Version:  1.3 April 9,2007
  5. ;;; Globalization by XANADU - ***Had to delete in order to get past spam
  6. ;;; Purpose: Break All selected objects
  7. ;;;    permitted objects are lines, lwplines, plines, splines,
  8. ;;;    ellipse, circles & arcs
  9. ;;;
  10. ;;;  Function  c:BreakTouching - Break objects touching the single Break object
  11. ;;;
  12. ;;; Sub_Routines:      
  13. ;;;    break_with      
  14. ;;;    ssget->vla-list
  15. ;;;    list->3pair     
  16. ;;;    onlockedlayer   
  17. ;;;    get_interpts Return a list of intersect points
  18. ;;;    break_obj  Break entity at break points in list
  19. ;;; Requirements: objects must have the same z-value
  20. ;;; Restrictions: Does not Break objects on locked layers
  21. ;;; Returns:  none
  22. ;;;
  23. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED     ;
  24. ;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR  ;
  25. ;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.            ;
  26. ;;;
  27. ;;;  You are hereby granted permission to use, copy and modify this
  28. ;;;  software without charge, provided you do so exclusively for
  29. ;;;  your own use or for use by others in your organization in the
  30. ;;;  performance of their normal duties, and provided further that
  31. ;;;  the above copyright notice appears in all copies and both that
  32. ;;;  copyright notice and the limited warranty and restricted rights
  33. ;;;  notice below appear in all supporting documentation.
  34. ;;;
  35. ;;+++++++++++++++++++++++
  36. ;; M A I N   S U B R O U T I N E                  
  37. ;;+++++++++++++++++++++++
  38.   
  39. (defun break_with (ss2brk ss2brkwith self / cmd intpts lst masterlist ss ssobjs
  40.                     onlockedlayer ssget->vla-list list->3pair
  41.                     get_interpts break_obj
  42.                    )
  43.    ;; ss2brk     selection set to break
  44.    ;; ss2brkwith selection set to use as break points
  45.    ;; self       when true will allow an object to break itself
  46.    ;;            note that plined will break at each vertex
  47.    (vl-load-com)
  48.   
  49.   
  50. ;;++++++++++++++++++++
  51. ;; S U B   F U N C T I O N S                     
  52. ;;++++++++++++++++++++
  53.   
  54.    (defun onlockedlayer (ename / entlst)
  55.      (setq entlst (tblsearch "LAYER" (cdr (assoc 8 (entget ename)))))
  56.      (= 4 (logand 4 (cdr (assoc 70 entlst))))
  57.    )
  58.    
  59.    (defun ssget->vla-list (ss / i ename lst)
  60.      (setq i -1)
  61.      (while (setq ename (ssname ss (setq i (1+ i))))
  62.        (setq lst (cons (vlax-ename->vla-object ename) lst))
  63.      )
  64.      lst
  65.    )
  66.   
  67.    (defun list->3pair (old / new)
  68.      (while (setq new (cons (list (car old) (cadr old) (caddr old)) new)
  69.                   old (cdddr old))
  70.      )
  71.      (reverse new)
  72.    )
  73.    
  74. ;;===============
  75. ;;  return a list of intersect points
  76. ;;===============
  77. (defun get_interpts (obj1 obj2 / iplist)
  78.    (if (not (vl-catch-all-error-p
  79.               (setq iplist (vl-catch-all-apply
  80.                              'vlax-safearray->list
  81.                              (list
  82.                                (vlax-variant-value
  83.                                  (vla-intersectwith obj1 obj2 acextendnone)
  84.                                ))))))
  85.      iplist
  86.    )
  87. )
  88.   
  89.   
  90. ;;================
  91. ;;  Break entity at break points in list
  92. ;;================
  93. (defun break_obj (ent brkptlst / brkobjlst en enttype maxparam closedobj
  94.                    minparam obj obj2break p1param p2 p2param
  95.                   )
  96.   
  97.    (setq obj2break ent
  98.          brkobjlst (list ent)
  99.          enttype   (cdr (assoc 0 (entget ent)))
  100.    )
  101.   
  102.    (foreach brkpt brkptlst
  103.      ;;  get last entity created via break in case multiple breaks
  104.      (if brkobjlst
  105.        (progn
  106.          ;;  if pt not on object x, switch objects
  107.          (if (not (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj2break brkpt)))
  108.              )
  109.            (foreach obj brkobjlst ; find the one that pt is on
  110.              (if (numberp (vl-catch-all-apply 'vlax-curve-getdistatpoint (list obj brkpt)))
  111.                (setq obj2break obj) ; switch objects
  112.              )
  113.            )
  114.          )
  115.        )
  116.      )
  117.   
  118.      ;;  Handle any objects that can not be used with the Break Command
  119.      ;;  using one point, gap of 0.000001 is used
  120.      (cond
  121.        ((and (= "SPLINE" enttype) ; only closed splines
  122.              (vlax-curve-isclosed obj2break))
  123.         (setq p1param (vlax-curve-getparamatpoint obj2break brkpt)
  124.               p2      (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))
  125.         )
  126.         (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
  127.        )
  128.        ((= "CIRCLE" enttype) ; break the circle
  129.         (setq p1param (vlax-curve-getparamatpoint obj2break brkpt)
  130.               p2      (vlax-curve-getpointatparam obj2break (+ p1param 0.000001))
  131.         )
  132.         (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans p2 0 1))
  133.         (setq enttype "ARC")
  134.        )
  135.        ((and (= "ELLIPSE" enttype) ; only closed ellipse
  136.              (vlax-curve-isclosed obj2break))
  137.         ;;  Break the ellipse, code borrowed from Joe Burke  6/6/2005
  138.         (setq p1param  (vlax-curve-getparamatpoint obj2break brkpt)
  139.               p2param  (+ p1param 0.000001)
  140.               minparam (min p1param p2param)
  141.               maxparam (max p1param p2param)
  142.               obj      (vlax-ename->vla-object obj2break)
  143.         )
  144.         (vlax-put obj 'startparameter maxparam)
  145.         (vlax-put obj 'endparameter (+ minparam (* pi 2)))
  146.        )
  147.       
  148.        ;;=====================
  149.        (t  ;   Objects that can be broken     
  150.         (setq closedobj (vlax-curve-isclosed obj2break))
  151.         (command "._break" obj2break "_non" (trans brkpt 0 1) "_non" (trans brkpt 0 1))
  152.         (if (not closedobj) ; new object was created
  153.             (setq brkobjlst (cons (entlast) brkobjlst))
  154.         )
  155.        )
  156.      )
  157.    )
  158. )
  159.    ;;++++++++++++++++++
  160.    ;;   S T A R T   H E R E                        
  161.    ;;++++++++++++++++++
  162.      (if (and ss2brk ss2brkwith)
  163.      (progn
  164.        ;;  CREATE a list of entity & it's break points
  165.        (foreach obj (ssget->vla-list ss2brk) ; check each object in ss2brk
  166.          (if (not (onlockedlayer (vlax-vla-object->ename obj)))
  167.            (progn
  168.              (setq lst nil)
  169.              ;; check for break pts with other objects in ss2brkwith
  170.              (foreach intobj (ssget->vla-list ss2brkwith)
  171.                (if (and (or self (not (equal obj intobj)))
  172.                         (setq intpts (get_interpts obj intobj))
  173.                    )
  174.                  (setq lst (append (list->3pair intpts) lst)) ; entity w/ break points
  175.                )
  176.              )
  177.              (if lst
  178.                (setq masterlist (cons (cons (vlax-vla-object->ename obj) lst) masterlist))
  179.              )
  180.            )
  181.          )
  182.        )
  183.        ;;  masterlist = ((ent brkpts)(ent brkpts)...)
  184.        (if masterlist
  185.          (foreach obj2brk masterlist
  186.            (break_obj (car obj2brk) (cdr obj2brk))
  187.          )
  188.        )
  189.        )
  190.    )
  191. ;;===========
  192.   
  193. )
  194. (prompt "\nBreak Routines Loaded, Enter BreakTouching to run.")
  195. (princ)
  196. ;;===========
  197. ;;  Break many objects with a selected objects
  198. ;;  Selected Objects create ss to be broken   
  199. ;;===========
  200. (defun c:BreakTouching (/ cmd ss1 ss2)
  201.    ;;  get all objects touching entities in the sscross
  202.    ;;  limited obj types to "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"
  203.    (defun gettouching (sscros / ss lst lstb lstc objl)
  204.      (and
  205.        (setq lstb (vl-remove-if 'listp (mapcar 'cadr (ssnamex sscros)))
  206.              objl (mapcar 'vlax-ename->vla-object lstb)
  207.        )
  208.        (setq
  209.          ss (ssget "_A" (list (cons 0 "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE")
  210.                               (cons 410 (getvar "ctab"))))
  211.        )
  212.        (setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  213.        (setq lst (mapcar 'vlax-ename->vla-object lst))
  214.        (mapcar
  215.          '(lambda (x)
  216.             (mapcar
  217.               '(lambda (y)
  218.                  (if (not
  219.                        (vl-catch-all-error-p
  220.                          (vl-catch-all-apply
  221.                            '(lambda ()
  222.                               (vlax-safearray->list
  223.                                 (vlax-variant-value
  224.                                   (vla-intersectwith y x acextendnone)
  225.                                 ))))))
  226.                    (setq lstc (cons (vlax-vla-object->ename x) lstc))
  227.                  )
  228.                ) objl)
  229.           ) lst)
  230.      )
  231.      lstc
  232.    )
  233.    (command "._undo" "_begin")
  234.    (setq cmd (getvar "CMDECHO"))
  235.    (setvar "CMDECHO" 0)
  236.    (setq ss1 (ssadd))
  237.    ;;  get objects to break
  238.    (if (and (not (prompt "\nSelect object(s) to break with & press enter: "))
  239.             (setq ss2 (ssget '((0 . "LINE,ARC,SPLINE,LWPOLYLINE,POLYLINE,CIRCLE,ELLIPSE"))))
  240.             (mapcar '(lambda (x) (ssadd x ss1)) (gettouching ss2))
  241.        )
  242.      (break_with ss1 ss2 nil) ; ss2break ss2breakwith (flag nil = not to break with self)
  243.    )
  244.    (setvar "CMDECHO" cmd)
  245.    (command "._undo" "_end")
  246.    (princ)
  247. )
回复

使用道具 举报

1

主题

4

帖子

4

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 18:00:20 | 显示全部楼层
为了适应一篇帖子,我不得不删减所有内容,但这是原文,因为可能我删除了我日常生活中需要的东西:不确定:哈哈
全垒打。lsp
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 18:24:59 | 显示全部楼层
也许如果你问一下这个套路的作者。
较新的版本将允许空白。
一些新事物加入到日常生活中。
http://www.theswamp.org/index.php?topic=10370.msg293043#msg293043
 
修订版1.6可在此处找到
http://www.theswamp.org/index.php?topic=10370.0
回复

使用道具 举报

1

主题

4

帖子

4

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 18:38:40 | 显示全部楼层
*面部手掌*:Dyeah*现在感觉有点不舒服
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 16:41 , Processed in 1.247193 second(s), 60 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表