Automating Leader Movement to Circle Centers for Multiple Locations

Automating Leader Movement to Circle Centers for Multiple Locations

ishaq03
Advocate Advocate
750 Views
8 Replies
Message 1 of 9

Automating Leader Movement to Circle Centers for Multiple Locations

ishaq03
Advocate
Advocate

I am currently working on a project that involves several locations where I need to move the leader lines to the centre of circles. Manually adjusting each leader is quite time-consuming, given the number of locations I am dealing with.

I wanted to ask if there is an automated solution or a LISP routine that can help speed up this process by moving all leaders to the centre of the selected circles at once. Ideally, I would like a way to select multiple circles and corresponding leaders and have the leaders automatically snapped to the centre of the circles.

Any help or guidance would be greatly appreciated

ishaq03_2-1725887589397.png

 

0 Likes
Accepted solutions (1)
751 Views
8 Replies
Replies (8)
Message 2 of 9

ishaq03
Advocate
Advocate

Hi Every one,

 

I’d appreciate any guidance as soon as possible due to the urgency of the task

0 Likes
Message 3 of 9

hosneyalaa
Advisor
Advisor

Capture1.JPG

0 Likes
Message 4 of 9

ishaq03
Advocate
Advocate

@hosneyalaa 

What?

0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

Some guidance, without spelling it all out....

 

If LDATA is the entity data list of a Leader, and CDATA is the entity data list of a Circle, then this moves the Leader's arrowhead to the center of the Circle:

(entmod (subst (assoc 10 CDATA) (assoc 10 LDATA) LDATA))

Fortunately, it substitutes the Circle center into the first DXF-10 entry of the Leader, not all of them, and that is always the arrowhead location.  It's very convenient that they both use the same DXF number, so you can substitute that entry wholesale, and don't need to extract the point coordinates.

 

So finding the pairs is maybe the more involved part.  I expect, if your drawing is representative, that you could select only the Leaders, and for each, do a Crossing-Window selection in (ssget), building a little box around the arrowhead location, looking for a Circle, and if it finds one, do the above substitution.

Kent Cooper, AIA
0 Likes
Message 6 of 9

CADaSchtroumpf
Advisor
Advisor

For try: copy/paste the code directely in command line

