Jump to content

Recommended Posts

Posted

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?

Posted
(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)
)

Posted
       (> (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

Posted
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

Posted

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

Posted
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 :)

Posted

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

Posted
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)
)

Posted

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 :oops:

Posted

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 :oops:

 

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

Posted

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

  • 1 month later...
Posted

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...