;;;==UNBIND.LSP=====================================================
;;; Unbind Xrefs with reattaching bound xreferences in a one click
;;; removing the bound items and recreating the original file
;;; Modified by Henrique 2016
;;;==================================================================
(prompt "\nUNBIND\nLoading ...")
(vl-load-com)
(defun C:UX (/ ai_dcl blck_name blk_list expr flist flist1 fname head rep whead xsels)
(setq expr (getvar "expert"))
(setvar "EXPERT" 4)
(setvar "CMDECHO" 0)
;;; Check to see if AI_UTILS is loaded, If not, try to find it,
;;; and then try to load it.
(cond
((and ai_dcl (listp ai_dcl))) ; it's already loaded.
((not (findfile "ai_utils.lsp")) ; find it
(ai_abort "SPECIAL"
(strcat "Can't locate file AI_UTILS.LSP."
"\n Check support directory."
)
)
)
((eq "failed" (load "ai_utils" "failed")) ; load it
(ai_abort "SPECIAL" "Can't load file AI_UTILS.LSP")
)
)
(command "-layer" "on" "*" "thaw" "*" "unlock" "*" "S" "0" "")
(setq blk_list (ai_table "block" 14)) ; no anonymous, Xrefs or
; Xref dependents.
(setq rep 0)
(repeat (length blk_list)
(setq blck_name (nth rep blk_list))
(if (wcmatch blck_name "*$0$*") ;bound block
(progn
(setq head (substr BLCK_NAME 1 (str_pos "$" BLCK_NAME))
whead (strcat head "*")
fname (substr head 1 (- (strlen head) 1))
flist (list '(-4 . "")
)
flist1 (list (cons 0 "INSERT")
(cons 2 fname)
)
)
(if (or (setq xsels (ssget "X" flist))
(setq xsels (ssget "X" flist1))
)
(progn
(command "wblock" (strcat (getvar "dwgprefix") fname ".dwg") "" "0,0" xsels "")
(repeat 3 (command "purge" "a" "" "n")
)
(command "-attach" (strcat (getvar "dwgprefix") fname ".dwg") "o" "0,0,0" "" "" "")
)
)
) ;end progn
) ;endif
(setq rep (+ 1 rep))
) ;end repeat
(setvar "EXPERT" EXPR)
;(command "rpurge")
(prompt "\n")
(prompt "\nWBlocking complete.")
(princ)
)

(defun STR_POS (schar sstring /)
(setq ptr (strlen sstring)
ctr 0
fnd nil
)
(while (and (< ctr ptr) (not fnd))
(setq ctr (+ 1 ctr))
(setq fnd (or fnd (= (substr sstring ctr 1) schar)))
) ;end while
(setq ctr ctr)
)
(c:ux)

Advertisements