((lambda ( / ss n dxf_ent pt_cen rad lg pt_up pt_bt ss_ml i dxf_ml dxf_l dxf_mt)
  (setq ss (ssget '((0 . "CIRCLE"))))
  (cond
    (ss
      (repeat (setq n (sslength ss))
        (setq
          dxf_ent (entget (ssname ss (setq n (1- n))))
          pt_cen (trans (cdr (assoc 10 dxf_ent)) 0 1)
          rad (cdr (assoc 40 dxf_ent))
          lg (sqrt (+ (* rad rad) (* rad rad)))
          pt_up (polar pt_cen (* pi 0.25) lg)
          pt_bt (polar pt_cen (+ pi (* pi 0.25)) lg)
          ss_ml (ssget "_C" pt_bt pt_up '((0 . "MULTILEADER")))
        )
        (cond
          (ss_ml
            (repeat (setq i (sslength ss_ml))
              (setq
                dxf_ml (entget (ssname ss_ml (setq i (1- i))))
                dxf_l (member '(304 . "LEADER_LINE{") dxf_ml)
                dxf_mt (reverse (cdr (member '(304 . "LEADER_LINE{") (reverse dxf_ml))))
              )
              (entmod
                (append
                  dxf_mt
                  (subst
                    (cons 10 pt_cen)
                    (assoc 10 dxf_l)
                    dxf_l
                  )
                )
              )
              (entupd (cdar dxf_ml))
            )
          )
        )
      )
    )
  )
  (prin1)
))
0 Likes
Message 7 of 9

CADaSchtroumpf
Advisor
Advisor
Accepted solution

@ishaq03 

Opps

Sorry I thought it was 'MULTILEADER', for simple 'LEADER' this should work.

 

((lambda ( / ss n dxf_ent pt_cen rad lg pt_up pt_bt ss_ml i dxf_ml)
  (setq ss (ssget '((0 . "CIRCLE"))))
  (cond
    (ss
      (repeat (setq n (sslength ss))
        (setq
          dxf_ent (entget (ssname ss (setq n (1- n))))
          pt_cen (trans (cdr (assoc 10 dxf_ent)) 0 1)
          rad (cdr (assoc 40 dxf_ent))
          lg (sqrt (+ (* rad rad) (* rad rad)))
          pt_up (polar pt_cen (* pi 0.25) lg)
          pt_bt (polar pt_cen (+ pi (* pi 0.25)) lg)
          ss_ml (ssget "_C" pt_bt pt_up '((0 . "LEADER")))
        )
        (cond
          (ss_ml
            (repeat (setq i (sslength ss_ml))
              (setq dxf_ml (entget (ssname ss_ml (setq i (1- i)))))
              (entmod
                (subst
                  (cons 10 (trans pt_cen 1 0))
                  (assoc 10 dxf_ml)
                  dxf_ml
                )
              )
              (entupd (cdar dxf_ml))
            )
          )
        )
      )
    )
  )
  (prin1)
))

 

 

0 Likes
Message 8 of 9

ishaq03
Advocate
Advocate

I used the LISP code you provided for aligning the leader with the center of a circle object, and it has been very helpful. I would now like to request an enhancement to this code.

Would it be possible to modify the code so that it works with block objects as well? Specifically, I would like the leader to move to the center of a block object’s insertion point, instead of the circle. This would greatly improve the functionality in my current workflow.

Your help in modifying the code would be much appreciated. Thank you in advance!

0 Likes
Message 9 of 9

CADaSchtroumpf
Advisor
Advisor

@ishaq03  a écrit :

Would it be possible to modify the code so that it works with block objects as well? Specifically, I would like the leader to move to the center of a block object’s insertion point, instead of the circle. This would greatly improve the functionality in my current workflow.


Maybe like this?

If suitable you can replace the anonymous function ((lambda with a (defun C: my_function

Don't forget to remove the last parenthesis of the code.

(vl-load-com)
((lambda ( / ss n dxf_ent pt_cen obj rad lg pt_up pt_bt ss_ml i dxf_ml)
  (setq ss (ssget '((0 . "CIRCLE,INSERT"))))
  (cond
    (ss
      (repeat (setq n (sslength ss))
        (setq
          dxf_ent (entget (ssname ss (setq n (1- n))))
          pt_cen (trans (cdr (assoc 10 dxf_ent)) 0 1)
          obj (vlax-ename->vla-object (cdar dxf_ent))
        )
        (cond
          ((eq (cdr (assoc 0 dxf_ent)) "INSERT")
            (vla-GetBoundingBox obj 'pmin 'pmax)
            (setq
              pt_bt (safearray-value pmin)
              pt_up (safearray-value pmax)
            )
          )
          (T
            (setq
              rad (cdr (assoc 40 dxf_ent))
              lg (sqrt (+ (* rad rad) (* rad rad)))
              pt_up (polar pt_cen (* pi 0.25) lg)
              pt_bt (polar pt_cen (+ pi (* pi 0.25)) lg)
            )
          )
        )
        (setq ss_ml (ssget "_C" pt_bt pt_up '((0 . "LEADER"))))
        (cond
          (ss_ml
            (repeat (setq i (sslength ss_ml))
              (setq dxf_ml (entget (ssname ss_ml (setq i (1- i)))))
              (entmod
                (subst
                  (cons 10 (trans pt_cen 1 0))
                  (assoc 10 dxf_ml)
                  dxf_ml
                )
              )
              (entupd (cdar dxf_ml))
            )
          )
        )
      )
    )
  )
  (prin1)
))

 

0 Likes