Layer regen problem

Sa Mite Samite

Usenet Archive
Joined
Jul 29, 2003
Messages
17
Reaction score
0
Here is one of strange things I notice in AutoCAD 2000 & + (not in 14 version). Place do this experiment.

Freeze all layers then manually; for simplicity turn all layers ON, unlock them. Then, PROGRAMATICALLY, using entmod & entupd (does not work on this case) THAW all layers. Even though the layer dialog box will show that all layers are ON and THAWED, regardless of the attempts to regen or regenall, the layer state on the screen will not be updated unless you MANUALLY freeze at least on layer, then thaw it on the DIALOG BOX. Is this bug or one of the AutoCAD improvements?

Because you may not have a LISP routine to do so, I'm including mine simplified one. Note, that there is no error trap set up in any of the following procedures. If you will need to iuse them in the future make sure improve them.

Here is a routine to SAVE the layer state:

(defun LayerState_Save ( / ref ret)

(while (setq ref (tblnext "LAYER" (not ref)))

(setq ret (append ret (list (list (cdr (assoc 2 ref))

(cdr (assoc 62 ref))

(cdr (assoc 6 ref))

(cdr (assoc 70 ref))

)))))

)

Here is a routine to RESTORE the layer state:

(defun LayerState_Restore (REF / enl enm)

(while REF

(and (setq enm (tblobjname "LAYER" (nth 0 (car REF))))

(setq enl (entget enm))

(setq enl (subst (cons 62 (nth 1 (car REF)))

(assoc 62 enl) enl)

enl (subst (cons 6 (nth 2 (car REF)))

(assoc 6 enl) enl)

enl (subst (cons 70 (nth 3 (car REF)))

(assoc 70 enl) enl))

(entmod enl))

(setq REF (cdr REF)))

(princ)

)

So, what you do, you save first

(setq a (LayerState_Save))

than after you follow the instruction above you restore the layer state PROGRAMATICALLY.

(LayerState_Restore A)

then

type, regenall

NOTHING CHANGED ON THE SCREEN.
 
the solution to this is to (entupd) all the entities on those layers

my custom layer manager does that, in fact its more complicated...

the first step might be to (entupd) entities on those layers but then you have to scan all selectable blocks NOT on those layers- for if they contain nested objects on those layers, then you need to (entupd) the block.

the resulting 'regen' is actually FASTER than a regenall most of the time!!!

not only is there potentially faster regens but you dont get the heart-stopping screen flicker, reminiscent of smooth R12 autocad regens. also, to regen a layer doesnt require regenerating a previously hidden view. under certain circumstances, it does take a longer time to scan the block tables and select objects (entupd) than autocads regen command, but it is a minor difference.

the reason i defined my own layer manager is to go back to the simplicity of the old autocad layer manager. plus added functionality. the smooth regens were a bonus.

one difficulty may be trying to honor draworder settings. that is, objects are drawn in the order they were created. <<maybe not... does (ssget) use draworder tables to sort its result?>> but if your like me, draworder has no value anyway

if you develop a (regen_layers <layer_list>) function, use all your skill to make the loops as fast as possible, optimize the process by breaking up <layer_list> into internal layers and external layers (xrefs) then (ssget "A" objects_on_the_internal_layers) (foreach_ename_in_ss (entupd ename)) then (ssget "A" blocks_NOT_on_the_internal_layers) (foreach_ename_in_ss ;if it hasnt been scanned already (scan_the_block_for (internal_layers-OR-external_layers)) ;if it contains a layer in <layer_list> then:
(entupd ename)
)

dont forget to scan nested blocks (recursion)

when your done with your function, i'll race you with mine
 
I recall someone here mentioning a bug when using
vanilla lisp to do this. I believe the solution was to either use (command) or resort to activex functions.
 

Latest threads

Back
Top