Jump to content

A button macro to Thaw frozen layers and Freeze thawed layers


Recommended Posts

I use LT, so can only implement macros & DIESEL solutions.

 

Can anyone think of a way to write a command that would toggle the frozen and thawed layers?

 

To my knowledge I cannot use a Layer State because there are user generated layers that are unique with each drawing.

 

Ultimately I delete the frozen layers and all objects on those layers, so anything that can return a list of layers from within a macro would be amazing.

Link to comment
Share on other sites

No such thing as a command or macro to Toggle OFF/ON layers or FROZEN/THAWED layers?

 

If I was Autodesk I would make a LAYSWITCHFROZEN command.

Link to comment
Share on other sites

Autodesk dont need to do it as it can be done via a program in various ways but not in LT

 

Somebody out there if you can export a layer list LT!!! name and on/off etc then you could easily write a script (excel) to change layer states.

Link to comment
Share on other sites

I had never thought of this. Perhaps it is possible to import the layer list into a script file and let that populate which layers are set to frozen and which are set to thawed. Brilliant. I do not know how to export in this way, but I will look into it regardless. Thanks BIGAL.

Link to comment
Share on other sites

Can you run the command layerstate its on the layers window as a button and you can save all on all off etc it would then be possible to change the file to the opposite and reload. you would load in say notepad and do a search replace

Link to comment
Share on other sites

The best I can come up with (without LISP):

 

Thaw all layers:

^C^C^P._-layer;"thaw";"*";;

 

Restore layers:

^C^C^P._layerp;

 

Note that this will not account for any layer changes made once thawed. To have more functionality, LISP (or other code) is required

Edited by BlackBox
Link to comment
Share on other sites

Had a quick go at this and layerstates apears to be supported by LT.

 

Ok now how to do it layerstates export out it will write a las file which is a txt file you will find in this file two lines for every layer, 90 then say 11 which is = Off & frozen 90 3 = no plot 90 10 =frozen 90 0 = on & Thaw & no plot

 

In word you can edit two lines in one go if you just change the 3 to say 11 it may screw up the las file color No 3, if a layer has a 11 in the name, you need to do a search and replace at least 4 times, do a macro and save it first is to put a dummy number in for Frozen say fXXXX then a dummy number for on onxxxx and so on then swap Fxxxx for a new ON number else you will make everything ON and can not work out what should be turned off.

 

Make the edits then reload your las file. eg search replace 90^p3 with 90^pFxxx the ^p is end of line hence in middle changes 2 lines

 

Hope this makes sense if you struggle with the word part post here once you have the macro done it would only take a min or two to do.

 

heres the word macro for one change just copy paste contents for each on of frozen no plot etc

Sub OnOff()
'
' OnOff Macro
' Macro recorded 8/3/2011 by
'
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = "90^p0"
       .Replacement.Text = "90^ponthawnoplot"
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Link to comment
Share on other sites

  • 3 months later...

So sorry BIGAL, I only just noticed yours and Renderman's additional suggestions.

 

I have not solved this yet, just haven't had a break in the workflow to do much 'tinkering'.

 

I have found this menu when you right-click in the Layer Properties Manager. If I sort layers by ON/OFF then select all the OFF layers I can switch them ON, then right-click, Invert Selection and switch these layes OFF.

Layer Props Right Click Menu.jpg

 

Still clumsier than I hoped. I wish AutoCAD had a function to toggle a layer setting across all layers.

 

Anyway, trust you BIGAL to have an ambitious solution. I love it. I will keep working on this, but have hit a snag trying to write the macro to export a LAYERSTATE. It seems that I cannot do it without a dialog box.

Link to comment
Share on other sites

Thanks for your input Dadgad and Manila Wolf.

 

As a small scale example I have attached a picture of my layer properties manager.

 

Layer FreezeThaw Toggle.PNG

 

What I am trying to acheive is a button macro that will delete all the layers that are frozen, and the objects that are on them.

 

At the moment I do this all a slow way using the following steps:

 

1. Button to lock all layers:

^C^C_layer LO * ^C^C

 

2. Then Thaw and Unlock the frozen layers (in layer properties manager GUI), then Select All objects in the model, then Erase.

 

3. And finish with the button to unlock all layers:

^C^C_layer U * ^C^C

 

I'm hoping to streamline the step 2. But this is usually where you meet the end of macro's capabilities and need to start using LISP, so I'm not holding out much hope.

Link to comment
Share on other sites

  • 1 month later...
No such thing as a command or macro to Toggle OFF/ON layers or FROZEN/THAWED layers?

 

If I was Autodesk I would make a LAYSWITCHFROZEN command.

 

Just for fun, this is the best I could do so quickly - I may need to revise the regen step - but give this a try:

 

