goorgoor Posted November 28, 2013 Posted November 28, 2013 I have tried "_.EXACRELOAD" and "-xr;r;*", BUT both of them turn the unloaded xref back on! I want to have this reload command in a LISP file, so everytime i run my lisp file it reloads only the those xref which needs to get reloaded. Is it a way to only update new xrefs that have been changed? Quote
BlackBox Posted December 2, 2013 Posted December 2, 2013 (vl-load-com) (defun c:FOO (/ *error* acDoc xrefs) (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) ) (vlax-for x (vla-get-blocks (setq acDoc (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (and (= :vlax-true (vla-get-isXref x)) (> (vla-get-count x) 0) ) (setq xrefs (cons x xrefs)) ) ) (if xrefs (progn (vla-startundomark acDoc) (foreach xref xrefs (vl-catch-all-apply 'vla-reload (list xref)) (prompt (strcat "\n >> Reloaded XREF >> \"" (vla-get-name xref) "\"" ) ) ) ) (prompt "\n** No loaded XREFs found ** ") ) (*error* nil) ) Quote
Lee Mac Posted December 2, 2013 Posted December 2, 2013 (> (vla-get-count x) 0) Careful with this one, as the count property in this case corresponds to the number of objects in the block definition, not the number of block references Lee Quote
BlackBox Posted December 3, 2013 Posted December 3, 2013 Careful with this one, as the count property in this case corresponds to the number of objects in the block definition, not the number of block references Hi Lee, I must be missing something, as in testing here this is successful even for nested XREFs... I do get a value greater than one (1) when loaded (depending on the drawing), but seem to always get zero (0) when unloaded... Is this not what you too observe? I'm sure there's another way to qualify if a reference is loaded via LISP API; how would you go about determining this? Cheers Quote
Lee Mac Posted December 3, 2013 Posted December 3, 2013 Good observation - when originally viewing your code I thought you were testing for references of the xref in the drawing, hence my clarification that the ActiveX count property related to the number of objects in the definition rather than the number of references in the drawing; however, I was not aware that all objects were removed from the block definition when an xref is unloaded - that's a new one for me! Lee Quote
BlackBox Posted December 3, 2013 Posted December 3, 2013 Good observation - when originally viewing your code I thought you were testing for references of the xref in the drawing, hence my clarification that the ActiveX count property related to the number of objects in the definition rather than the number of references in the drawing; however, I was not aware that all objects were removed from the block definition when an xref is unloaded - that's a new one for me! I was surprised to find that there is not a bool IsUnLoaded Property of the BlockTableRecord exposed to LISP / DXF. Cheers, mate Quote
goorgoor Posted December 5, 2013 Author Posted December 5, 2013 Here is my code where i pasted the code you provided. When i ran it, nothing happened! The Xref file i had changed didnt get updated/reloaded! (defun c:csab () (command "-layer" "S" "0" "") (command ".chprop" "all" "" "color" "bylayer" "ltype" "bylayer" "Lweight" "bylayer" "") (command ".layereval" "0") (command "-scalelistedit" "r" "y" "e") (command "qsave") (vl-load-com) (defun c:FOO (/ *error* acDoc xrefs) (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) ) (vlax-for x (vla-get-blocks (setq acDoc (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (and (= :vlax-true (vla-get-isXref x)) (> (vla-get-count x) 0) ) (setq xrefs (cons x xrefs)) ) ) (if xrefs (progn (vla-startundomark acDoc) (foreach xref xrefs (vl-catch-all-apply 'vla-reload (list xref)) (prompt (strcat "\n >> Reloaded XREF >> \"" (vla-get-name xref) "\"" ) ) ) ) (prompt "\n** No loaded XREFs found ** ") ) (*error* nil) ) ) Quote
BlackBox Posted December 5, 2013 Posted December 5, 2013 Here is my code where i pasted the code you provided. When i ran it, nothing happened! The Xref file i had changed didnt get updated/reloaded! That's because you've defined c:FOO, but never invoked (called) it... As a quick adaptation to your code, give this a try: (vl-load-com) (defun c:FOO (/ *error* acDoc xrefs) (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) ) (vlax-for x (vla-get-blocks (setq acDoc (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (and (= :vlax-true (vla-get-isXref x)) (> (vla-get-count x) 0) ) (setq xrefs (cons x xrefs)) ) ) (if xrefs (progn (vla-startundomark acDoc) (foreach xref xrefs (vl-catch-all-apply 'vla-reload (list xref)) (prompt (strcat "\n >> Reloaded XREF >> \"" (vla-get-name xref) "\"" ) ) ) ) (prompt "\n** No loaded XREFs found ** ") ) (*error* nil) ) (defun c:CSAB () (foreach x (list '(clayer "0") '(layereval 0) ) (vl-catch-all-apply 'setvar x) ) (command "._setbylayer" "_all" "" "_y" "_y" "._-scalelistedit" "_r" "_y" "_e" "._qsave" ) (c:FOO) (princ) ) Quote
goorgoor Posted December 6, 2013 Author Posted December 6, 2013 That worked fine Thanks I want also to know if i add some more code to what you have provided above, can i just add it after: (command [b]"._layer" "_S" "_0" "*"[/b] [b]"._purge" "_a" "*" "_n"[/b] "._setbylayer" "_all" "" "_y" "_y" "._-scalelistedit" "_r" "_y" "_e" "._qsave" Also...could you tell me what these code does? vla-get-blocks vla-get-activedocument (vlax-get-acad-object) (= :vlax-true (vla-get-isXref x)) (> (vla-get-count x) 0) (vl-catch-all-apply 'vla-reload (list xref)) Will the code you provided only update the xref which are not been reloaded or will it do other thing as well, like resetting the layer and scale and mess things up Quote
BlackBox Posted December 6, 2013 Posted December 6, 2013 I want also to know if i add some more code to what you have provided above, can i just add it after: (command [b]"._layer" "_S" "_0" "*"[/b] [b]"._purge" "_a" "*" "_n"[/b] "._setbylayer" "_all" "" "_y" "_y" "._-scalelistedit" "_r" "_y" "_e" "._qsave" So long as it is part of a Command function call, you *should* be able to add it... Just be sure to account for all parameters. Be mindful that some sysvars can affect what parameters are needed. Also...could you tell me what these code does? vla-get-blocks vla-get-activedocument (vlax-get-acad-object) (= :vlax-true (vla-get-isXref x)) (> (vla-get-count x) 0) (vl-catch-all-apply 'vla-reload (list xref)) That code segment iterates the BlockTable, and if each BlockTableRecord is both an Xref, and has a Count greater than zero (read: poor mans API for determining if an Xref is loaded), it reloads the Xref. Will the code you provided only update the xref which are not been reloaded or will it do other thing as well, like resetting the layer and scale and mess things up Unfortunately, to the best of my knowledge, LISP has no way of determining if an Xref has changes... So the code above reloads all loaded Xrefs (skipping those that are unloaded). Cheers Quote
goorgoor Posted December 10, 2013 Author Posted December 10, 2013 Those more commands didnt work! I dont think that i call for them as well. No Purge happenes here :-( APPLOAD foo.lsp successfully loaded. Command: Command: Command: FOO >> Reloaded XREF >> "1GBEN_ISO-METRIC" Command: (vl-load-com) (defun c:FOO (/ *error* acDoc xrefs) (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) ) (vlax-for x (vla-get-blocks (setq acDoc (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (and (= :vlax-true (vla-get-isXref x)) (> (vla-get-count x) 0) ) (setq xrefs (cons x xrefs)) ) ) (if xrefs (progn (vla-startundomark acDoc) (foreach xref xrefs (vl-catch-all-apply 'vla-reload (list xref)) (prompt (strcat "\n >> Reloaded XREF >> \"" (vla-get-name xref) "\"" ) ) ) ) (prompt "\n** No loaded XREFs found ** ") ) (*error* nil) ) (defun c:CSAB () (foreach x (list '(clayer "0") '(layereval 0) ) (vl-catch-all-apply 'setvar x) ) (command "._setbylayer" "_all" "" "_y" "_y" "._-scalelistedit" "_r" "_y" "_e" "-purge" "r" "*" "n" "._qsave" ) (c:FOO) (princ) ) Quote
2cook2 Posted January 23, 2014 Posted January 23, 2014 Is there a way to have this reload only the xrefs that have been changed? I have numerous xrefs and it would be quicker than to reload all. Thanks ScottL Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.