Want to replace the Xref (REF-A.dwg )with the REF-B.dwg file in the new path using replaceXreftarget.lsp

Want to replace the Xref (REF-A.dwg )with the REF-B.dwg file in the new path using replaceXreftarget.lsp

Kana_Higashi
Enthusiast Enthusiast
531 Views
4 Replies
Message 1 of 5

Want to replace the Xref (REF-A.dwg )with the REF-B.dwg file in the new path using replaceXreftarget.lsp

Kana_Higashi
Enthusiast
Enthusiast

I would like to replace the Xref (REF-A.dwg )with the REF-B.dwg file in the new path using replaceXreftarget.lsp

in this DWG drawing.But it always shows an error: no function definition: VLA-GET-XREFERENCES.

Does anyone know how to code AutoLisp to achieve this function?

Thanks

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

paullimapa
Mentor
Mentor

Fails because there’s no built in function with that name 


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

paullimapa
Mentor
Mentor
Accepted solution

try this modified code:

 

(defun c:cx (/ found xref xrefpath xrefname vla-get-xreferences)
;;; a list of all xref names
;;; return example ("xref1" "x2")
;;; https://jtbworld.com/autocad-axblock-lsp
(defun vla-get-xreferences (adoc / b bn tl)
  (vlax-for b (vla-get-blocks
                adoc
              )
    (if (= (vla-get-isxref b) :vlax-true)
      (setq tl (cons (vla-get-name b) tl))
    )
  )
  (reverse tl)
)

  (setq xrefname (strcase (getstring "\nEnter the name of the Xref to reload: " T))) ; include T accommodate names with spaces
  (setq xrefpath (getfiled "Select Xref file" "" "dwg" 0))
  (if (and xrefpath xrefname)
    (progn
      (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
      (setq xref (vla-get-xreferences (vla-get-activedocument (vlax-get-acad-object))))  
;      (setq found nil)
      (foreach eachxref xref
        (if (= (strcase xrefname) (strcase eachxref))
          (progn
            (setq found t)
 ;           (vla-reload eachxref (strcat xrefpath))
            (vl-cmdf "_.Xref" "_P" eachxref xrefpath)
 ;           (vla-rename eachxref (substr (vl-filename-base xrefpath) 1 (vl-string-position "." (vl-filename-base xrefpath))) t)
            (vl-cmdf "_.Rename" "_B" eachxref (vl-filename-base xrefpath)) 
          )
        )
      )
      (if (not found)
        (alert (strcat "Could not find Xref named " xrefname))
        (alert (strcat "Successfully Repathed Xref named " xrefname " to\n" xrefpath)) ; added this message
      )
      (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
    )
  )
  (princ)
)

 


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

Kana_Higashi
Enthusiast
Enthusiast
OH, bro this works. The basic functions have been achieved. Thanks for the help:)
0 Likes
Message 5 of 5

paullimapa
Mentor
Mentor

glad to have helped..cheers!!!


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