Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add segment to a leader.

10 REPLIES 10
Reply
Message 1 of 11
kpennell
995 Views, 10 Replies

Add segment to a leader.

Hey all.

 

I've managed to retrieve the important points of a leader with the following code:

 

(setq edata (entget (entlast)))

(setq leader? (cdr (assoc 0 edata)))

 

(cond

((= leader? "LEADER")())

(T(setq edata (cdr (entget (car (entsel "\nPick a leader: "))))))

)

 

(setq edata10 (member (assoc 10 edata) edata))

(setq listlength (length edata10))

 

(setq WCSLastPoint (cdr (nth (- listlength 6) edata10))); last point in WCS

(setq UCSLastPoint (trans WCSLastPoint 0 1))

(setq WCS2ndLastPoint (cdr (nth (- listlength 7) edata10))); second last point in WCS

(setq UCS2ndLastPoint (trans WCS2ndLastPoint 0 1))

 

(setq lastpointX (car UCSLastPoint))

(setq 2ndlastpointX (car UCS2ndLastPoint))

 

(cond

((> lastpointX 2ndlastpointX)(setq justify "Left"))

((< lastpointX 2ndlastpointX)(setq justify "Right"))

(T(Alert "The last segment of the leader is vertical"))

)

 

What I'd like to do is add a horizontal segment of a known length to the leader, obviously based on the last point.  I have to assume that the user is in the appropriate UCS for this, but I can trouble shoot for that later.

 

What do I do here?  subst old list iwth a new list and apply it to the entity somehow?

 

Thanks much

KP

10 REPLIES 10
Message 2 of 11
pbejse
in reply to: kpennell


@kpennell wrote:

Hey all.

   

What I'd like to do is add a horizontal segment of a known length to the leader, obviously based on the last point.  I have to assume that the user is in the appropriate UCS for this, but I can trouble shoot for that later.

 

What do I do here?  subst old list iwth a new list and apply it to the entity somehow?

 

Thanks much

KP



KP

would this be right after you create the leader?

(setq edata (entget (entlast)))

(setq leader? (cdr (assoc 0 edata)))

 

or

Modify an existing leader?

((= leader? "LEADER")())

(T(setq edata (cdr (entget (car (entsel "\nPick a leader: "))))))

 

Message 3 of 11
kpennell
in reply to: kpennell

Hey pbejse,

 

Yeah I aleady have the entity and the last two points of the leader, indicating which way the horizontal line should go, if it's justified right or left.  I did notice in your post though, that the code I posted did not show up, but other portions of my post did (something weird?).

 

Like I said, I'd like to take an existing leader and add a horizontal line segment (add an assoc 10 list) of a known length to the leader that was last created or user-selected.  I'm not sure how to substitute the dxf codes.

 

Thanks

KP

Message 4 of 11
pbejse
in reply to: kpennell


@kpennell wrote:

Hey pbejse,

 

Yeah I aleady have the entity and the last two points of the leader, indicating which way the horizontal line should go, if it's justified right or left.  I did notice in your post though, that the code I posted did not show up, but other portions of my post did (something weird?).

 

Like I said, I'd like to take an existing leader and add a horizontal line segment (add an assoc 10 list) of a known length to the leader that was last created or user-selected.  I'm not sure how to substitute the dxf codes.

 

Thanks

KP


I dont have cad with me right now KP.  I personally use vl-put-coordinates , another alternative is to recreate the leader via entmake. I'll get back to you after i get my hands on Acad.

 


 

Message 5 of 11
kpennell
in reply to: kpennell

Yeah, I've found some posts regarding the vl-put-coordinates, but I don't understand the syntax, though I think it's the best way to go to modify something existing, rather than deleting it and re-creating it.

 

Thanks for your attention on this.  I look forward to it.

 

KP

Message 6 of 11
pbejse
in reply to: kpennell

Alright KP here we go.

What is the length of the landing? are the existing leader entities only have tow points?

 

Message 7 of 11
kpennell
in reply to: kpennell

3/32 is the landing length, and no, it's not always two points.  That's why in the code I do have developed, it's getting the last and second last point to determine the proper justification.

 

Thanks

KP

Message 8 of 11
pbejse
in reply to: kpennell


@kpennell wrote:

3/32 is the landing length, and no, it's not always two points.  That's why in the code I do have developed, it's getting the last and second last point to determine the proper justification.

 

Thanks

KP



I see, what would happen if the leader is "VERTICAL" jsut show an alert box?

 BTW: if it has a landing but longer than 3/32 , what then?

Message 9 of 11
pbejse
in reply to: pbejse

Since you have not answered yet

 

try his for now, its a bit messy though

 

(defun c:Landing  (/ ss e pts)
(vl-load-com)     
      (setq ss (ssget ":L" '((0 . "LEADER"))))
      (repeat (sslength ss)
            (setq e (ssname ss 0))
            (setq pts (mapcar 'cdr
                              (vl-remove-if-not
                                    '(lambda (x) (= (car x) 10))
                                    (entget e))))
            (vlax-put
                  (vlax-ename->vla-object e)
                  'coordinates
                  (apply
                        'append
                        (list
                              (vlax-get
                                    (vlax-ename->vla-object
                                          e)
                                    'Coordinates)
                              (polar
                                    (last pts)
                                    (if (> (caar pts)
                                           (car (last pts)))
                                          pi
                                          0.0)
                                    0.09375))))
            (ssdel e ss)
            )
      (princ)
      )

 

Not sure if i got the correct landing length. try it and tell me what you think. then i'll get back to you tomorrow.

 

HTH

Message 10 of 11
kpennell
in reply to: kpennell

works great.  tried it with several configurations, and worked.

 

huge thanks mate.

 

as for the tidiness, what would you do?  WIsh I knew more about vl syntax.

 

KP

Message 11 of 11
pbejse
in reply to: kpennell


@kpennell wrote:

works great.  tried it with several configurations, and worked.

 

huge thanks mate.

 KP



You are welocme KP. Glad i could help.

@kpennell wrote:

as for the tidiness, what would you do?  WIsh I knew more about vl syntax.


Nothing really, jus the usual bells and whistles.Last night i wrote  the code in haste.

 Anyhoo, here's a cleaner version (not much different though)

 

(defun c:Landing  (/ ss e pts)
(vl-load-com)     
     (if (setq ss (ssget ":L" '((0 . "LEADER"))))
       (repeat (sslength ss)
             (setq e (ssname ss 0))
             (setq pts (mapcar 'cdr
                               (vl-remove-if-not
                                     '(lambda (x) (= (car x) 10))
                                     (entget e))))
             (vlax-put
                   (vlax-ename->vla-object e)
                   'coordinates
                   (apply
                         'append
                         (list
                               (apply 'append pts)
                               (polar
                                     (last pts)
                                     (if (> (caar pts)
                                            (car (last pts)))
                                           pi
                                           0.0)
                                     0.09375))))
             (ssdel e ss)
             )(princ "\nNo Leader entity selected"))
      (princ)
      )

 

Cheers KP

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost