Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Change xref name and path

  1. #1
    Member
    Join Date
    2011-02
    Posts
    17
    Login to Give a bone
    0

    Default Change xref name and path

    Can I change xref name and path in autolisp / visuallisp??

    Please give me some hint!!!

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Yes, you can.

    Hint: Look into the VLAX-DUMP-OBJECT function.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Quote Originally Posted by krkeec763189 View Post
    Can I change xref name and path in autolisp / visuallisp??
    This would change the name of the selected Xref and replace it with the entered one .

    Code:
    (defun c:TesT (/ ss name)
    ;;; Tharwat 05. Dec. 2011 ;;;
      (if (and (not (eq (setq name (getstring t "\n Enter new name for Xref :")) ""))
               (setq ss (car (entsel "\n Select Xref :")))
               (vlax-property-available-p (vlax-ename->vla-object ss) 'Path)
          )
        (vla-put-name
          (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
                    (cdr (assoc 2 (entget ss)))
          )
          name
        )
        (cond ((eq name "") (princ "\n New name of Xref cann't be nil "))
              ((not ss) (princ "\n Missed to select Xref "))
              (t (princ "\n Your selection is not Xref drawing !! "))
        )
      )
      (princ)
    )

  4. #4
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Look here - XrefRename

    M.R.


    As you can see, maybe you wanted replacing Xref with new one :

    Code:
    (defun c:replacexref ( / xrent xrnew xrdir xrnnam xrfile ) (vl-load-com)
      (if (setq xrent (car (entsel "\nSelect Xref to change to other Xref : ")))
        (progn
          (setq xrnew (getfiled "Select new Xref" "" "dwg" 16))
          (setq xrdir (vl-filename-directory xrnew))
          (setq xrnnam (vl-filename-base xrnew))
          (setq xrfile (strcat xrnnam (vl-filename-extension xrnew)))
          (if (eq (getvar 'dwgprefix) (strcat xrdir "\\"))
            (vl-cmdf "-xref" "p" (cdr (assoc 2 (entget xrent))) xrfile)
            (vl-cmdf "-xref" "p" (cdr (assoc 2 (entget xrent))) xrnew)
          )
          (vla-put-Name
          (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
                    (cdr (assoc 2 (entget xrent)))
            )
            xrnnam
          )
          (vla-save (vla-get-activedocument (vlax-get-acad-object)))
          (c:revert)
        )
        (prompt "\nMissed selecting Xref")
      )
    (princ)
    )
    Last edited by marko_ribar; 2011-12-05 at 03:17 PM. Reason: still back to (getfiled "Select new Xref" "" "dwg" 16) instead of (getfiled "Select new Xref" "" "dwg" 8)

  5. #5
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Just out of curosity Marko, why use this line of code?
    Code:
    (c:revert)
    And where does it come from?

    Cheers.

  6. #6
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Quote Originally Posted by jmcshane View Post
    Just out of curosity Marko, why use this line of code?
    Code:
    (c:revert)
    And where does it come from?

    Cheers.
    It's a call to the Express Tool Revert command (reopen and revert to last saved state).
    I think it's attempt to reload the xrefs (reloaded on startup), but one can easily reload all xrefs (command or vl). Hell, I use this macro on a daily basis...

    Code:
    ;RELOAD ALL XREFS
    (defun c:XE (/) (command "_.-xref" "_RELOAD" "*" ) (princ))

  7. #7
    100 Club
    Join Date
    2003-11
    Location
    Dublin, Ireland.
    Posts
    152
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Thanks Alan.

  8. #8
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Change xref name and path

    You are wright Alan,...

    Code:
    (defun c:replacexref ( / xrent xrnew xrdir xrnnam xrfile ) (vl-load-com)
      (if (setq xrent (car (entsel "\nSelect Xref to change to other Xref : ")))
        (progn
          (setq xrnew (getfiled "Select new Xref" "" "dwg" 16))
          (setq xrdir (vl-filename-directory xrnew))
          (setq xrnnam (vl-filename-base xrnew))
          (setq xrfile (strcat xrnnam (vl-filename-extension xrnew)))
          (if (eq (getvar 'dwgprefix) (strcat xrdir "\\"))
            (vl-cmdf "-xref" "p" (cdr (assoc 2 (entget xrent))) xrfile)
            (vl-cmdf "-xref" "p" (cdr (assoc 2 (entget xrent))) xrnew)
          )
          (vla-put-Name
          (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
                    (cdr (assoc 2 (entget xrent)))
            )
            xrnnam
          )
          (command "_.-XREF" "RELOAD" "*")
        )
        (prompt "\nMissed selecting Xref")
      )
    (princ)
    )
    My apology, I missed the point that I can reload replaced xref witch will update its name in EXTERNALREFERENCES dialog box...

    Sincerely, M.R.
    Last edited by marko_ribar; 2011-12-09 at 02:32 PM.

  9. #9
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Quote Originally Posted by marko_ribar View Post
    You are wright Alan,...

    Code:
    (defun c:replacexref ( / xrent xrnew xrdir xrnnam xrfile ) (vl-load-com)
      (if (setq xrent (car (entsel "\nSelect Xref to change to other Xref : ")))
        (progn
          (setq xrnew (getfiled "Select new Xref" "" "dwg" 16))
          (setq xrdir (vl-filename-directory xrnew))
          (setq xrnnam (vl-filename-base xrnew))
          (setq xrfile (strcat xrnnam (vl-filename-extension xrnew)))
          (if (eq (getvar 'dwgprefix) (strcat xrdir "\\"))
            (vl-cmdf "-xref" "p" (cdr (assoc 2 (entget xrent))) xrfile)
            (vl-cmdf "-xref" "p" (cdr (assoc 2 (entget xrent))) xrnew)
          )
          (vla-put-Name
          (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object)))
                    (cdr (assoc 2 (entget xrent)))
            )
            xrnnam
          )
          (command "_.-XREF" "RELOAD" "*")
        )
        (prompt "\nMissed selecting Xref")
      )
    (princ)
    )
    My apology, I missed the point that I can reload replaced xref witch will update its name in EXTERNALREFERENCES dialog box...

    Sincerely, M.R.
    No worries.
    I would only reload the target xref, rather than all. I know of plenty of occasions when one might have only a few of the many xrefs loaded and wouldn't want them reloaded just then. Plus, it's just good programming. The only thing you should assume is that the user has the worst possible setup.

  10. #10
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Change xref name and path

    Only because this is loosely related...

    Quote Originally Posted by alanjt View Post
    I would only reload the target xref, rather than all. I know of plenty of occasions when one might have only a few of the many xrefs loaded and wouldn't want them reloaded just then. Plus, it's just good programming. The only thing you should assume is that the user has the worst possible setup.
    Written a while ago; I'm sure there's some streamlining to be done, but FWIW -

    ** Implied selection accepted

    Code:
    (defun c:XRR () (c:XrefReload))
    (defun c:XrefReload  (/ *error* _Reload)
      (princ "\rXREF: RELOAD ")
      (vl-load-com)
    
      (defun *error*  (msg)
        (if acDoc
          (vla-endundomark acDoc))
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** "))))                 ; Fatal error, display it
        (princ))
    
      (defun _Reload  (arg)
        ((lambda (oBlocks / typ)
           (cond
             ((= 'VLA-OBJECT (setq typ (type arg)))
              (if (and (vlax-property-available-p arg 'isxref)
                       (= :vlax-true (vla-get-isxref arg)))
                (progn
                  (vl-catch-all-apply 'vla-reload (list arg))
                  (prompt (strcat "\n  >>  Reloaded XREF  >>  \""
                                  (vla-get-name arg)
                                  "\"")))
                (prompt "\n** Selected object is not an external reference ** ")))
             ((= 'LIST typ)
              (foreach name arg (_Reload (vla-item oBlocks name))))
             ((= 'PICKSET typ)
              (vlax-for x
                        (setq ss (vla-get-activeselectionset acDoc))
                (_Reload (vla-item oBlocks (vla-get-name x))))
              (vla-delete ss))))
          (vla-get-blocks acDoc)))
    
      ((lambda (acDoc / ss)
         (vla-startundomark acDoc)
         (cond
    
           ;; Implied reference selection
           ((setq ss (ssget "_I" '((0 . "INSERT") (8 . "XREF"))))
             (sssetfirst nil)
             (_Reload ss))
    
           ;; Manually select from a list of all blocks on xref layer
           ((setq ss (ssget "_x" '((0 . "INSERT") (8 . "XREF"))))
            (prompt
              "\n** Note - An underscore (\"_\") will display as a period (\".\") ** ")
            ((lambda (/ lst opt)
               (vla-startundomark acDoc)
               (vlax-for x
                         (setq ss (vla-get-activeselectionset acDoc))
                 (setq lst (cons (vla-get-name x) lst)))
               (setq lst (vl-sort lst '<))
               (vla-delete ss)
               (initget
                 (setq opt
                        (vl-string-right-trim
                          " "
                          (vl-string-translate
                            "_"
                            "."
                            (strcat
                              "All "
                              (apply
                                'strcat
                                (mapcar '(lambda (x) (strcat x " ")) lst)))))))
               (if (or (setq n
                              (getkword
                                (strcat
                                  "\nEnter XREF to reload ["
                                  (vl-string-right-trim
                                    "/"
                                    (vl-string-translate " " "/" opt))
                                  "]<All>: ")))
                       (setq n "ALL"))
                 (if (wcmatch (strcase n) "A*,ALL")
                   (_Reload lst)
                   (_Reload (list n)))))))
    
           ;; No references exist
           ((prompt
              "\n** No external references found in active drawing ** ")))
         (*error* nil))
        (vla-get-activedocument (vlax-get-acad-object))))
    Last edited by BlackBox; 2016-07-29 at 04:24 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Page 1 of 2 12 LastLast

Similar Threads

  1. Change xref path type
    By jdcincy in forum AutoLISP
    Replies: 14
    Last Post: 2012-04-24, 04:50 PM
  2. rename and change xref path
    By krkeec763189 in forum Dot Net API
    Replies: 0
    Last Post: 2011-12-22, 01:29 PM
  3. Replies: 16
    Last Post: 2010-10-15, 04:36 PM
  4. Change Xref from Full Path to Relative Path
    By ccowgill in forum AutoLISP
    Replies: 6
    Last Post: 2009-05-27, 11:54 AM
  5. Replies: 1
    Last Post: 2007-05-05, 02:59 PM

Posting Permissions

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