Can I change xref name and path in autolisp / visuallisp??
Please give me some hint!!!
|
Can I change xref name and path in autolisp / visuallisp??
Please give me some hint!!!
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
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) )
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)
Just out of curosity Marko, why use this line of code?
And where does it come from?Code:(c:revert)
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))
You are wright Alan,...
My apology, I missed the point that I can reload replaced xref witch will update its name in EXTERNALREFERENCES dialog box...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) )
Sincerely, M.R.
Last edited by marko_ribar; 2011-12-09 at 02:32 PM.
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.
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
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