TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: KewlToyZ on August 17, 2009, 05:22:01 PM

Title: Compensate for bind failures?
Post by: KewlToyZ on August 17, 2009, 05:22:01 PM
Occasionally we run into a failure on a file to bind its XREF's because an XREF contains a block with the same name as an XREF. Unfortunately AutoCAD never mentions which object name so it can be updated. It is a mistake clients make occassionally.
Has anyone ever looked at fixing this with a routine automatically?

I am fiddling with some of the block routines you good folks shared with me last week.
I wondered where I would catch the error for the XREF having the same name as a block or nested block that could cause the failure? :?

Code: [Select]
(defun c:xrb ()
(vl-load-com)
(vlax-for Obj (vla-get-Blocks
                  (vla-get-ActiveDocument
                    (vlax-get-acad-object)))

    ;; Get hold of the block collection for
    ;; the active document and iterate through it.

    ;; Note:-
    ;; To make the program faster, set the ActiveDocument Object
    ;; to a variable defined in the main function, and use it in
    ;; the sub-function to save calling vlax-get-acad-object multiple
    ;; times.

    (if (eq :vlax-true (vla-get-IsXRef Obj))
     
      ;; Check Block is an XRef

      (if (vl-catch-all-error-p
            (vl-catch-all-apply 'vla-bind (list Obj)))

        ;; Use vl-catch-all-apply to trap any errors that
        ;; may occur, and prevent program from crashing!
        (alert
        ;(princ
          (strcat "\n** " (vla-get-Name Obj) " Failed to Bind **"))))
        )

        ;; Notify of an error during reloading.
  (princ "\n XREF reloading complete!!!\n")
  (princ)
)
Title: Re: Compensate for bind failures?
Post by: KewlToyZ on August 18, 2009, 01:52:23 PM
More or less I'm trying to capture the specific error for tht failure.
I had considered in the direction of testing every block(insert) entry to see if it has a matching xref entry title.
But it would have to build both as a list and compare them and this could take quite awhile depending on the nesting.
So in the error trap would be the only time I should check for an identical entry and rename the xref generically possibly?
I'm just considering automating this somewhat to catch potential failures and fix them for me instead.
I guessed at placing it in a while loop to go back and bind again until everything is bound in this rare case.

Any feedback would be appreciated.