Author Topic: Detaching all unreferenced external references  (Read 7008 times)

0 Members and 1 Guest are viewing this topic.

FOUAD ABOU RJEILY

  • Guest
Detaching all unreferenced external references
« on: June 28, 2012, 11:02:49 AM »
Can somebody help on this issue please.
Purpose: Cleaning up all unreferenced [File References] from the active Dwg document using code.

The XREF command in AutoCAD shows the list of all References Xrefs, Raster images , pdf ... and their status.

I tried to get the same list of references using lisp code:
- For Xrefs: I got only the one having status=loaded as Overlay or Attach using (tblsearch "Block".)
- For JPG only status=loaded ones using ssget '((0 . "IMAGE").

How can I get all of them including for 'Status'=Unreferenced?


ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Detaching all unreferenced external references
« Reply #1 on: June 28, 2012, 11:47:32 AM »
Maybe this *.lsp from azarko can help you, though I haven't analyized it yet...

http://forums.augi.com/showthread.php?64428-LISP-Routine-to-remove-all-unrefernced-Xref-s/page3&p=#22

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BlackBox

  • King Gator
  • Posts: 3770
Re: Detaching all unreferenced external references
« Reply #2 on: June 28, 2012, 02:50:26 PM »

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. (defun _GetXrefNames (doc / xrefs)
  4.   ;; RenderMan, 2010
  5.   ;; Example:
  6.   ;; (_GetXrefNames (vla-get-activedocument (vlax-get-acad-object)))
  7.   (vlax-for oBlock (vla-get-blocks doc)
  8.     (if (= :vlax-true (vla-get-isxref oBlock))
  9.       (setq xrefs (cons (vla-get-name oBlock) xrefs))))
  10.   xrefs)
  11.  
"How we think determines what we do, and what we do determines what we get."

JohnK

  • Administrator
  • Seagull
  • Posts: 10669
Re: Detaching all unreferenced external references
« Reply #3 on: June 28, 2012, 04:04:49 PM »
Do you mean "Unloaded"?

Here is an oldie that I found/did that will demonstrate finding the unloaded xrefs. It will just print it to the command line but you can take it from there right?

Code - Auto/Visual Lisp: [Select]
  1. ( (lambda (/ entry xname xpath saved-xref-name)
  2.     ;; if at minimum bit nu 32 isnt set, then the drawing is unloaded.
  3.     ;;
  4.     ;; 70  Block-type flags (bit-coded values, may be combined):
  5.     ;; 0 = Indicates none of the following flags apply
  6.     ;; 1 = This is an anonymous block generated by hatching, associative
  7.     ;;     dimensioning, other internal operations, or an application
  8.     ;; 2 = This block has non-constant attribute definitions (this bit is not
  9.     ;;     set if the block has any attribute definitions that are constant,
  10.     ;;     or has no attribute definitions at all)
  11.     ;; 4 = This block is an external reference (xref)
  12.     ;; 8 = This block is an xref overlay
  13.     ;; 16 = This block is externally dependent
  14.     ;; 32 = This is a resolved external reference, or dependent of an
  15.     ;;      external reference (ignored on input)
  16.     ;; 64 = This definition is a referenced external reference (ignored on
  17.     ;;      input)
  18.     (while
  19.       ;; itterate thru all xrefs in dwg
  20.       (setq entry (tblnext "block" (not entry)))
  21.       ;; get the first block
  22.       (if (cdr (assoc 1 entry))
  23.         ;; check to see if it has a path (is an xref)
  24.         ;;
  25.         ;; if it does..
  26.         (if (zerop (logand (cdr (assoc 70 entry)) 32))
  27.          (print (cdr (assoc 2 entry))))))
  28.     (princ)) )

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

BlackBox

  • King Gator
  • Posts: 3770
Re: Detaching all unreferenced external references
« Reply #4 on: June 28, 2012, 04:18:10 PM »
pbejse saved me from needing to writing the VLA-* equivalent, in this thread:

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/selecting-only-loaded-xrefs/td-p/2957742

Quote
Code - Auto/Visual Lisp: [Select]
  1. (defun c:SelXref  (/ Xr_lst)
  2.      blk  (vla-get-blocks
  3.     (if (eq (vla-get-isXref blk) :vlax-true)
  4.       (setq Xr_lst
  5.          (cons
  6.            (cons
  7.              (vla-get-name blk)
  8.              (if (> (vla-get-count blk) 0)
  9.                "Loaded" "Unloaded"))
  10.            Xr_lst))))
  11.   (foreach n Xr_lst (print n))
  12.   (princ))
  13.  
"How we think determines what we do, and what we do determines what we get."