Ignore "unloaded" or "not found" xrefs during a bind/insert LISP Routine

Ignore "unloaded" or "not found" xrefs during a bind/insert LISP Routine

asleafty
Explorer Explorer
2,562 Views
9 Replies
Message 1 of 10

Ignore "unloaded" or "not found" xrefs during a bind/insert LISP Routine

asleafty
Explorer
Explorer
I have written a LISP routine to create some background files of our house plans that are used by outside vendors. Basically the code will bind and insert all xref's, then set layer visibility of specific content and wblock out files for each background we intend to provide. The trouble is if there is any xref that is "not found" or "unloaded" within the file it will break the routine and not finish the bind/insert process. What I need to do is have the routine essentially ignore or skip the xrefs that aren't resolved, and only move forward with the ones that are. Unfortunately my limited experience with LISP writing has not taught me those skills yet. Can someone please assist? I have attached a copy of the code for your reference.
0 Likes
Accepted solutions (1)
2,563 Views
9 Replies
Replies (9)
Message 2 of 10

kpblc2000
Advisor
Advisor
Why not to use standard command _.etransmit?
You can check every block definition at your dwg, check - is it xref or not, try (by using findfile function) to find an xref file. If it doesn't found - exclude it.
I dont'nkow simple mechanism to find an 'unloaded' xrefs. I think you'll have to check all block definitions, filter an xrefs, then go through all dwg database and check xref insertions (do not forget - xre can be inserted to another static or dynamic block, or to another xref, or to table cell, it could be isolated and so on).

Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям! | Do you find the posts helpful? "LIKE" these posts!
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.


Алексей Кулик aka kpblc | Aleksei Kulik aka kpblc Facebook | LinkedIn
autolisp.ru
Техническая поддержка программистов Autodesk в СНГ
Библиотека пользовательских lisp-функций | Custom Lisp-function library

0 Likes
Message 3 of 10

asleafty
Explorer
Explorer
Thank you kpblc2000. Unfortunately I don't think using the etransmit functionality will work for what I need as there is some additional manipulation of the drawing content that occurs after the bind/insert, yet prior to the wblock of the deliverable file. Is there a way I can get AutoCAD to return a list of loaded xref's and use that list within the bind function? I appreciate your assistance. I know just enough LISP to get excited about what I could do with it, but not enough to always get the job done.
0 Likes
Message 4 of 10

gdefilo
Advocate
Advocate
Accepted solution

Hi asleafty,

 

starting from this thread:

http://www.cadtutor.net/forum/showthread.php?14319-Any-lisp-to-reload-only-quot-loaded-quot-xrefs

 

I managed to build this Lisp:

 

(defun c:bindloaded(/ cObj cName)
  (setq cObj(tblnext "BLOCK" T))
  (while cObj
    (setq cName(cdr(assoc 2 cObj)))
    (if
      (and
	 (=(logand(cdr(assoc 70 cObj))32)32)
	 (=(logand(cdr(assoc 70 cObj))4)4)
	 ); end and
      (progn
       (vl-cmdf "bindtype" "1")
       (vl-cmdf "_.xref" "_unload" cName)
       (vl-cmdf "_.xref" "_reload" cName)
       (vl-cmdf "_.xref" "_bind" cName)
       ); end progn
      ); wnd if
  (setq cObj(tblnext "BLOCK"))
  ); end while
   (princ)
  ); end of c:bindloaded

It performs a reload of all xref's already loaded and then bind them all.

I tested it and it works for me.

Hope it will for you too.

 

Giancarlo

 

Message 5 of 10

asleafty
Explorer
Explorer
Thanks Giancarlo!! That seems to work wonderfully for what I need! I really appreciate your time and effort to write that for me. My drafters will certainly be happy that the routine will function better now!
0 Likes
Message 6 of 10

gdefilo
Advocate
Advocate

Hi asleafty,

 

I'm glad it helped!

 

Cheers,

Giancarlo

 

0 Likes
Message 7 of 10

David_White
Contributor
Contributor

just what i was looking for 

many thanks

0 Likes
Message 8 of 10

jfcadx
Contributor
Contributor

Hi

 

Is it possible to add to this bindloaded.lsp so that it detaches unloaded or unreferenced xreferences.

 

Thanks in advance

0 Likes
Message 9 of 10

gdefilo
Advocate
Advocate

Yes, it's possibile.

You need to add just a line at the end of the code:

(defun c:bindloaded(/ cObj cName)
  (setq cObj(tblnext "BLOCK" T))
  (while cObj
    (setq cName(cdr(assoc 2 cObj)))
    (if
      (and
	 (=(logand(cdr(assoc 70 cObj))32)32)
	 (=(logand(cdr(assoc 70 cObj))4)4)
	 ); end and
      (progn
       (vl-cmdf "bindtype" "1")
       (vl-cmdf "_.xref" "_unload" cName)
       (vl-cmdf "_.xref" "_reload" cName)
       (vl-cmdf "_.xref" "_bind" cName)
       ); end progn
      ); wnd if
  (setq cObj(tblnext "BLOCK"))
  ); end while
   (princ)
(command "-xref" "d" "*")
  ); end of c:bindloaded

 

Hope this helps.

Giancarlo 

0 Likes
Message 10 of 10

jfcadx
Contributor
Contributor

It did, Thank You

0 Likes