Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This lisp sends objects to back that are set to a certain color. It has been working but now has mysteriously stopped and now gives the error "AutoCAD.Application: Invalid input". This code is way more advanced than my understanding so any help is appreciated.
Jared
;; Colour(s) to Back - Lee Mac ;; Sends all objects of specific colour(s) (object colour/layer colour) to the back of the draw order. (defun c:col2back ( / *error* blk bll col doc exd lac lck ls1 ls2 sor ) (setq col '(9 13 14 21 51 61)) ;; List of colour(s) to send to back (vlax-for lay (vla-get-layers (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (if (= :vlax-true (vla-get-lock lay)) (vla-put-lock (car (setq lck (cons lay lck))) :vlax-false) ) (if (member (vla-get-color lay) col) (setq lac (cons (vla-get-name lay) lac)) ) ) (vlax-for blk (vla-get-blocks doc) (if (and (= :vlax-false (vla-get-isxref blk)) (= :vlax-false (vla-get-islayout blk))) ( (lambda ( / lst ) (vlax-for obj blk (if (or (and (= acbylayer (vla-get-color obj)) (member (vla-get-layer obj) lac)) (member (vla-get-color obj) col) ) (setq lst (cons obj lst)) ) ) (if lst (progn (setq exd (vla-getextensiondictionary blk) bll (cons (vla-get-name blk) bll) ) (vlax-invoke (cond ( (LM:catchapply 'vla-getobject (list exd "acad_sortents"))) ( (vla-addobject exd "acad_sortents" "acdbsortentstable")) ) 'movetobottom lst ) ) ) ) ) ) ) (vlax-for lay (vla-get-layouts doc) (vlax-for obj (setq blk (vla-get-block lay)) (cond ( (or (and (= acbylayer (vla-get-color obj)) (member (vla-get-layer obj) lac)) (member (vla-get-color obj) col) ) (setq ls1 (cons obj ls1)) ) ( (and (= "AcDbBlockReference" (vla-get-objectname obj)) (member (vla-get-name obj) bll)) (setq ls2 (cons obj ls2)) ) ) ) (if (or ls1 ls2) (progn (setq exd (vla-getextensiondictionary blk) sor (cond ( (LM:catchapply 'vla-getobject (list exd "acad_sortents"))) ( (vla-addobject exd "acad_sortents" "acdbsortentstable")) ) ) (if ls2 (vlax-invoke sor 'movetobottom ls2)) (if ls1 (vlax-invoke sor 'movetobottom ls1)) ) ) ) (foreach lay lck (vla-put-lock lay :vlax-true)) (vla-regen doc acallviewports) (princ) ) ;; Catch Apply - Lee Mac ;; Applies a function to a list of parameters and catches any exceptions. (defun LM:catchapply ( fun arg / rtn ) (if (not (vl-catch-all-error-p (setq rtn (vl-catch-all-apply fun arg)))) rtn) ) (vl-load-com) (princ)
Jared - Sr. CAD Technician
Words to live by: If it ain't broke, you're not trying hard enough.
Solved! Go to Solution.