I have an old routine that no longer works. Any chance someone can apply a fix to it?
(defun XREFnameSync (/ *acad* *doc* *blocks* blk blkName blkPath s1 xLstAdd xLstFin) (vl-load-com) (or *acad* (setq *acad* (vlax-get-acad-object))) (or *doc* (setq *doc* (vla-get-activedocument *acad*))) (setq *blocks* (vla-get-blocks *doc*)) (vlax-for x *blocks* (if (= (vla-get-isxref x) :vlax-true) (if (setq s1 (ssget "x" (list (cons 0 "INSERT") (cons 2 (vla-get-name x)) ) ) ) (progn (setq blk (vlax-ename->vla-object (ssname s1 0))) (setq blkName (vla-get-name blk)) (setq blkPath (vl-filename-base (vla-get-path blk))) (if (not (= blkname blkpath)) (if (not (member blkpath xLstFin)) (command "-rename" "block" blkname (setq xLstAdd blkpath)) ) (setq xLstAdd blkname) ) (setq xLstFin (if xLstFin (append xLstFin (list xLstAdd)) (list xLstAdd) )) ) ) ) ) (princ) )
Solved! Go to Solution.
Solved by Ian_Bryant. Go to Solution.
Solved by Ian_Bryant. Go to Solution.
@RocksterB wrote:I have an old routine that no longer works. Any chance someone can apply a fix to it?
How is it supposed to work RocksterB? Give us the condition . from "this" to "that"
Hi,
Ithe function does work in most cases, but the results are not obvious
because the XREF manager window does not update after using
the Rename command.(The CLASSICXREF window does update)
To get the new manger window to update you can use
(command "-XREF" "Reload" "*") at the end of the function.
When testing I noticed your function can fall over if it is trying to
rename xref s that have different names, but reference the same dwg
depending on the order of the names in the block table, so try this:
(defun XREFnameSync ( / blk blkName blkPath s1)
(vl-load-com)
(vlax-for x (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(if (= (vla-get-isxref x) :vlax-true)
(if (setq s1 (ssget "x" (list (cons 0 "INSERT") (cons 2 (vla-get-name x)))))
(progn
(setq blk (vlax-ename->vla-object (ssname s1 0)))
(setq blkName (vla-get-name blk))
(setq blkPath (vl-filename-base (vla-get-path blk)))
(if (/= blkname blkpath)
(if (not (tblsearch "Block" blkpath))
(vla-put-name x blkpath)
)
)
)
)
)
)
(command "-XREF" "Reload" "*")
(princ)
)
Regards Ian
@Ian_Bryant wrote:Hi,
Ithe function does work in most cases, but the results are not obvious
because the XREF manager window does not update after using
the Rename command.....
Regards Ian
Is that what this is? Never notice that behaviour before.
Cheers Ian
Hi,
using (command "-XREF" "Reload" "*") is a bit crude
as it will reload all Xrefs including ones that have been unloaded.
You can try the following, which does not alter the loaded/unloaded status of the Xrefs:
(defun XREFnameSync ( / blk blkName blkPath s1 test)
(vl-load-com)
(vlax-for x (setq b (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
(if (= (vla-get-isxref x) :vlax-true)
(if (setq s1 (ssget "x" (list (cons 0 "INSERT") (cons 2 (vla-get-name x)))))
(progn
(setq blk (vlax-ename->vla-object (ssname s1 0)))
(setq blkName (vla-get-name blk))
(setq blkPath (vl-filename-base (vla-get-path blk)))
(if (/= blkname blkpath)
(if (not (tblsearch "Block" blkpath))
(progn
(vla-put-name x blkpath)
(setq test (assoc 71 (entget (tblobjname "BLOCK" blkpath))))
(vlax-invoke-method x 'Reload)
(if test (vlax-invoke-method x 'Unload))
)
)
)
)
)
)
)
(princ)
)
Regards Ian