Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Old Routine - New Day

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
RocksterB
552 Views, 6 Replies

Old Routine - New Day

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)
)

 

6 REPLIES 6
Message 2 of 7
pbejse
in reply to: RocksterB


@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"

 

Message 3 of 7
Ian_Bryant
in reply to: RocksterB

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

 

Message 4 of 7
pbejse
in reply to: Ian_Bryant


@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

Message 5 of 7
RocksterB
in reply to: pbejse

That seems to have fixed the problem. Thanks Ian!

Message 6 of 7
Ian_Bryant
in reply to: RocksterB

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

 

 

Message 7 of 7
RocksterB
in reply to: Ian_Bryant

Sweet! That does work much smoother. That's again for the added effort.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost