Jump to content

Justify Mleader text to the arrow.


aawilds

Recommended Posts

I have a bit a head scratcher. I want a lisp that when run I will be able to select the whole drawing and all the mleaders will automatically justify to the side that the leader and arrow is on. Occasionally our leaders get move and it is time consuming to change them individually. Any help would be greatly appreciated.

Link to comment
Share on other sites

Here you go .. does not check for locked layers.

(defun c:foo (/ pts s)
 (if (setq s (ssget "_X" '((0 . "multileader"))))
   (foreach ml	(mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex s)))
     (setq pts (vlax-invoke ml 'getleaderlinevertices 0))
     (cond ((equal (car pts) (cadddr pts) 1e- (print "Vertical leader.."))
    ((< (car pts) (cadddr pts)) (vla-put-textjustify ml 1))
    ((vla-put-textjustify ml 3))
     )
   )
 )
 (princ)
)
(vl-load-com)

Link to comment
Share on other sites

Thank you so much :D . I have got to learn the visual lisp functions and how to use them, because that is far simpler then what I was trying to do by changing DXF codes.

Link to comment
Share on other sites

Nice startup, Ron!

 

I just decided to experiment on what the heck is going on with your code, and played with this:

 

(defun C:test ( / SS i )
 (and 
   (setq SS (ssget "_:L" '((0 . "MULTILEADER"))))
   (repeat (setq i (sslength SS))
     (foo (ssname SS (setq i (1- i))))
   )
 )
 (princ)
)

(setq foo 
 (lambda ( e / e o L pts )
   
   (defun GroupByN ( n L / r )
     (repeat n (and L (setq r (cons (car L) r))) (setq L (cdr L)) r)
     (if L (cons (reverse r) (GroupByN n L)) (list (reverse r)))
   ); defun GroupByN
   
   (cond 
     (
       (and 
         ; (setq e (car (entsel "\nPick mleader: ")))
         (setq o (vlax-ename->vla-object e))
         (setq L (GroupByN 3 (vlax-invoke o 'GetLeaderLineVertices 0)))
         (setq pts (list (car L)(last L)))
       )
       (vl-some 
         (function
           (lambda ( x / xf yf al )
             (mapcar 'set '(xf yf al) x)
             (and
               (apply xf (append (mapcar 'car pts) (if (eq eq xf) (list 1e-1))))
               (apply yf (append (mapcar 'cadr pts) (if (eq eq yf) (list 1e-1))))
               (progn 
                 (vla-put-TextJustify o (eval al)) 
                 ; (alert (vl-symbol-name al)) 
                 T
               )
             )
           ); lambda
         ); function
         '(
           (eq > acAttachmentPointBottomCenter) ; OK
           (eq < acAttachmentPointTopCenter) ; OK 
           (< eq acAttachmentPointMiddleLeft) ; NOT
           (> eq acAttachmentPointMiddleRight) ; NOT
           (< < acAttachmentPointBottomLeft) ; OK
           (> < acAttachmentPointBottomRight) ; OK
           (< > acAttachmentPointTopLeft) ; OK
           (> > acAttachmentPointTopRight) ; OK
         ); list
       ); vl-some
     )
   ); cond
   (princ)
 ); lambda
); setq foo

 

I assume that the first point of the 'GetLeaderLineVertices method is the first point of the leader line (closest vertex to the text content) whereas the last point represents the arrowhead point - is that correct?

Link to comment
Share on other sites

Thank you so much :D . I have got to learn the visual lisp functions and how to use them, because that is far simpler then what I was trying to do by changing DXF codes.

 

Glad to help. DXF codes are nice but mleaders are much easier to manipulate via vla-* functions IMO.

Link to comment
Share on other sites

Nice startup, Ron!

 

I just decided to experiment on what the heck is going on with your code, and played with this:

 

(defun C:test ( / SS i )
 (and 
   (setq SS (ssget "_:L" '((0 . "MULTILEADER"))))
   (repeat (setq i (sslength SS))
     (foo (ssname SS (setq i (1- i))))
   )
 )
 (princ)
)

(setq foo 
 (lambda ( e / e o L pts )
   
   (defun GroupByN ( n L / r )
     (repeat n (and L (setq r (cons (car L) r))) (setq L (cdr L)) r)
     (if L (cons (reverse r) (GroupByN n L)) (list (reverse r)))
   ); defun GroupByN
   
   (cond 
     (
       (and 
         ; (setq e (car (entsel "\nPick mleader: ")))
         (setq o (vlax-ename->vla-object e))
         (setq L (GroupByN 3 (vlax-invoke o 'GetLeaderLineVertices 0)))
         (setq pts (list (car L)(last L)))
       )
       (vl-some 
         (function
           (lambda ( x / xf yf al )
             (mapcar 'set '(xf yf al) x)
             (and
               (apply xf (append (mapcar 'car pts) (if (eq eq xf) (list 1e-1))))
               (apply yf (append (mapcar 'cadr pts) (if (eq eq yf) (list 1e-1))))
               (progn 
                 (vla-put-TextJustify o (eval al)) 
                 ; (alert (vl-symbol-name al)) 
                 T
               )
             )
           ); lambda
         ); function
         '(
           (eq > acAttachmentPointBottomCenter) ; OK
           (eq < acAttachmentPointTopCenter) ; OK 
           (< eq acAttachmentPointMiddleLeft) ; NOT
           (> eq acAttachmentPointMiddleRight) ; NOT
           (< < acAttachmentPointBottomLeft) ; OK
           (> < acAttachmentPointBottomRight) ; OK
           (< > acAttachmentPointTopLeft) ; OK
           (> > acAttachmentPointTopRight) ; OK
         ); list
       ); vl-some
     )
   ); cond
   (princ)
 ); lambda
); setq foo

 

I assume that the first point of the 'GetLeaderLineVertices method is the first point of the leader line (closest vertex to the text content) whereas the last point represents the arrowhead point - is that correct?

 

From my test, the first point is the closest to the arrow.

Link to comment
Share on other sites

From my test, the first point is the closest to the arrow.

 

Short test confirmed this:

(and 
 (setq p ((lambda (L) (list (car L) (cadr L) (caddr L))) (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'GetLeaderLineVertices 0)))
 (entmakex (list (cons 0 "POINT") (cons 62 1) (cons 10 p)))
)

 

Thanks! :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...