View Full Version : Change xref name and path
krkeec763189
2011-12-05, 07:00 AM
Can I change xref name and path in autolisp / visuallisp??
Please give me some hint!!!
BlackBox
2011-12-05, 07:45 AM
Yes, you can.
Hint: Look into the VLAX-DUMP-OBJECT function. :wink:
Tharwat
2011-12-05, 08:38 AM
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 . ;)
(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)
)
marko_ribar
2011-12-05, 12:16 PM
Look here - XrefRename (http://www.jtbworld.com/lisp/XrefRename.htm)
M.R.
:)
As you can see, maybe you wanted replacing Xref with new one :
(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)
)
jmcshane
2011-12-08, 05:49 PM
Just out of curosity Marko, why use this line of code?
(c:revert)
And where does it come from?
Cheers.
alanjt
2011-12-08, 08:37 PM
Just out of curosity Marko, why use this line of 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...
;RELOAD ALL XREFS
(defun c:XE (/) (command "_.-xref" "_RELOAD" "*" ) (princ))
jmcshane
2011-12-09, 09:18 AM
Thanks Alan.
marko_ribar
2011-12-09, 10:29 AM
You are wright Alan,...
(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.
alanjt
2011-12-09, 01:05 PM
You are wright Alan,...
(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.
BlackBox
2011-12-09, 02:57 PM
Only because this is loosely related...
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
(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))))
Only because this is loosely related...
Written a while ago; I'm sure there's some streamlining to be done, but FWIW -
** Implied selection accepted
I know what you mean. :p
BlackBox
2011-12-13, 06:56 AM
I know what you mean. :p
My how our definitions of "a while ago" are different. :p LoL
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.