Author Topic: mark many radius at middle point of arc at once  (Read 2998 times)

0 Members and 1 Guest are viewing this topic.

meja

  • Newt
  • Posts: 47
mark many radius at middle point of arc at once
« on: May 23, 2015, 10:02:57 PM »
I have a code like this below
Code - Auto/Visual Lisp: [Select]
  1. (defun c:darp (/ oldos ent obj elst plst blst p par pd i pt ssl)
  2. (setq oldos (getvar "osmode"))
  3. (setvar "osmode" 0)
  4. (setq ent (car (entsel "\n SELECT arc in lwpolyline "))
  5.         obj (vlax-ename->vla-object ent)
  6.         elst (entget ent)
  7.         plst (list)
  8.         blst (list)
  9. )
  10. (foreach a elst
  11.         (if (= (car a) 10)
  12.         (setq plst (append plst (list (cdr a))))
  13.         )
  14.         (if (= (car a) 42)
  15.         (setq blst (append blst (list (cdr a))))
  16.         )
  17. )
  18. (setq i 0)
  19. (foreach b blst
  20.         (if (not (equal b 0 0.000001))
  21.         (progn
  22.                 (setq p (nth i plst)
  23.                           par (vlax-curve-getparamatpoint obj p)
  24.                           pd (vlax-curve-getpointatparam obj (+ par 0.5))
  25.                 )
  26.                 (command "undo" "be")
  27.                 (setq ssl  (acet-explode ent))
  28.                 (setq pt (cdr (assoc 10 (entget (ssname ssl i)))))
  29.                 (command "undo" "e")
  30.                 (command "undo" 1)
  31.                 (command "dimradius" pd (list (/ (+ (car pt) (car pd)) 2) (/ (+ (cadr pt)
  32.  
  33. (cadr pd)) 2)))
  34.         )
  35.         )
  36.         (setq i (1+ i))
  37. )
  38. (setvar "osmode" oldos)
  39. )
  40.  

NOW.i want to mark many arcs at once in my landscape job
HOW CAN REPEAT FUNCTION DO IT?
« Last Edit: May 23, 2015, 10:52:05 PM by meja »

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: mark many radius at middle point of arc at once
« Reply #1 on: May 24, 2015, 06:09:57 AM »
Please try the following program:
Code - Auto/Visual Lisp: [Select]
  1. ;; Automatic Radial Dimensions  -  Lee Mac
  2. ;; Automatically generates radial dimensions for a selection of arcs & polylines with arc segments.
  3.  
  4. (defun c:dimrads ( / dimrad midang ent enx idx sel )
  5.  
  6.     (defun dimrad ( cen chd )
  7.         (eval
  8.             (list 'defun 'dimrad '( cen chd )
  9.                 (list 'vla-adddimradial
  10.                         (if (= 1 (getvar 'cvport))
  11.                             'paperspace
  12.                             'modelspace
  13.                         )
  14.                     )
  15.                    '(vlax-3D-point cen)
  16.                    '(vlax-3D-point chd)
  17.                    '(/ (distance cen chd) -2.0)
  18.                 )
  19.             )
  20.         )
  21.         (dimrad cen chd)
  22.     )
  23.  
  24.     (defun midang ( a1 a2 )
  25.         (if (< a2 a1) (midang a1 (+ a2 pi pi)) (/ (+ a1 a2) 2.0))
  26.     )
  27.  
  28.     (if
  29.         (setq sel
  30.             (ssget
  31.                '(   (-4 . "<OR")
  32.                         (0 . "ARC")
  33.                         (-4 . "<AND")
  34.                             (0 . "LWPOLYLINE")
  35.                             (-4 . "<>")
  36.                             (42 . 0.0)
  37.                         (-4 . "AND>")
  38.                     (-4 . "OR>")
  39.                 )
  40.             )
  41.         )
  42.         (repeat (setq idx (sslength sel))
  43.             (setq ent (ssname sel (setq idx (1- idx)))
  44.                   enx (entget ent)
  45.             )
  46.             (if (= "ARC" (cdr (assoc 0 enx)))
  47.                 (dimrad
  48.                     (trans (cdr (assoc 10 enx)) ent 0)
  49.                     (trans
  50.                         (polar
  51.                             (cdr (assoc 10 enx))
  52.                             (midang (cdr (assoc 50 enx)) (cdr (assoc 51 enx)))
  53.                             (cdr (assoc 40 enx))
  54.                         )
  55.                         ent 0
  56.                     )
  57.                 )
  58.                 (   (lambda ( lst )
  59.                         (mapcar
  60.                            '(lambda ( x y / b c p q r )
  61.                                 (if (not (equal 0.0 (setq b (cdr (assoc 42 x))) 1e-8))
  62.                                     (progn
  63.                                         (setq p (cdr (assoc 10 x))
  64.                                               q (cdr (assoc 10 y))
  65.                                               r (/ (* (distance p q) (1+ (* b b))) 4 b)
  66.                                               c (polar p (+ (angle p q) (- (/ pi 2) (* 2 (atan b)))) r)
  67.                                         )
  68.                                         (dimrad
  69.                                             (trans c ent 0)
  70.                                             (trans (polar c (midang (angle c p) (angle c q)) r) ent 0)
  71.                                         )
  72.                                     )
  73.                                 )
  74.                             )
  75.                             lst
  76.                             (if (= 1 (logand 1 (cdr (assoc 70 enx))))
  77.                                 (append (cdr lst) (list (car lst)))
  78.                                 (cdr lst)
  79.                             )
  80.                         )
  81.                     )
  82.                     (LM:lwvertices enx)
  83.                 )
  84.             )
  85.         )
  86.     )
  87.     (princ)
  88. )
  89.  
  90. ;; LW Vertices  -  Lee Mac
  91. ;; Returns a list of lists in which each sublist describes
  92. ;; the position, starting width, ending width and bulge of the
  93. ;; vertex of a supplied LWPolyline
  94.  
  95. (defun LM:lwvertices ( e )
  96.     (if (setq e (member (assoc 10 e) e))
  97.         (cons
  98.             (list
  99.                 (assoc 10 e)
  100.                 (assoc 40 e)
  101.                 (assoc 41 e)
  102.                 (assoc 42 e)
  103.             )
  104.             (LM:lwvertices (cdr e))
  105.         )
  106.     )
  107. )
  108.  

