lisp fix xref "not found" (path lost)

lisp fix xref "not found" (path lost)

renanemeyer
Advocate Advocate
691 Views
7 Replies
Message 1 of 8

lisp fix xref "not found" (path lost)

renanemeyer
Advocate
Advocate

Hello everyone on the forum!

I'm facing a difficulty, which in this case I've already looked for several alternatives here on the forum, but none of them gave me any feedback. Directly my autocad loses the references (like the attached image).

 

renanemeyer_0-1709747744296.png

renanemeyer_1-1709747771531.png

I was doing a lisp to reload, because I have a standard folder, 

renanemeyer_0-1709748039247.png

so all my references are always in a standard folder. but nothing worked, nothing I've ever found on the forum or what I tried to create

 

 

 

 

(defun c:r-xrefs (/ doc xrefs item name path fullpath basepath)
  (vl-load-com)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq xrefs (vla-get-blocks doc))
  (setq basepath (vl-filename-directory (vl-filename-directory (getvar "DWGPREFIX"))))
  
  (vlax-for item xrefs
    (if (= :vlax-true (vlax-get-property item 'IsXRef))
      (progn
        (setq name (vlax-get-property item 'Name))
        (setq path (vlax-get-property item 'Path))
        (princ (strcat "\nXref: " name ", Caminho atual: " path))

        (if (or (= (vl-string-right-trim " " (strcase path)) "XREF NOT FOUND")
                (vl-string-search "..\\" path))
          (progn
            (setq fullpath (strcat basepath "Base\\" name ".dwg"))
            (if (findfile fullpath)
              (progn
                (command "_-xref" "_Path" name fullpath)
                (command "_-xref" "_Reload" name)
                (princ (strcat "\nReassociando e recarregando Xref: " name " com novo caminho: " fullpath))
              )
              (princ (strcat "\nFalha ao encontrar arquivo no caminho: " fullpath))
            )
          )
          (princ (strcat "\nXref: " name " já está carregado e não precisa de atualização."))
        )
      )
    )
  )

  (princ)
)
(princ)

 

 


Does anyone know what else can be adjusted or have an idea of ​​how it is possible? 

0 Likes
Accepted solutions (1)
692 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

Will need more information as to why this occurs.

1. Are those xrefs actually somewhere like either located inside the Base or Main folder?

2. Why are they called Xref1, Xref2, Xref3 and etc instead of the actual drawing name?

3. Were the xrefs successfully found in this particular drawing before?

4. Are those xrefs attached/overlay with full paths or relative paths?

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 8

renanemeyer
Advocate
Advocate

Thanks for the feedback @paullimapa 
1. my main drawing is always inside Main, and the xrefs are always inside Base
2. I just named it for the print to clarify, as the name is always a long string of characters
3. Yes, they were present. I usually change several days, but on some of the days I open the file, these xrefs are lost (sometimes not all, just one or the other and the rest remain)
4. Attached is an attached image of another example

renanemeyer_1-1709753311035.png

 

 

0 Likes
Message 4 of 8

paullimapa
Mentor
Mentor

Could be problem with path being longer than supported

Are these all full path xrefs or relative?

What happens when they're placed in the same folder?

Do a screen capture of your ABOUT command and share that here


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 8

renanemeyer
Advocate
Advocate

Well observed, it could be because the path is longer than supported.
They are all full path xrefs, but due to organization and habit, I don't leave them all in the same folder, I create subfolders as the base for this.

print of about:

renanemeyer_0-1709754731791.png

 

0 Likes
Message 6 of 8

paullimapa
Mentor
Mentor
Accepted solution

So you do have the latest 2024 updates installed

You may also want to do the following:

1. Use Recover command to open up each xref and then do a safe in case there's any corruption

2. Make sure under Options this is set:

paullimapa_0-1709755385632.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 8

renanemeyer
Advocate
Advocate

Thank you for your availability and patience in analyzing the case @paullimapa 
I believe that this will not be easily solved using Lisp, I will follow the conventional solution or the adjustment as mentioned.
Thanks

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

Glad to have helped…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes