Author Topic: Add & delete vertices - LEADERs & LWPOLYLINEs  (Read 5601 times)

0 Members and 1 Guest are viewing this topic.

hermanm

  • Guest
Add & delete vertices - LEADERs & LWPOLYLINEs
« 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.

 

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Add & delete vertices - LEADERs & LWPOLYLINEs
« Reply #1 on: October 04, 2010, 05:33:34 AM »
Does vla-update work to resolve the issue? To keep on the VL track.

hermanm

  • Guest
Re: Add & delete vertices - LEADERs & LWPOLYLINEs
« Reply #2 on: October 04, 2010, 10:45:59 AM »
Does vla-update work to resolve the issue? To keep on the VL track.

No.:(

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Add & delete vertices - LEADERs & LWPOLYLINEs
« Reply #3 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   :|

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Add & delete vertices - LEADERs & LWPOLYLINEs
« Reply #4 on: October 04, 2010, 10:57:46 AM »
I have 2008 Vanilla at home and it works fine. Post the drawing.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

hermanm

  • Guest
Re: Add & delete vertices - LEADERs & LWPOLYLINEs
« Reply #5 on: October 04, 2010, 03:38:18 PM »
I have 2008 Vanilla at home and it works fine. Post the drawing.

File attached.

kpblc

  • Bull Frog
  • Posts: 396
Re: Add & delete vertices - LEADERs & LWPOLYLINEs
« Reply #6 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
« Last Edit: October 08, 2010, 02:26:16 PM by kpblc »
Sorry for my English.