Delete LEADER Vertex

Discussion in 'AutoCAD' started by jonesr, Jun 3, 2004.

  1. jonesr

    jonesr Guest

    I often receive drawings with "extra" vertices in LEADERS.Anyone have some
    automation to remove a vertex from a LEADER?
     
    jonesr, Jun 3, 2004
    #1
  2. jonesr

    John Uhden Guest

    Not offhand, but look into modifying the ActiveX 'Coordinates property.

    (Sorry, guys, for not being around; been really busy)
     
    John Uhden, Jun 3, 2004
    #2
  3. jonesr

    Jürg Menzi Guest

    Hi jonesr

    Try this function:

    (defun C:CleanLeaders ( / CurEnt CurObj CurSet EntCnt FltLst NewLst OldLst)
    (vl-load-com)
    (setq FltLst '((0 . "LEADER"))
    EntCnt 0
    )
    (if (setq CurSet (cond ((ssget "I" FltLst)) ((ssget FltLst))))
    (progn
    (while (setq CurEnt (ssname CurSet 0))
    (setq CurObj (vlax-ename->vla-object CurEnt)
    OldLst (vlax-get CurObj "Coordinates")
    )
    (if (> (length OldLst) 6) ;enough vertices?
    (progn
    (setq EntCnt (1+ EntCnt)
    NewLst (append
    (mapcar
    '(lambda (i)
    (nth i OldLst)
    ) '(0 1 2)
    )
    (reverse
    (mapcar
    '(lambda (i)
    (nth i (reverse OldLst))
    ) '(0 1 2)
    )
    )
    )
    )
    (vlax-put CurObj "Coordinates" NewLst)
    (vla-Update CurObj)
    )
    )
    (ssdel CurEnt CurSet)
    )
    (alert (strcat (itoa EntCnt) " Leader(s) cleaned..."))
    )
    )
    (princ)
    )

    Cheers
     
    Jürg Menzi, Jun 3, 2004
    #3
  4. jonesr

    John Uhden Guest

    Herman:

    It's time. :)

    What you need to add to your arsenal are Ken Alexander's contributions which I
    took the liberty to remold as follows:
    Oops. It doesn't say so, but their purpose is to convert a list of reals (as
    returned by (vlax-get Object 'Coordinates)), e.g. (x1 y1 z1 x2 y2 z2 ... xn yn
    zn) into a list of lists, e.g. ((x1 y1 z1)(x2 y2 z2)...(xn yn zn)). For 2D,
    such as LWPOLYLINEs, use the Double_Up... ((x1 y1)(x2 y2)...(xn yn)).

    Note that (vlax-get) will return a list, whereas (vla-get-coordinates) will
    return a more cumbersome variant that requires conversion to a list. Just MHO.
    ;;-------------------------------------------------
    ;; Functions originated by Ken Alexander (03-05-03)
    ;; that are 10X faster than @cv_parse_list, yet limited
    ;; to only pairs or triplets.
    ;; Thanks, Ken!
    ;; (01-02-04) corrected to (while old ...)
    ;; Revised (01-16-04) to increase speed thanks to Tony T's
    ;; example of using (while (setq ...))
    (defun @cv_double_up (old / new)
    (and
    old
    (while
    (setq new (cons (list (car old)(cadr old)) new)
    old (cddr old)
    )
    )
    )
    (reverse new)
    )
    ;; Revised (01-16-04) to increase speed thanks to Tony T's
    ;; example of using (while (setq ...))
    (defun @cv_triple_up (old / new)
    (and
    old
    (while
    (setq new (cons (list (car old)(cadr old)(caddr old)) new)
    old (cdddr old)
    )
    )
    )
    (reverse new)
    )
    ;; (01-16-04) combination of @cv_double_up and @cv_triple_up
    ;; Not yet employed.
    (defun @cv_grouplist (old n / new)
    ;; n must be 2 or 3
    (and
    old
    (cond
    ((= n 2)
    (while
    (setq new (cons (list (car old)(cadr old)) new)
    old (cddr old)
    )
    )
    )
    ((= n 3)
    (while
    (setq new (cons (list (car old)(cadr old)(caddr old)) new)
    old (cdddr old)
    )
    )
    )
    )
    )
    (reverse new)
    )
     
    John Uhden, Jun 4, 2004
    #4
  5. jonesr

    Jeff Mishler Guest

    John,
    I tried this myself the other day and kept getting errors. After looking at
    the help files, again, I thought I found the reason for the errors....and
    now you suggest doing it this way. Could you explain the errors of my ways?

    From the help:
    You cannot change the number of coordinates in the object by using this
    property. You can only change the location of existing coordinates.

    Thanks,

    Jeff
     
    Jeff Mishler, Jun 5, 2004
    #5
  6. jonesr

    John Uhden Guest

    Hi, Jeff.

    Just worked for me (2004)...
    Say: (setq plist '((0.0 0.0 0.0)(1.0 1.0 0.0)(2.0 1.0 0.0)(2.0 2.0 0.0)(2.0 3.0
    0.0)))
    Then: (vlax-put Object 'Coordinates (apply 'append plist))

    Yep, I read the help too. I guess they lied a little. That warning surely
    applys to Traces and 2D Solids, as they require 4 corners, but it doesn't apply
    to *POLYLINEs or leaders. Except, of course, don't try to put fewer than two
    pairs. Not sure, but maybe you tried to use integers instead of reals.
     
    John Uhden, Jun 5, 2004
    #6
  7. jonesr

    Jürg Menzi Guest

    Hi Jeff

    Works also for me in A2k2, A2k4 and A2k5...
    See my sample in this thread.

    Cheers
     
    Jürg Menzi, Jun 6, 2004
    #7
  8. jonesr

    Jeff Mishler Guest

    Well, I went back and tried it again, attempting to duplicate what tried
    last week as exact as possible. I guess I really screwed up because this
    time it worked...;-/
    I'm glad I didn't post the code because someone would've pointed out some
    stupid spelling error, or something similar......;-)

    Thanks for making me re-look at this, now I KNOW it works and I won't
    believe the help files ever again.....j/k

    Jeff
     
    Jeff Mishler, Jun 7, 2004
    #8
  9. jonesr

    jonesr Guest

    Command: CLEANLEADERS
    Select objects: 1 found
    Select objects: ; error: Exception occurred
     
    jonesr, Jun 11, 2004
    #9
  10. jonesr

    Juerg Menzi Guest

    Hi jonesr

    Works for me...
    Would you post a sample drawing in the customer-files ng?

    Cheers
    Juerg
     
    Juerg Menzi, Jun 11, 2004
    #10
  11. jonesr

    Juerg Menzi Guest

    jonesr

    I've found the reason for this error. Leaders with annotation can't change the coordinates property. Without annotation no problem. In the moment I don't know another solution.

    Cheers
    Juerg
     
    Juerg Menzi, Jun 11, 2004
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.