Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Toggle Layer Help

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Jonathan3891
876 Views, 13 Replies

Toggle Layer Help

I cant figure out the problem with this lisp file.

 

If the layer is already frozen upon opening the drawing it wont work. I have to manually unfreeze it for this lisp to start working.

 

Any help would be appreciated.

 

(defun MVT nil (FreezeThawLayer "Model Views")
(princ)
)

(defun FreezeThawLayer ( layer / dx en )
    (if (null (setq en (tblobjname "LAYER" layer)))
        (entmake
            (list
               '(0 . "LAYER")
               '(100 . "AcDbSymbolTableRecord")
               '(100 . "AcDbLayerTableRecord")
                (cons 2 layer)
               '(70 . 0)
            )
        )
        (setq en (entget en)
              dx (assoc 70 en)
              en (entmod (subst (cons 70 (boole 6 1 (cdr dx))) dx en))
        )
    )
    (princ)
)

 

 


Jonathan Norton
Blog | Linkedin
13 REPLIES 13
Message 2 of 14
ВeekeeCZ
in reply to: Jonathan3891

I just tried your code and it DOES work (C3D 2020). 

 

Just sidenote. Don't like a bit that code allows freezing of the current layer. That should be excluded.

Message 3 of 14
Kent1Cooper
in reply to: Jonathan3891

It worked for me [Acad2019] -- I don't know what to suggest [having no failure to analyze].

Kent Cooper, AIA
Message 4 of 14
Jonathan3891
in reply to: Kent1Cooper

Maybe its something with Advance Steel. It can be fickle at times with certain pieces of lisp code.

 

It likes to reject variables.


Jonathan Norton
Blog | Linkedin
Message 5 of 14
cadffm
in reply to: Jonathan3891

It's not working in plain AutoCAD (for this situation you talk about),

so it isn't a advance steel thing- It's a core AutpCAD thing.

 

To correct the statement "I have to manually unfreeze it for this lisp to start working."

@Anonymous

The code works a also in this situation as expected, but the layer objects are still not displaying!

The Layer is thawed, new objects on this layer are visible too, but not the older existed objects.

Sebastian

Message 6 of 14
dlanorh
in reply to: Jonathan3891

It needs a regen or an (entupd)

 

(defun MVT nil (FreezeThawLayer "Model Views")
(princ)
)

(defun FreezeThawLayer ( layer / dx en el)
    (if (null (setq en (tblobjname "LAYER" layer)))
        (entmake
            (list
               '(0 . "LAYER")
               '(100 . "AcDbSymbolTableRecord")
               '(100 . "AcDbLayerTableRecord")
                (cons 2 layer)
               '(70 . 0)
            )
        )
        (setq el (entget en)
              dx (assoc 70 el)
              el (entmod (subst (cons 70 (boole 6 1 (cdr dx))) dx el))
        )
    )
    (if en (entupd en))
    (princ)
)

 

I am not one of the robots you're looking for

Message 7 of 14
cadffm
in reply to: dlanorh


@dlanorh  schrieb:

It needs a regen or an (entupd)


 

Just guessing or also tested?

It will not change the problem (tested with a simple plain AutoCAD-DWG in ACAD 2013,2021 and also with C3D2021).

1. Objects in model tab,  layer was freezed and current view is in model tab > at the last save

2. Open the file, run the program

3. Layer is thawed after (FreezeThawLayer "Model Views"),

    new objects on this layer appears but the old objects  are still not visible

 

Switch to Layout TAB and back to model will fix the problem.

_tilemode 0 _tilemode 1

but this isn't a smart way.

 

@dlanorh 

Do you know how to reproduce the problem yourself (according to my instructions)?

Sebastian

Message 8 of 14
Kent1Cooper
in reply to: Jonathan3891


@Jonathan3891 wrote:

....

If the layer is already frozen upon opening the drawing it wont work. ....


The discussion of whether a REGEN is needed raises the question:  What does "it wont work" above mean?  Have you tried using it and then REGEN-ing to make what's on that Layer appear?  Or does it not Thaw the Layer at all?  Or is the not-working some other issue?

 

It certainly was once true that if a Layer was frozen when the drawing was opened, AutoCAD had not thought about what's on that Layer at all yet, and if you then Thawed it, it was necessary to REGEN to see that content.  But now it doesn't seem to be needed, at least in a quickie trial, but maybe there are other circumstances I haven't thought of that can sometimes still make it necessary.

Kent Cooper, AIA
Message 9 of 14
cadffm
in reply to: Kent1Cooper

1. Objects in model tab,  layer was freezed and current view is in model tab > at the last save

2. Open the file, run the program

3. Layer is thawed after (FreezeThawLayer "Model Views"),

    new objects on this layer appears but the old objects  are still not visible

 

REGEN

REGENALL

REDRAW

REDRAWALL

ZOOM

PAN

creating new objects

entupd (the Layer)

entupd (the object)

 

still invisible

 

edit the object(s) by command like MOVE

or ENTMOD the object

or switching to a layout and back to model tab

 

and the objects appears

Sebastian

Message 10 of 14
Jonathan3891
in reply to: cadffm

3D orbit makes the objects on said layer appear as well.


Jonathan Norton
Blog | Linkedin
Message 11 of 14
cadffm
in reply to: Jonathan3891

Time to go other ways, use the extended VisualLisp  functions

 

 


(setq LAYER (vla-item (vla-get-layers (vla-get-activeDocument(vlax-get-Acad-Object))) "Model views"))

 

(vla-put-Freeze LAYER :vlax-false) / (vla-put-Freeze LAYER :vlax-true)

 

 

 

Sebastian

Message 12 of 14
dlanorh
in reply to: cadffm

Tested, in 2012 with a named view. I cannot test any later versions of AutoCAD. The OP needs to supply a standard example drawing otherwise we are all testing in the dark. If it works on some systems and not others this suggests a possible different system variable setting somewhere.

I am not one of the robots you're looking for

Message 13 of 14
Kent1Cooper
in reply to: Jonathan3891

How about going the other way, to the more simple and direct Layer command?  Does it work for you this way [it does for me, but then so did your original]?

 

(defun FreezeThawLayer (layer / laydata)
  (if (not (setq laydata (tblsearch "LAYER" layer)))
    (command "_.layer" "_make" layer ""); then
    (command "_.layer" ; else
      (if (= (logand 1 (cdr (assoc 70 laydata))) 1); frozen?
        "_thaw" ; then
        "_freeze" ; else
      ); if
      layer ""
;;;     "_.regen"  ;;; optional if needed?
    ); command
  ); if
  (princ)
); defun

 

[It should perhaps also have something added to prevent Freezing the current Layer, but it will simply fail if you try it on that Layer, so maybe the resulting error message would be enough -- it's not like you're going to want it to Freeze some other Layer in that situation.]

Kent Cooper, AIA
Message 14 of 14
Jonathan3891
in reply to: Kent1Cooper

Works great! Thanks again Kent!

Jonathan Norton
Blog | Linkedin

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report