Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Detaching Unreferenced or Orphaned Images & Xref's

10 REPLIES 10
Reply
Message 1 of 11
jeffsl
8008 Views, 10 Replies

Detaching Unreferenced or Orphaned Images & Xref's

Does anybody know of a lisp routine, script or something else that can be run to remove these items? I'm aware of how to do this manually in the "image manager" or "xref manager". Just looking for something quicker to facilitate this.

Thanks,

-Jeff
10 REPLIES 10
Message 2 of 11
sdanis
in reply to: jeffsl

Try this

(command "image" "detach" "*")
Message 3 of 11
jeffsl
in reply to: jeffsl

That will detach everything? I only want to detach "Unreferenced" or "Orphaned" images & xref's.
Message 4 of 11
CherMcGettigan
in reply to: jeffsl

Was your issue with Unreferenced or Orphaned images resolved?  I am having this problem also.

 

Message 5 of 11
scot-65
in reply to: jeffsl

Today is your lucky day.

From help from other members in this community, many years ago, I have a block of code that will detach unreferenced images.

It is part of a comprehensive file maintenance program, therefore no defun statement.

 

   ;*** AUTOMATICALLY REMOVE ALL UNREFERENCED IMAGES *** 5-5-07
   (if (and (setq dict (dictsearch (namedobjdict) "ACAD_IMAGE_DICT"))
            (assoc 350 dict) );and
    (progn
     (setq lst nil)
     (if (setq ss1 (ssget "X" (list (cons 0 "IMAGE"))))
      (progn
       (princ "\n Removing Unreferenced Images.")
       (setq n 0)
       (repeat (sslength ss1)
       	(setq lst (cons (cdr (assoc 340 (entget (ssname ss1 n)))) lst)
              n (1+ n))
       );repeat
      );progn
     );if
     (setq n nil)
     (while (setq n (tblnext "BLOCK" (not n)))
      (setq ss1 (cdr (assoc -2 n)))
      (while ss1
       (if (= (cdr (assoc 0 (setq elst (entget ss1)))) "IMAGE")
        (setq lst (cons (cdr (assoc 340 elst)) lst)) );if
       (setq ss1 (entnext ss1))
      );while
     );while
     (foreach n dict
      (if (and (= (car n) 350) (not (member (cdr n) lst)))
       (entdel (cdr n)) );if
      );foreach
    );progn
   );if
   (setq dict nil ss1 nil n nil lst nil elst nil)

 

As far as xref's, I do not have a similar program.

Hope this helps.


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 6 of 11
braudpat
in reply to: jeffsl

 

Hello From France

 

I am not a developper but I have a routine XD which detach automatically ALL UnReferenced XRefs from the current drawing !

Sorry I don't know who is the author !?

 

Loading with APPLOAD

Run with XD

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 7 of 11
mid-awe
in reply to: braudpat

braudpat,
I know that this is an old post but as we are still active in this community, I am very much hoping for some help. I have a PDFUNDERLAY that rests on a layer made for it. The PDFUNDERLAY is the only item on the layer named "DRAWING". I need to delete the PDF making it's status "UNREFERENCED", then I need to detach it so that I can delete the PDF from it's location in "\\Documents\\". This is so that I can re-render and attach the PDF for to be included with the etransmit package. I have no issues until I try to detach the PDFUNDERLAY. Even the "XD__Remove_UnReferenced_XREF.lsp" does nothing other than return "nil". I am at whit's end. 
Anyone please help.
Thank you in advance for any suggestions and/or help.



Message 8 of 11
mid-awe
in reply to: mid-awe

I finally worked it out utilizing scot-65's code. I had to make just a few changes; here it is for anyone else hunting this information down.

 

(IF (AND (SETQ DICT (DICTSEARCH (NAMEDOBJDICT) "ACAD_PDFDEFINITIONS"))
	   (ASSOC 350 DICT)
      )					;and
    (PROGN
      (SETQ LST NIL)
      (IF (SETQ SS1 (SSGET "X" (LIST (CONS 0 "PDFUNDERLAY"))))
	(PROGN
	  (PRINC "\n Removing Unreferenced PDFs.\n")
	  (SETQ N 0)
	  (REPEAT (SSLENGTH SS1)
	    (SETQ LST (CONS (CDR (ASSOC 340 (ENTGET (SSNAME SS1 N)))) LST)
		  N   (1+ N)
	    )
	  )				;repeat
	)				;progn
      )					;if
      (SETQ N NIL)
      (WHILE (SETQ N (TBLNEXT "BLOCK" (NOT N)))
	(SETQ SS1 (CDR (ASSOC -2 N)))
	(WHILE SS1
	  (IF (= (CDR (ASSOC 0 (SETQ ELST (ENTGET SS1)))) "PDFUNDERLAY")
	    (SETQ LST (CONS (CDR (ASSOC 340 ELST)) LST))
	  )				;if
	  (SETQ SS1 (ENTNEXT SS1))
	)				;while
      )					;while
      (FOREACH N DICT
	(IF (AND (= (CAR N) 350) (NOT (MEMBER (CDR N) LST)))
	  (ENTDEL (CDR N))
	)				;if
      )					;foreach
    )					;progn
  )

The above code is ONLY for DETACHING UNREFERENCED PDFUNDERLAYs. I am sure that it can be applied to the slew of XREFs but I only need this version.

Message 9 of 11
mid-awe
in reply to: mid-awe

Unfortunately, even though the above program does appear to detach the PDF, the file on disk is still locked and does not allow itself to be deleted. Can anyone see what I have missed?

 

Please help if you can.

 

Thank you in advance for any help / advice.

Message 10 of 11
mid-awe
in reply to: mid-awe

Fortunately, I have found a work-around solution. I do not need to detach and etransmit withing the same session. Therefore I can detach after each etransmit, that will allow for updating the PDFUNDERLAY as I need once per session.

 

If anyone else knows of a way to detach the unreferenced PDFUNDERLAY in a way that allows the PDF file to be deleted from it's location on HDD, then I am eager to hear it.

 

Sometimes we just have to work around Autodesk.

 

Thanks all.

Message 11 of 11
HillcoFire
in reply to: braudpat

That was perfect for my needs.

Thank you from Texas!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost