Reload XREFs, Detach unloaded AND "not found" XREFs

Reload XREFs, Detach unloaded AND "not found" XREFs

dcalhounGT6GH
Contributor Contributor
1,313 Views
4 Replies
Message 1 of 5

Reload XREFs, Detach unloaded AND "not found" XREFs

dcalhounGT6GH
Contributor
Contributor

I'm looking for a LISP routine to:

1) Reload all xrefs

2) Detach all unloaded XREFS

3) Detach all "not found" XREFS


What I've found so far is great for detaching unloaded XREFS, but doesn't take care of the other 2 things.


;DETACHES UNLOADED XREFS
(defun remove-unloaded-xrefs ()
(vlax-for block (vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)))
(if (and (= :vlax-true (vla-get-isxref block))
(= 0 (vla-get-count block))
)
(vla-detach block)
)
)
)
(defun c:dux ()
(remove-unloaded-xrefs)
(princ)
)



 

 

0 Likes
Accepted solutions (1)
1,314 Views
4 Replies
Replies (4)
Message 2 of 5

pbejse
Mentor
Mentor

Consider using tblsearch and check for DXF 70, Unloaded and Not Found will have a value 12

Add this to check if XREF 

(= 4 (logand 4 (cdr (assoc 70 var)))

 

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

@dcalhounGT6GH wrote:

I'm looking for a LISP routine to:

1) Reload all xrefs

2) Detach all unloaded XREFS

....


I'm confused....  If you first Reload all Xrefs, can there be any unloaded Xref's?

Kent Cooper, AIA
0 Likes
Message 4 of 5

dcalhounGT6GH
Contributor
Contributor

Sorry for not clarifying. We will have a main work folder, which we will copy over select files to use, depending on selections made. A-1-A-2-FLR is our main floor plan drawing and all of the XREFs may or may not be copied to the work folder. The reload (at least doing it manually through the XREF palette) would look for those XREFs, then list its status as "Not Found". There might be an easier way to do this than how I'm thinking.

My end goal is to be able to create my "job folder" with only the options needed, have a LISP routine "clean" those unused XREFs from my floor plan, then ultimately, bind, insert, those XREFs, and explode the resulting blocks (another LISP routine that I'm working on). I'm just now dipping my toes into LISP and truly appreciate all the help from you all.

0 Likes
Message 5 of 5

dcalhounGT6GH
Contributor
Contributor
Accepted solution

So, I found this in a thread from 2008:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-code-help-review-detaching-not-...

 

(defun c:Test1 (/ Ent tempBit Str)

(while (setq Ent (tblnext "block" (not Ent)))
(setq tempBit (cdr (assoc 70 Ent)))
(if
(and
(equal (logand 4 tempBit) 4)
(zerop (logand 32 tempBit))
)
(if (not (findfile (cdr (assoc 1 Ent))))
(setq Str
(if Str
(strcat Str "," (cdr (assoc 2 Ent)))
(cdr (assoc 2 Ent))
)
)
)
)
)
(if Str
(command "_.xref" "_detach" Str)
)
(command "_.xref" "_reload" "*")
(princ)
)
[/code]

 

I added in this line and it seems to work great 🙂 

(command "_.xref" "_reload" "*")

 

Thank you all for your help

 

0 Likes