Results 1 to 6 of 6

Thread: Need LSP: Rename Reference Name in Xref pallette to match File Name

  1. #1
    Member
    Join Date
    2008-10
    Posts
    2
    Login to Give a bone
    0

    Default Need LSP: Rename Reference Name in Xref pallette to match File Name

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

  2. #2
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: Need LSP: Rename Reference Name in Xref pallette to match File Name

    Quote Originally Posted by haydenrosser View Post
    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:
    Code:
    (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)))
        )
      )

  3. #3
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Need LSP: Rename Reference Name in Xref pallette to match File Name

    And to pick an xref to be loaded from another file, then also rename it:
    Code:
    (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

  4. #4
    Member
    Join Date
    2008-10
    Posts
    2
    Login to Give a bone
    0

    Unhappy Re: Need LSP: Rename Reference Name in Xref pallette to match File Name

    Quote Originally Posted by mweaver View Post
    This will rename all xrefs to match their filenames:
    Code:
    (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.

    Code:
    (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.

  5. #5
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: Need LSP: Rename Reference Name in Xref pallette to match File Name

    Quote Originally Posted by haydenrosser View Post
    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.

    Code:
    (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!!!)

  6. #6
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: Need LSP: Rename Reference Name in Xref pallette to match File Name

    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.

    Code:
    (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
    )

Similar Threads

  1. Change xref colors to match the output file
    By cadd4la in forum AutoLISP
    Replies: 6
    Last Post: 2014-11-10, 12:58 PM
  2. Replies: 0
    Last Post: 2013-02-22, 07:07 PM
  3. Display xref names in "References - Unsolved Reference File" dialogbox
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2013-02-17, 01:40 PM
  4. Use Reference Manager to rename and relink XREFS
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 2
    Last Post: 2012-05-18, 11:51 AM
  5. To Rename an XREF
    By andrewp in forum AutoCAD General
    Replies: 8
    Last Post: 2006-08-16, 07:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •