乐筑天下

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

[编程交流] 自动编号和长度

[复制链接]

7

主题

30

帖子

23

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 18:32:42 | 显示全部楼层 |阅读模式
嗨,有人能帮我吗?我没有任何关于autolisp的内容,我需要一个例程,可以自动编号,也可以一次性获取多项式的长度。我还需要输入startnumber的可能性。
如果可能的话,多段线的数量和长度必须放在多段线的上方和中间。
谢谢
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:38:02 | 显示全部楼层
这有帮助吗?
 
http://www.cadtutor.net/forum/showthread.php?t=35234
回复

使用道具 举报

7

主题

30

帖子

23

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 18:39:51 | 显示全部楼层
嘿,李,谢谢你的Lisp程序。这几乎是我需要的。关于自动编号和对齐,这很完美,但我仍然忽略了多段线的长度。
有关更多信息,请参阅图片。
再次感谢您的帮助。
 

                               
登录/注册后可看大图
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:45:27 | 显示全部楼层
试一试,它使用字段:
 
  1. (defun c:PLen ( / *error* doc spc ent uFlag tStr )  
  2. (vl-load-com)
  3. ;; Lee Mac  ~  21.04.10
  4. (defun *error* (msg)
  5.    (and uFlag (vla-EndUndoMark doc))
  6.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  7.        (princ (strcat "\n** Error: " msg " **")))
  8.    (princ))
  9. (setq doc (vla-get-ActiveDocument
  10.              (vlax-get-acad-object))
  11.       
  12.        spc (if (or (eq AcModelSpace (vla-get-ActiveSpace doc))
  13.                    (eq :vlax-true   (vla-get-MSpace doc)))
  14.              (vla-get-ModelSpace doc)
  15.              (vla-get-PaperSpace doc)))
  16. (setq *num (cond ( *num ) ( 1 ))
  17.        *num (1- (cond ((getint (strcat "\nSpecify Starting Number <" (itoa *num) "> : ")))
  18.                       (*num))))
  19. (while (setq ent (CurveifFoo (lambda (ent)
  20.                                 (and (isCurveObject ent)
  21.                                      (vlax-property-available-p
  22.                                        (vlax-ename->vla-object ent) 'Length)))
  23.                     (strcat "\nSelect Curve Number [" (itoa (setq *num (1+ *num))) "] : ")))
  24.    (setq uFlag (not (vla-StartUndoMark doc))
  25.          tStr  (strcat (itoa *num) "- %<\\AcObjProp Object(%<\\_ObjId "
  26.                        (GetObjectID (vlax-ename->vla-object ent)) ">%).Length \\f "%lu6\>%"))
  27.    (AlignObjtoCurve
  28.      (MCMText spc (getvar 'VIEWCTR) 0. tStr) ent (getvar 'TEXTSIZE))
  29.    (setq uFlag (vla-EndUndoMark doc)))
  30. (princ))
  31. (defun GetObjectID ( obj )
  32. (if (eq "X64" (strcase (getenv "PROCESSOR_ARCHITECTURE")))
  33.    (vlax-invoke-method (vla-get-Utility
  34.                          (vla-get-ActiveDocument
  35.                            (vlax-get-acad-object))) 'GetObjectIdString obj :vlax-false)
  36.    (itoa (vla-get-Objectid obj))))
  37. (defun MCMText (block point width string / o)
  38. (vla-put-AttachmentPoint
  39.    (setq o (vla-AddMText block
  40.              (vlax-3D-point point) width string))
  41.    acAttachmentPointMiddleCenter)
  42. o)
  43. (defun isCurveObject (ent)
  44. (not
  45.    (vl-catch-all-error-p
  46.      (vl-catch-all-apply
  47.        (function vlax-curve-getEndParam) (list ent)))))
  48. (defun CurveifFoo ( foo str / sel ent )
  49. (while
  50.    (progn
  51.      (setq sel (entsel str))
  52.      
  53.      (cond (  (vl-consp sel)
  54.               (if (not (foo (setq ent (car sel))))
  55.                 (princ "\n** Invalid Object Selected **"))))))
  56. ent)
  57.    
  58. (defun AlignObjToCurve ( obj ent o / *error* msg gr code data pt cAng lAng )
  59. (vl-load-com)
  60. (defun *error* (msg)
  61.    (and obj   (not (vlax-erased-p obj)) (vla-delete obj))
  62.    (and uFlag (vla-EndUndoMark doc))
  63.    
  64.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  65.        (princ (strcat "\n** Error: " msg " **")))
  66.    (princ))   
  67. (or *Mac$Per* (setq *Mac$Per* (/ pi 2.)))
  68. (or *Mac$Off* (setq *Mac$Off* 1.))
  69. (setq msg  (princ "\n<< [+/-] for offset, [P]erpendicularity toggle >>"))
  70. (while
  71.    (progn
  72.      (setq gr (grread 't 15 0) code (car gr) data (cadr gr))
  73.      
  74.      (cond (  (and (= 5 code) (listp data))
  75.             
  76.               (setq pt   (vlax-curve-getClosestPointto ent data)
  77.                     cAng (angle pt data)
  78.                     lAng (+ cAng *Mac$Per*))
  79.             
  80.               (cond (  (and (> lAng (/ pi 2)) (<= lAng pi))
  81.                        (setq lAng (- lAng pi)))
  82.                   
  83.                     (  (and (> lAng pi) (<= lAng (/ (* 3 pi) 2)))
  84.                        (setq lAng (+ lAng pi))))
  85.             
  86.               (vla-put-InsertionPoint Obj
  87.                 (vlax-3D-point (polar pt cAng (* o *Mac$Off*))))
  88.               (vla-put-Rotation Obj lAng)
  89.             
  90.             t)
  91.            
  92.            (  (= 2 code)
  93.             
  94.               (cond (  (vl-position data '(43 61))
  95.                      
  96.                        (setq *Mac$Off* (+ *Mac$Off* 0.1)))
  97.                     
  98.                     (  (= 45 data)
  99.                      
  100.                        (setq *Mac$Off* (- *Mac$Off* 0.1)))
  101.                     
  102.                     (  (vl-position data '(80 112))
  103.                      
  104.                        (setq *Mac$Per* (- (/ pi 2.) *Mac$Per*)))
  105.                     
  106.                     (  (vl-position data '(13 32))
  107.                      
  108.                        (setq Obj nil))
  109.                     
  110.                     (t )))
  111.            
  112.            (  (and (= 3 code) (listp data))
  113.             
  114.               (setq pt   (vlax-curve-getClosestPointto ent data)
  115.                     cAng (angle pt data)
  116.                     lAng (+ cAng *Mac$Per*))
  117.               
  118.               (cond (  (and (> lAng (/ pi 2)) (<= lAng pi))
  119.                        (setq lAng (- lAng pi)))
  120.                      
  121.                     (  (and (> lAng pi) (<= lAng (/ (* 3 pi) 2)))
  122.                        (setq lAng (+ lAng pi))))
  123.               
  124.               (vla-put-InsertionPoint Obj
  125.                 (vlax-3D-point (polar pt cAng (* o *Mac$Off*))))
  126.               (vla-put-Rotation Obj lAng)
  127.               
  128.               (setq Obj nil))
  129.            
  130.            (  (= 25 code) (setq Obj nil))
  131.            
  132.            (t ))))
  133. data)

 
回复

使用道具 举报

6

主题

249

帖子

247

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-5 18:49:36 | 显示全部楼层
更新为包括圆和圆弧
 
  1. (defun c:PLab (/ obj)
  2. ;; Label each LWPolyline segment with number and distance
  3. ;; Alan J. Thompson, 04.21.10
  4. (if (and (setq obj (car (entsel "\nSelect LWPolyline: ")))
  5.           (or (eq "LWPOLYLINE" (cdr (assoc 0 (entget obj))))
  6.               (alert "Invalid object!")
  7.           )
  8.           (setq obj (vlax-ename->vla-object obj))
  9.      )
  10.    ((lambda (n l / a b)
  11.       (while (nth (1+ (setq n (1+ n))) l)
  12.         (progn
  13.           (vla-put-rotation
  14.             (AT:MText (vlax-3d-point
  15.                         (vlax-curve-GetClosestPointTo
  16.                           obj
  17.                           (mapcar (function (lambda (x y) (/ (+ x y) 2.)))
  18.                                   (setq a (nth n l))
  19.                                   (setq b (nth (1+ n) l))
  20.                           )
  21.                         )
  22.                       )
  23.                       (strcat (itoa (1+ n))
  24.                               " - "
  25.                               (rtos (abs (- (vlax-curve-getDistAtPoint obj a)
  26.                                             (vlax-curve-getDistAtPoint obj b)
  27.                                          )
  28.                                     )
  29.                               )
  30.                       )
  31.                       0.
  32.                       nil
  33.                       8
  34.             )
  35.             (angle a b)
  36.           )
  37.         )
  38.       )
  39.     )
  40.      -1
  41.      (AT:ListGroupByNumber (vlax-get obj 'Coordinates) 2)
  42.    )
  43. )
  44. (princ)
  45. )
  46. ;;; Add MText to drawing
  47. ;;; Pt - MText insertion point
  48. ;;; Str - String to place in created MText object
  49. ;;; Wd - Width of MText object (if nil, will be 0 width)
  50. ;;; Lay - Layer to place Mtext object on (nil for current)
  51. ;;; Jus - Justification # for Mtext object
  52. ;;;       1 or nil= TopLeft
  53. ;;;       2= TopCenter
  54. ;;;       3= TopRight
  55. ;;;       4= MiddleLeft
  56. ;;;       5= MiddleCenter
  57. ;;;       6= MiddleRight
  58. ;;;       7= BottomLeft
  59. ;;;       8= BottomCenter
  60. ;;;       9= BottomRight
  61. ;;; Alan J. Thompson, 05.23.09 / 04.09.10
  62. (defun AT:MText (Pt Str Wd Lay Jus / Wd s o)
  63. (or Wd (setq Wd 0.))
  64. (setq s  (if (or (eq acmodelspace
  65.                       (vla-get-activespace
  66.                         (cond (*AcadDoc*)
  67.                               ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
  68.                         )
  69.                       )
  70.                   )
  71.                   (eq :vlax-true (vla-get-mspace *AcadDoc*))
  72.               )
  73.             (vla-get-modelspace *AcadDoc*)
  74.             (vla-get-paperspace *AcadDoc*)
  75.           )
  76.        Pt (cond ((vl-consp Pt) (vlax-3d-point Pt))
  77.                 ((eq (type Pt) 'variant) Pt)
  78.           )
  79. )
  80. (setq o (vla-addMText s Pt Wd (vl-princ-to-string Str)))
  81. (and Lay (tblsearch "layer" Lay) (vla-put-layer o Lay))
  82. (cond ((vl-position Jus '(1 2 3 4 5 6 7 8 9))
  83.         (vla-put-AttachmentPoint o Jus)
  84.         (vla-put-InsertionPoint o Pt)
  85.        )
  86. )
  87. o
  88. )
  89. ;;; Group items in list based on specified number
  90. ;;; L - List to process
  91. ;;; # - Number of items for grouping
  92. ;;; Alan J. Thompson, 03.26.10
  93. (defun AT:ListGroupByNumber (L # / n g f)
  94. (setq n -1)
  95. (while (> (1- (length L)) n)
  96.    (repeat # (setq g (cons (nth (setq n (1+ n)) L) g)))
  97.    (setq f (cons (reverse g) f)
  98.          g nil
  99.    ) ;_ setq
  100. ) ;_ while
  101. (reverse f)
  102. ) ;_ defun
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:52:53 | 显示全部楼层
我想艾伦疯了
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-5 18:57:10 | 显示全部楼层
爆笑
我确实让他们有点失控了。自从你按照MP的代码做了那个边界框例程之后,除了使用mapcar(或者像我所知道的那样定义函数)之外,我一直像个疯子一样喜欢和滥用lambda。
 
我是说,看看这个:
  1. (defun c:PLen ( / *error* doc spc ent obj uFlag tStr )  
  2. (vl-load-com)
  3. ;; Lee Mac  ~  21.04.10
  4. (defun *error* (msg)
  5.    (and uFlag (vla-EndUndoMark doc))
  6.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  7.        (princ (strcat "\n** Error: " msg " **")))
  8.    (princ))
  9. (setq doc (vla-get-ActiveDocument
  10.              (vlax-get-acad-object))
  11.       
  12.        spc (if (or (eq AcModelSpace (vla-get-ActiveSpace doc))
  13.                    (eq :vlax-true   (vla-get-MSpace doc)))
  14.              (vla-get-ModelSpace doc)
  15.              (vla-get-PaperSpace doc)))
  16. (setq *num (cond ( *num ) ( 1 ))
  17.        *num (1- (cond ((getint (strcat "\nSpecify Starting Number <" (itoa *num) "> : ")))
  18.                       (*num))))
  19. (while (setq ent (CurveifFoo (lambda (ent)
  20.                                 (and (isCurveObject ent)
  21.                                      (vl-some
  22.                                        (function
  23.                                          (lambda ( property )
  24.                                            (vlax-property-available-p
  25.                                              (vlax-ename->vla-object ent) property)))
  26.                                        '(Length ArcLength Circumference))))
  27.                     (strcat "\nSelect Curve Number [" (itoa (setq *num (1+ *num))) "] : ")))
  28.    (setq uFlag (not (vla-StartUndoMark doc))
  29.          tStr  (strcat (itoa *num) "- %<\\AcObjProp Object(%<\\_ObjId "
  30.                        (GetObjectID (setq obj (vlax-ename->vla-object ent))) ">%)."
  31.                        (vl-some
  32.                          (function
  33.                            (lambda ( property )
  34.                              (if (vlax-property-available-p obj (read property)) property)))
  35.                          '("Length" "ArcLength" "Circumference")) " \\f "%lu6\>%"))
  36.    (AlignObjtoCurve
  37.      (MCMText spc (getvar 'VIEWCTR) 0. tStr) ent (getvar 'TEXTSIZE))
  38.    (setq uFlag (vla-EndUndoMark doc)))
  39. (princ))
  40. (defun GetObjectID ( obj )
  41. (if (eq "X64" (strcase (getenv "PROCESSOR_ARCHITECTURE")))
  42.    (vlax-invoke-method (vla-get-Utility
  43.                          (vla-get-ActiveDocument
  44.                            (vlax-get-acad-object))) 'GetObjectIdString obj :vlax-false)
  45.    (itoa (vla-get-Objectid obj))))
  46. (defun MCMText (block point width string / o)
  47. (vla-put-AttachmentPoint
  48.    (setq o (vla-AddMText block
  49.              (vlax-3D-point point) width string))
  50.    acAttachmentPointMiddleCenter)
  51. o)
  52. (defun isCurveObject (ent)
  53. (not
  54.    (vl-catch-all-error-p
  55.      (vl-catch-all-apply
  56.        (function vlax-curve-getEndParam) (list ent)))))
  57. (defun CurveifFoo ( foo str / sel ent )
  58. (while
  59.    (progn
  60.      (setq sel (entsel str))
  61.      
  62.      (cond (  (vl-consp sel)
  63.               (if (not (foo (setq ent (car sel))))
  64.                 (princ "\n** Invalid Object Selected **"))))))
  65. ent)
  66.    
  67. (defun AlignObjToCurve ( obj ent o / *error* msg gr code data pt cAng lAng )
  68. (vl-load-com)
  69. (defun *error* (msg)
  70.    (and obj   (not (vlax-erased-p obj)) (vla-delete obj))
  71.    (and uFlag (vla-EndUndoMark doc))
  72.    
  73.    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  74.        (princ (strcat "\n** Error: " msg " **")))
  75.    (princ))   
  76. (or *Mac$Per* (setq *Mac$Per* (/ pi 2.)))
  77. (or *Mac$Off* (setq *Mac$Off* 1.))
  78. (setq msg  (princ "\n<< [+/-] for offset, [P]erpendicularity toggle >>"))
  79. (while
  80.    (progn
  81.      (setq gr (grread 't 15 0) code (car gr) data (cadr gr))
  82.      
  83.      (cond (  (and (= 5 code) (listp data))
  84.             
  85.               (setq pt   (vlax-curve-getClosestPointto ent data)
  86.                     cAng (angle pt data)
  87.                     lAng (+ cAng *Mac$Per*))
  88.             
  89.               (cond (  (and (> lAng (/ pi 2)) (<= lAng pi))
  90.                        (setq lAng (- lAng pi)))
  91.                   
  92.                     (  (and (> lAng pi) (<= lAng (/ (* 3 pi) 2)))
  93.                        (setq lAng (+ lAng pi))))
  94.             
  95.               (vla-put-InsertionPoint Obj
  96.                 (vlax-3D-point (polar pt cAng (* o *Mac$Off*))))
  97.               (vla-put-Rotation Obj lAng)
  98.             
  99.             t)
  100.            
  101.            (  (= 2 code)
  102.             
  103.               (cond (  (vl-position data '(43 61))
  104.                      
  105.                        (setq *Mac$Off* (+ *Mac$Off* 0.1)))
  106.                     
  107.                     (  (= 45 data)
  108.                      
  109.                        (setq *Mac$Off* (- *Mac$Off* 0.1)))
  110.                     
  111.                     (  (vl-position data '(80 112))
  112.                      
  113.                        (setq *Mac$Per* (- (/ pi 2.) *Mac$Per*)))
  114.                     
  115.                     (  (vl-position data '(13 32))
  116.                      
  117.                        (setq Obj nil))
  118.                     
  119.                     (t )))
  120.            
  121.            (  (and (= 3 code) (listp data))
  122.             
  123.               (setq pt   (vlax-curve-getClosestPointto ent data)
  124.                     cAng (angle pt data)
  125.                     lAng (+ cAng *Mac$Per*))
  126.               
  127.               (cond (  (and (> lAng (/ pi 2)) (<= lAng pi))
  128.                        (setq lAng (- lAng pi)))
  129.                      
  130.                     (  (and (> lAng pi) (<= lAng (/ (* 3 pi) 2)))
  131.                        (setq lAng (+ lAng pi))))
  132.               
  133.               (vla-put-InsertionPoint Obj
  134.                 (vlax-3D-point (polar pt cAng (* o *Mac$Off*))))
  135.               (vla-put-Rotation Obj lAng)
  136.               
  137.               (setq Obj nil))
  138.            
  139.            (  (= 25 code) (setq Obj nil))
  140.            
  141.            (t ))))
  142. data)
5λ表达式
 
你知道,我很惊讶你没有评论我放弃了结束行注释和变量赋值。
 
顺便说一句:我的三角测试(最后一个星期一)得了96分,其中2分被取消了,因为我忘了在一个问题上表示我的单位。如果你没有回答我的问题,我会完全迷失在那一部分。谢谢。
193250dyvivzjjk2y7ycka.jpg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:58:47 | 显示全部楼层
 
别担心,伙计,很高兴你一切顺利
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
438
发表于 2022-7-5 19:01:34 | 显示全部楼层
李Mac的普兰lisp工程伟大的什么我想要的,但有可能有一个将。。。
[列表=1]
  • 不进行自动编号。
  • 总长度值自动插入到多段线的中心/中点。
    在查找每条多段线的长度时,我希望加快速度。如果可能的话,我希望能够选择所有多段线,并让所有值自动插入到每个单独的多段线上。
     
    再次感谢,希望不要要求太多。
  • 回复

    使用道具 举报

    114

    主题

    1万

    帖子

    1万

    银币

    中流砥柱

    Rank: 25

    铜币
    543
    发表于 2022-7-5 19:06:31 | 显示全部楼层
    嗨,戈登,
     
    试一试,让我知道你(使用场)进展如何,
     
    [code]defunc:PlL[color=BLUE vl load com][color b];;李Mac ~ 29.04.10defunmsg[color=BLUE b]([/color b][color=BLUE wcmatch][color b]([/color b][color=BLUE b]“*中断,*取消*,*退出*”princ][color][color=BLUE strcat][color][n**错误:“[/color b][msg”**“princsetq[color]spc如果[color][color=RED或[color]eq[color]b][color][color=红色](vla get ActiveSpacesetqdoc[color=BLUE vla get ACTIVESTACT)([color=BLUE b]eq[color=BLUE vla get MSpacedoc color][/colorvla get模型空间[color]docvla get纸张空间[color]doc[color=BLUE if[color b]([/color b][color=BLUE b]b]-1[color]ssssget0“线,*折线”[color]而[color]setq[color]essname[color]ss[color=BLUE 1+/color]i[setqDerangle0。0。0。[color=BLUE b]]vlax曲线getFirstDerivevlax曲线getParamatPointesetqp中点e]]]]setq[color]MCMText spcp/[color=BLUE pi][color][color=BLUE pi][009999]2。[/color b](getvarTEXTSIZE0。strcat“%”。长度\\f \“%lu6 \”>%“[/color b]([/color=RED]colorvla put rotation[/colorObjMakeReadable Derprinc[color=RED b][color=REDdefunMCMText b][color=RED点宽度字符串/ovla放置附着点[color]setq[color]o[color][color=BLUE vla AddMText color]([/color b][color=BLUE BLUE vlax-3D-point b]acAttachmentPointMiddleCentervla放置插入点[color]o[color=Blue vlax-3D点[color b]点o([/颜色defun[color]使可读a[color=BLUE b][color=BLUE>[/color b]a[color=BLUE b][pi[color]2[color] [color]api[color]([/color[color=BLUE b]
    回复

    使用道具 举报

    发表回复

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

    本版积分规则

    • 微信公众平台

    • 扫描访问手机版

    • 点击图片下载手机App

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

    GMT+8, 2025-7-3 18:01 , Processed in 1.633275 second(s), 74 queries .

    © 2020-2025 乐筑天下

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