Hi I am creating a lisp rotine that will unload a list of images from the drawing and I tryed both "vl-cdmd" and "command". "-image " work when I type in at the command line ,but not when I runing the rotine it didn't show me any error messages either.
could some one read my code and tell me if I had done anything wrong?
(DEFUN C:DETUN ()
(getvisibilitystate); return an entity list
(setq list_a nil)
(setq img1 nil)
(setq vis1 (entget vis))
(while (assoc 303 vis1)
(setq img1 (list (cdr (assoc 303 vis1))))
(setq List_a (append List_a img1));list contain all images name
(setq vis1 (cdr (member (assoc 303 vis1) vis1)))
)
(setq a 1)
(setq l1 (length list_a))
(repeat (- l1 1)
(setq vnam1 (nth a list_a))
(if (/= vnam1 vame)
(progn
(vl-cmdf "-Image" "u" vnam1)
(command "-Image" "d" vnam1)
)
)
(setq a (+ a 1))
)
(getvisibilitystate); return an entity list
which entity?
(entget vis)
where are you setting vis?
(if (/= vnam1 vame)
where are you setting vname?
the "-image" command, works as expected, using the 'command' or the 'vl-cmdf' function.
as a demo
(vl-load-com) (defun c:demo (/ i lst obj ss) (setq lst "") (prompt "\nSelect Images to Detach: ") (if (setq ss (ssget '((0 . "IMAGE")))) (progn (repeat (setq i (sslength ss)) (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))) lst (strcat lst "," (vla-get-name obj)) ) ) (vl-cmdf "-Image" "_D" lst) ) ) (princ) )
I hope this helps
Henrique
;; Get Dynamic Block Visibility State - Lee Mac
;; Returns the value of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Value of Visibility Parameter, else nil
(defun getvisibilitystate ();/blk )
(setq blk (car (entsel "\nSelect block: ")))
(vl-load-com)
(setq blk (vlax-ename->vla-object blk))
(setq vame (LM:getdynpropvalue blk (getvisibilityparametername blk)))
)
;; Get Dynamic Block Property Value - Lee Mac
;; Returns the value of a Dynamic Block property (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; prp - [str] Dynamic Block property name (case-insensitive)
(defun LM:getdynpropvalue ( blk prp )
(setq prp (strcase prp))
(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
(vlax-invoke blk 'getdynamicblockproperties)
)
)
;; Get Visibility Parameter Name - Lee Mac
;; Returns the name of the Visibility Parameter of a Dynamic Block (if present)
;; blk - [vla] VLA Dynamic Block Reference object
;; Returns: [str] Name of Visibility Parameter, else nil
(defun getvisibilityparametername ( blk );/ vis )
(setq vis nil)
(if
(and
(vlax-property-available-p blk 'effectivename)
(setq blk
(vla-item
(vla-get-blocks (vla-get-document blk))
(vla-get-effectivename blk)
)
)
(= :vlax-true (vla-get-isdynamicblock blk))
(= :vlax-true (vla-get-hasextensiondictionary blk))
(setq vis
(vl-some
'(lambda ( pair )
(if
(and
(= 360 (car pair))
(= "BLOCKVISIBILITYPARAMETER" (cdr (assoc 0 (entget (cdr pair)))))
)
(cdr pair)
)
)
(dictsearch
(vlax-vla-object->ename (vla-getextensiondictionary blk))
"ACAD_ENHANCEDBLOCK"
)
)
)
)
(cdr (assoc 301 (entget vis)))
)
)
(DEFUN C:DETUN ();/ *blks* ref xname)
(getvisibilitystate)
(setq list_a nil)
(setq img1 nil)
(setq vis1 (entget vis))
(while (assoc 303 vis1)
(setq img1 (list (cdr (assoc 303 vis1))))
(setq List_a (append List_a img1))
(setq vis1 (cdr (member (assoc 303 vis1) vis1)))
)
(setq a 1)
(setq l1 (length list_a))
(repeat (- l1 1)
(setq vnam1 (nth a list_a))
(if (/= vnam1 vame)
(progn
(vl-cmdf "-Image" "_u" vnam1)
(command "-Image" "_d" vnam1)
)
)
(setq a (+ a 1))
)
;;;
(command "explode" "l" "")
(command "-purge" "la" "*" "n")
)
Here is all my code I am taking a dynamic block as input and when the use choose a image and I unload the other unuse images using -image, but for some wired reason I can't seem to unload the -image command in the autolisp the command itself work when is useing in the command line .
Sorry I fiugre it out it was becasue the name of the image were different from the list, the -image command work just fine.
Thank you !!!
You're welcome,
glad you got a solution.
EDIT: I would suggest the use of a 'foreach'
(foreach x list_a (if (/= x vame) (progn (vl-cmdf "-Image" "_u" x) (vl-cmdf "-Image" "_d" x) ) ) )
instead of
(setq a 1) (setq l1 (length list_a)) (repeat (- l1 1) (setq vnam1 (nth a list_a)) (if (/= vnam1 vame) (progn (vl-cmdf "-Image" "_u" vnam1) (command "-Image" "_d" vnam1) ) ) (setq a (+ a 1)) )
Henrique