PDA

View Full Version : Need LSP: Rename Reference Name in Xref pallette to match File Name


haydenrosser
2009-03-27, 04:35 AM
Not sure if this LSP exists or not...but after trying to search for it for the last 4 hours,

After updating a path in a drawing, I need the Refence Name in the Xref Pallette to automatically change or be updated to reflect the new file name.

ie, if you have a file xrefed into a new drawing called drawing 1.dwg, then you repath it to a new drawing called Drawing 2.dwg, the name shown in the Xref pallete, under Reference Name, is still labelled Drawing 1.

As I am updating a set of drawings for which has now has been split into a west and east, i need the Reference Name to change as i am changing the path.

Any clues??

mweaver
2009-03-27, 01:21 PM
Not sure if this LSP exists or not...but after trying to search for it for the last 4 hours,

After updating a path in a drawing, I need the Refence Name in the Xref Pallette to automatically change or be updated to reflect the new file name.

ie, if you have a file xrefed into a new drawing called drawing 1.dwg, then you repath it to a new drawing called Drawing 2.dwg, the name shown in the Xref pallete, under Reference Name, is still labelled Drawing 1.

As I am updating a set of drawings for which has now has been split into a west and east, i need the Reference Name to change as i am changing the path.

Any clues??

This will rename all xrefs to match their filenames:(vl-load-com)
(setq
doc (vla-get-activedocument(vlax-get-acad-object))
blocks (vla-get-blocks doc)
)
(vlax-for blk blocks
(if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-path (list blk))))
(vla-put-name blk (vl-filename-base (vla-get-path blk)))
)
)

irneb
2009-03-27, 03:01 PM
And to pick an xref to be loaded from another file, then also rename it:(vl-load-com)
;;; Rename & Reload XRef
(defun c:XRefRen (/ xn xo name)
(while (not xo) ;Check if something's selected
(if (setq xn (entsel "\nPick xref to rename & repath <or ENTER type name>: "))
;Ask use to pick (or Enter to give name)
(setq xn (car xn)) ;Getonly the ENAME
(setq xn (getstring "\nEnter XRef name: ")) ;Else ask for block name
) ;_ end of if
(cond
((= (type xn) 'ENAME) ;If ENAME
(setq xo (vlax-ename->vla-object xn)) ;Get object ref of block insert
(if (= (vla-Get-ObjectName xo) "AcDbBlockReference") ;Check if it's a block
(setq xo (vla-Item (vla-Get-Blocks (vla-Get-ActiveDocument (vlax-get-acad-object))) (vla-Get-Name xo)))
;Get block def object
(progn
(princ "\nThat's not a BLOCK object, only blocks can be XREFS.")
(setq xo nil)
) ;_ end of progn
) ;_ end of if
)
((= (type xn) 'STR)
(if (not (setq xo (vla-Item (vla-Get-Blocks (vla-Get-ActiveDocument (vlax-get-acad-object))) xn)))
;Get block def object
(progn
(princ "\nThat's not a BLOCK object, only blocks can be XREFS.")
(setq xo nil)
) ;_ end of progn
) ;_ end of if
)
) ;_ end of cond
(if xo
(if (not (= (vla-Get-ObjectName xo) "AcDbBlockTableRecord")) ;Check if it's a block
(progn
(princ "\nThat's not a BLOCK object, only blocks can be XREFS.")
(setq xo nil)
) ;_ end of progn
(if (/= (vla-Get-IsXref xo) :vlax-true) ;Check if it's a xref
(progn
(princ "\nThat's not a XREFS.")
(setq xo nil)
) ;_ end of progn
) ;_ end of if
) ;_ end of if
) ;_ end of if
) ;_ end of while

(if (and xo (setq name (getfiled "Browse DWG to replace XRef" (findfile (vla-get-Path xo)) "dwg" 0))) ;Pick file
(progn
(vla-Put-Name xo (vl-filename-base name))
(vla-Put-Path xo name)
(vla-Reload xo)
)
)
(princ)
) ;_ end of defun

haydenrosser
2009-04-07, 08:43 AM
This will rename all xrefs to match their filenames:(vl-load-com)
(setq
doc (vla-get-activedocument(vlax-get-acad-object))
blocks (vla-get-blocks doc)
)
(vlax-for blk blocks
(if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-path (list blk))))
(vla-put-name blk (vl-filename-base (vla-get-path blk)))
)
)

I am not much of a code wiz at all, but i cant seem to get the above code to work. it kept returning nil,

In order to run the list, i set the code up as below.


(vl-load-com)
;;;Rename Xrefs
(DEFUN C:XRENAME (/ DOC BLOCKS)
(setq
doc (vla-get-activedocument(vlax-get-acad-object))
blocks (vla-get-blocks doc)
)
(vlax-for blk blocks
(if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-path (list blk))))
(vla-put-name blk (vl-filename-base (vla-get-path blk)))
)
)
)


