TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hermanm on October 04, 2010, 12:46:05 AM

Title: Add & delete vertices - LEADERs & LWPOLYLINEs
Post by: hermanm on October 04, 2010, 12:46:05 AM
Apparent anomaly in ACAD 2008 when deleting vertices on LEADERs using Active X methods

1. Once one vertex has been deleted, using:

Code: [Select]
(vlax-put obj 'coordinates (remove-triple coords index))

a second call on a different point fails with:

Exception occurred

A solution apparently is:

Code: [Select]
(entmod (entget obj))

before attempting to modify the LEADER.

Problem does not occur when adding vertices to a LEADER.

Code attached.

Acknowledgements:
Thanks to Kerry Brown & Gile for insight into making the LWPOLYLINE routines work in any coordinate system.
They and others have posted better & more complete routines for plines.

 
Title: Re: Add & delete vertices - LEADERs & LWPOLYLINEs
Post by: Lee Mac on October 04, 2010, 05:33:34 AM
Does vla-update work to resolve the issue? To keep on the VL track.
Title: Re: Add & delete vertices - LEADERs & LWPOLYLINEs
Post by: hermanm on October 04, 2010, 10:45:59 AM
Does vla-update work to resolve the issue? To keep on the VL track.

No.:(
Title: Re: Add & delete vertices - LEADERs & LWPOLYLINEs
Post by: Lee Mac on October 04, 2010, 10:46:30 AM
Does vla-update work to resolve the issue? To keep on the VL track.

No.:(

Twas worth a shot   :|
Title: Re: Add & delete vertices - LEADERs & LWPOLYLINEs
Post by: alanjt on October 04, 2010, 10:57:46 AM
I have 2008 Vanilla at home and it works fine. Post the drawing.
Title: Re: Add & delete vertices - LEADERs & LWPOLYLINEs
Post by: hermanm on October 04, 2010, 03:38:18 PM
I have 2008 Vanilla at home and it works fine. Post the drawing.

File attached.
Title: Re: Add & delete vertices - LEADERs & LWPOLYLINEs
Post by: kpblc on October 08, 2010, 02:22:43 PM
Try this (wrote only for leader objects):
Code: [Select]
(defun erase-leader-vertex (leader number / _kpblc-conv-list-to-3dpoints coords err)
                           ;|
    leader -> pointer to leader object. nil -> select by user
        could be ename or vla-object
    number -> number of vertex to erase. nil -> ask user. Should be more than 0 and less than
        leader vertex count
|;

;;; Call samples:
  ;|
(erase-leader-vertex (car (entsel)) 1)
(erase-leader-vertex (car (entsel)) 4)
|;

  (defun _kpblc-conv-list-to-3dpoints (lst / res)
    (cond
      ((not lst)
       nil
       )
      (t
       (setq res (cons (list (car lst)
                             (if (cadr lst)
                               (cadr lst)
                               0.
                               ) ;_ end of if
                             (if (caddr lst)
                               (caddr lst)
                               0.
                               ) ;_ end of if
                             ) ;_ end of list
                       (_kpblc-conv-list-to-3dpoints (cdddr lst))
                       ) ;_ end of cons
             ) ;_ end of setq
       )
      ) ;_ end of cond
    res
    ) ;_ end of defun

  (cond
    ((not leader)
     (if (= (type (setq leader (vl-catch-all-apply
                                 (function
                                   (lambda ()
                                     (ssname (ssget "_.+:E:S" '((0 . "LEADER"))))
                                     ) ;_ end of lambda
                                   ) ;_ end of function
                                 ) ;_ end of vl-catch-all-apply
                        ) ;_ end of setq
                  ) ;_ end of type
            'ename
            ) ;_ end of =
       (erase-leader-vertex (vlax-ename->vla-object leader) number)
       ) ;_ end of if
     )
    ((= (type leader) 'ename)
     (erase-leader-vertex (vlax-ename->vla-object leader) number)
     )
    ((and (= (type leader) 'vla-object)
          (wcmatch (strcase (vla-get-objectname leader)) "*LEADER*")
          ) ;_ end of and
     (setq coords (_kpblc-conv-list-to-3dpoints
                    (vlax-safearray->list (vlax-variant-value (vla-get-coordinates leader)))
                    ) ;_ end of _kpblc-conv-list-to-3dpoints
           ) ;_ end of setq
     (cond
       ((not number)
        (if (and (= (type
                      (setq number (vl-catch-all-apply (function (lambda ()
                                                                   (initget 6)
                                                                   (getint "\nSelect number of vertex to erase <Exit> " :)
                                                                   ) ;_ end of lambda
                                                                 ) ;_ end of function
                                                       ) ;_ end of vl-catch-all-apply
                            ) ;_ end of setq
                      ) ;_ end of type
                    'int
                    ) ;_ end of =
                 (<= number (length coords))
                 ) ;_ end of and
          (erase-leader-vertex leader number)
          ) ;_ end of if
        )
       ((> number (length coords))
        (princ "\nCan't erase this number!")
        )
       (t
        (if (vl-catch-all-error-p
              (setq err
                     (vl-catch-all-apply
                       (function
                         (lambda ()
                           (vla-put-coordinates
                             leader
                             ((lambda (/ lst)
                                (setq lst (apply (function append)
                                                 (vl-remove-if
                                                   (function
                                                     (lambda (x)
                                                       (= (1+ (vl-position x coords)) number)
                                                       ) ;_ end of lambda
                                                     ) ;_ end of function
                                                   coords
                                                   ) ;_ end of vl-remove-if
                                                 ) ;_ end of apply
                                      ) ;_ end of setq
                                (vlax-make-variant
                                  (vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length lst)))) lst)
                                  ) ;_ end of vlax-make-variant
                                ) ;_ end of lambda
                              )
                             ) ;_ end of vla-put-coordinates
                           (vla-update leader)
                           ) ;_ end of lambda
                         ) ;_ end of function
                       ) ;_ end of vl-catch-all-apply
                    ) ;_ end of setq
              ) ;_ end of vl-catch-all-error-p
          (princ (strcat "\n ** error ** : " (vl-catch-all-error-message err)))
          ) ;_ end of if
        )
       ) ;_ end of cond
     )
    ) ;_ end of cond
  (princ)
  ) ;_ end of defun