meja

  • Newt
  • Posts: 47
Re: mark many radius at middle point of arc at once
« Reply #2 on: May 24, 2015, 12:06:15 PM »
THX LEE,MY BIG SAINT OF LISP 8-)

I MODIFY CODE LIKE THIS
Code - Auto/Visual Lisp: [Select]
  1. (defun c:DRO  ()
  2.  
  3. &#65288;setvar "DIMTIX" 1&#65289; (setvar "DIMSOXD"     1)
  4.  
  5.  (setvar "DIMTMOVE"    1)  (setvar "DIMATFIT"     0)
  6.  
  7.  (setvar "DIMTOFL"     0)
  8.  
  9. (setvar "DIMTAD" 1)
  10.  
  11. (setq objEnt (entsel "\n Select a arc... "))
  12.      
  13. (setq pt (osnap (cadr objEnt) "_midp"))
  14.  
  15.  
  16. (command "dimradius" pt "" )
  17.  
  18.  (princ)
  19.  
  20. )

how to repeat?

It is hard to newbie
« Last Edit: May 25, 2015, 01:48:48 AM by meja »

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: mark many radius at middle point of arc at once
« Reply #3 on: May 24, 2015, 12:33:31 PM »
You're welcome! It was fun to write  :-)

meja

  • Newt
  • Posts: 47
Re: mark many radius at middle point of arc at once
« Reply #4 on: May 25, 2015, 09:23:57 PM »
LEE.another question , I hope dimstyle like the rightest dimradius? How to change the code you write?
PLS

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: mark many radius at middle point of arc at once
« Reply #5 on: May 26, 2015, 01:02:51 PM »
LEE.another question , I hope dimstyle like the rightest dimradius? How to change the code you write?
PLS

Change:
Code - Auto/Visual Lisp: [Select]
  1. (/ (distance cen chd) -2.0)
to:
Code - Auto/Visual Lisp: [Select]
  1. (/ (distance cen chd) 2.0)