...any furhter help would be greatly appreciated, i have to go through and sort out a drawing set around 300 sheets making sure all th xrefs i correct and each drawing has around 70 xrefs.

mweaver
2009-04-08, 07:16 AM
I am not much of a code wiz at all, but i cant seem to get the above code to work. it kept returning nil,

In order to run the list, i set the code up as below.


(vl-load-com)
;;;Rename Xrefs
(DEFUN C:XRENAME (/ DOC BLOCKS)
(setq
doc (vla-get-activedocument(vlax-get-acad-object))
blocks (vla-get-blocks doc)
)
(vlax-for blk blocks
(if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-path (list blk))))
(vla-put-name blk (vl-filename-base (vla-get-path blk)))
)
)
)


...any furhter help would be greatly appreciated, i have to go through and sort out a drawing set around 300 sheets making sure all th xrefs i correct and each drawing has around 70 xrefs.

The code I posted (and your defun based on my code) will return nil - they should also rename your xrefs. Is this not happening?

I'll see what I can throw together that will let you do this with objectdbx (fast!!!)

mweaver
2009-04-08, 08:24 AM
This has very little testing, but should work.
Note that the c:rxdbx routine is really included for illustration purposes only. Any method to call RenameXrefsDBX with a list of fully qualified drawing names will do the job.

The drawings will be saved to the same directory as the originals with "Fixed-" on the front end of the filename. Unfortunately objectdbx won't let us do a save - we have to do a saveas.

I would expect this to process something like one drawing per second - with 70 xrefs per drawing.

Hope this helps.

(vl-load-com)

(defun c:rxdbx (/)
(setq
dir (getfiled "Select the first drawing in the folder of drawings"
(getvar "dwgprefix")
"dwg"
0
)
Files (vl-directory-files (vl-filename-directory dir) "*.dwg" 1)
Files (mapcar
(function
(lambda (file)
(strcat (vl-filename-directory dir) "\\" file)
)
)
Files
)
)
(RenameXrefsDBX Files)
)




(defun RenameXrefsDBX(FileList / Doc Blocks rtlist)
(mapcar
(function
(lambda(File / ChangedList)
(setq
doc (GetRemoteDoc file)
blocks (vla-get-blocks doc)
)
(vlax-for blk blocks
(if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-path (list blk))))
(progn
(setq oldname (vla-get-name blk))
(vla-put-name blk (vl-filename-base (vla-get-path blk)))
(if (not (equal (strcase oldname)(setq newname (strcase (vla-get-name blk)))))
(setq rtlist (cons (vl-list* File oldname newname) rtlist))
)
)
)
)
(if (equal doc (vla-get-activedocument(vlax-get-acad-object)))
(vla-save doc)
(vla-saveas doc (strcat (vl-filename-directory file) "\\Fixed-" (vl-filename-base file) ".dwg"))
)
)
)
FileList
)
rtlist
)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Function: GetRemoteDoc ;;;
;;; Purpose: Retrieves the document object for the specified drawing file, pulling it from ;;;
;;; the documents collection if it occurs there. ;;;
;;; Arguments: ;;;
;;; fname String - the fully qualified pathname of the source file, with ;;;
;;; extension. ;;;
;;; Returns: an objectDbx document object ;;;
;;; Note: Don't forget to release the object ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun GetRemoteDoc (fname / dbxstr dbxdoc objDocs ActiveDwg)
(setq
objDocs (vla-get-documents (vlax-get-acad-object))
ActiveDwg (strcase (findfile (strcat (getvar "dwgprefix") (getvar "dwgname"))))
)
(cond
;;it is the active drawing
((= (strcase (findfile fname)) ActiveDwg)
(vla-get-activedocument (vlax-get-acad-object))
)
;;It's already open
((and
;;The filename is in the documents collection
(null
(vl-catch-all-error-p
(setq dbxdoc (vl-catch-all-apply
'vla-item
(list
objdocs
(strcat (vl-filename-base fname) ".DWG")
)
)
)
)
)
;;The drawing in the documents collection has the correct path
(= (strcase (findfile fname)) (strcase (findfile (vla-get-fullname dbxdoc))))
) ;end and
dbxdoc
)
;;we can open it with objectdbx
((setq fname (findfile fname))
(setq
DBXstr (cond
((< (atof (getvar "ACADVER")) 16.0)
"ObjectDBX.AxDbDocument"
)
(T (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2)))
)
DBXDoc (vla-getinterfaceobject (vlax-get-acad-object) DBXstr)
)
(vla-open DBXDoc fname)
dbxdoc
) ;end cond findfile fname
) ;end cond
)