PDA

View Full Version : Need help removing Dictionary from file



Archiman86
26th Mar 2010, 07:23 pm
I am trying to remove a specific dictionary from a bunch of files. The client we work with has issues in their document management system when this exists in the files. I am trying to get this to work so that it prints whether it did not already exist, or if it was deleted. Right now I keep getting an error that says:

error: bad function: <Entity name: 7ebb3460>

Here is what I have so far:

(defun c:GCI()
(setq newdictlist (dictsearch (namedobjdict) "GcImageDef_Dict"))
(If
(= nil newdictlist) (princ "\nGcImageDef_Dict does not exist.")
((dictremove (namedobjdict) "GcImageDef_Dict") (princ"\nThe GcImageDef_Dict has been removed."))
)
(princ)
)

Thanks in advance for any help!

Lee Mac
26th Mar 2010, 07:39 pm
I can't test it, but maybe something like this?



(defun c:GCI (/ newdictlist)
(cond ( (setq newdictlist (dictsearch (namedobjdict) "GcImageDef_Dict"))

(dictremove (namedobjdict) "GcImageDef_Dict")
(princ "\nThe GcImageDef_Dict has been removed."))

( (princ "\nGcImageDef_Dict does not exist.")))

(princ))

Archiman86
26th Mar 2010, 07:52 pm
Lee, Thanks! Thats works. By chance, can you explain why it would return that error for me. In theory, to my knowledge that should work. I mean, my version DID work, it jsut put that error after printing "...has been removed." Thanks again!

-Dan

Lee Mac
26th Mar 2010, 07:56 pm
It was this line:



((dictremove (namedobjdict) "GcImageDef_Dict") (princ"\nThe GcImageDef_Dict has been removed."))
Which would be interpreted as:



(<entity_name> "\nThe GcImageDef_Dict has been removed.")
I.e. as if the <entity_name> was a function, (which it isn't, of course).

To wrap two expressions in the THEN statement of the IF function, you need to use a wrapper like PROGN:



(defun c:GCI (/ newdictlist)

(setq newdictlist (dictsearch (namedobjdict) "GcImageDef_Dict"))
(If (= nil newdictlist)
(princ "\nGcImageDef_Dict does not exist.")
(progn
(dictremove (namedobjdict) "GcImageDef_Dict")
(princ"\nThe GcImageDef_Dict has been removed.")
) ; progn
) ; IF

(princ))

JohnM
26th Mar 2010, 08:00 pm
i think the issue is your IF statement (= nil newdictlist) should be
(= newdictlist nil)