(defun c:LAYSWAP  (/ *error* _swapVal _layswap)
 (vl-load-com)
 (princ "\rLAYSWAP ")

 (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 _swapVal  (val)
   (if (= :vlax-true val)
     :vlax-false
     :vlax-true))

 (defun _layswap  (oLayer lst)
   (foreach item  lst
     (eval item)))

 ((lambda (acDoc cLayer / mode)
    (initget "ALL FREEZE ON LOCK PLOT")
    (if (or (setq mode
                   (getkword
                     "\nSpecify mode [All/Freeze/On/Lock/Plot] <Freeze>: "))
            (not mode))
      (progn
        (vla-startundomark acDoc)
        (vlax-for oLayer  (vla-get-layers acDoc)
          (if (/= (vla-get-name oLayer) cLayer)
            (cond
              ((or (= nil mode) (= "FREEZE" mode))
               (_layswap
                 oLayer
                 (list '(vla-put-freeze
                         oLayer
                         (_swapVal (vla-get-freeze oLayer))))))
              ((= "ALL" mode)
               (_layswap
                 oLayer
                 (list '(vla-put-freeze
                         oLayer
                         (_swapVal (vla-get-freeze oLayer)))
                       '(vla-put-layeron
                         oLayer
                         (_swapVal (vla-get-layeron oLayer)))
                       '(vla-put-lock
                         oLayer
                         (_swapVal (vla-get-lock oLayer)))
                       '(vla-put-plottable
                         oLayer
                         (_swapVal (vla-get-plottable oLayer))))))
              ((= "ON" mode)
               (_layswap
                 oLayer
                 (list '(vla-put-layeron
                         oLayer
                         (_swapVal (vla-get-layeron oLayer))))))
              ((= "LOCK" mode)
               (_layswap
                 oLayer
                 (list '(vla-put-lock
                         oLayer
                         (_swapVal (vla-get-lock oLayer))))))
              ((= "PLOT" mode)
               (_layswap
                 oLayer
                 (list '(vla-put-plottable
                         oLayer
                         (_swapVal (vla-get-plottable oLayer)))))))))
        ;;(vla-regen acDoc acAllViewports)
        (vl-cmdf "._regenall")
        ))
    (*error* nil))
   (vla-get-activedocument (vlax-get-acad-object))
   (getvar 'clayer)))

 

Performing a LAYSWAP of the same option again will 'undo' the initial option.

 

:beer:

Link to comment
Share on other sites

Just for fun....

 

 

No "All" (preference):

(defun c:LayTog (/ *error* lst option)

 (defun *error* (msg)
   (and *AcadDoc* (vla-endundomark *AcadDoc*))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (vla-startundomark
   (cond (*AcadDoc*)
         ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
   )
 )

 (initget "Freeze Lock On Plot")
 (if (setq option
            (cdr
              (assoc
                (getkword "\nSpecify toggle option: [Freeze/Lock/On/Plot]: ")
                (setq lst '(("Freeze" . freeze) ("Lock" . lock) ("On" . layeron) ("Plot" . plottable)))
              )
            )
     )
   (progn (vlax-for layer (vla-get-layers *AcadDoc*)
            (vl-catch-all-apply 'vlax-put (list layer option (~ (vlax-get layer option))))
          )
          (vla-regen *AcadDoc* acActiveViewport)
   )
 )

 (*error* nil)
 (princ)
)

 

With "All":

(defun c:LayTog2 (/ *error* lst option)

 (defun *error* (msg)
   (and *AcadDoc* (vla-endundomark *AcadDoc*))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (vla-startundomark
   (cond (*AcadDoc*)
         ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
   )
 )

 (initget "All Freeze Lock On Plot")
 (if (setq option
            (cdr
              (assoc
                (getkword "\nSpecify toggle option: [All/Freeze/Lock/On/Plot]: ")
                (setq lst '(("All" . "All")
                            ("Freeze" . freeze)
                            ("Lock" . lock)
                            ("On" . layeron)
                            ("Plot" . plottable)
                           )
                )
              )
            )
     )
   (progn (cond ((eq option "All")
                 (setq lst (mapcar 'cdr (cdr lst)))
                 (vlax-for layer (vla-get-layers *AcadDoc*)
                   (foreach opt lst
                     (vl-catch-all-apply 'vlax-put (list layer opt (~ (vlax-get layer opt))))
                   )
                 )
                )
                ((vlax-for layer (vla-get-layers *AcadDoc*)
                   (vl-catch-all-apply 'vlax-put (list layer option (~ (vlax-get layer option))))
                 )
                )
          )
          (vla-regen *AcadDoc* acActiveViewport)
   )
 )

 (*error* nil)
 (princ)
)

Link to comment
Share on other sites

  • 2 weeks later...

Thanks.

Have u tried layer walk?

I use LAYWALK for other things, but it does not toggle the frozen layers in this case.

 

Also RenderMan and alanjt, thanks so much for the input. Where I work we still only have LT so I cannot implement these. So sorry.

 

How do you put them together so fast? Have you got code generators that you use?

Link to comment
Share on other sites

  • 6 months later...

Okay I think I may have simplified the logic:

 

I want to automate (macro, script or DIESEL) the process of locking all frozen layers. It is beyond me to know how.

Link to comment
Share on other sites

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