Jump to content

keystroke to hide show specific layer?


Recommended Posts

Posted

hi

runing autocad 2010,

i want to create a keystroke to hide /show a specific layer, how can i do it?

Thanks

Shay

Posted

There are a bunch of good tools for such tasks on the LAYERS2 toolbar.

LAYISO and LAYWALK specifically would be good choices.

Posted (edited)

i want to create a keystroke to hide /show a specific layer, how can i do it?

 

Quick example:

 

(defun c:FOO (/ layerName layerData)
 
 (if
   (and
     
[color=seagreen]      ;; If the current layer is not the same as the pre-defined
     ;; layer to be toggled[/color]
     (/= (getvar 'clayer) (setq layerName "LayerName"))

[color=seagreen]      ;; And, the pre-defined layer exists[/color]
     (setq layerData (tblsearch "layer" layerName))
   )

[color=seagreen]    ;; Then, use the -LAYER Command to toggle the display[/color]
   (command "._-layer"

[color=seagreen]             ;; Based upon the layer's current display setting,
            ;; Where DXF 70 represents the Freeze/Thaw status.
            ;; If, thawed, freeze... If frozen, thaw[/color]
            (if (= 0 (cdr (assoc 70 layerData)))
              "freeze"
              "thaw"
            )
            layerName
            ""
   )

   [color=seagreen];; Else, do nothing, as the pre-defined layer is either
   ;; the same as the current layer, or the layer does not exist[/color]
 )

 [color=seagreen];; Silent exit[/color]
 (princ)
)

Edited by BlackBox
Posted

dadgad:

there is specific layer i want to hide/show , using layerwalk ans isolation assume i dont know the layer identity

 

renderman

please be more step by step'ed as im not fimiliar with autocad coding..

Thanks

Posted

renderman

please be more step by step'ed as im not fimiliar with autocad coding..

 

Certainly, perhaps the comments added to the code example here will better explain what the code is doing.

 

dadgad:

there is specific layer i want to hide/show , using layerwalk ans isolation assume i dont know the layer identity

 

... I know that this was addressed to Dadgad, but this comment changes the approach I would have used in the sample above. Instead, simply consider adding an item to your ACAD.PGP file, which would create a keyboard shortcut for activating the LAYFRZ, and LAYERP Commands.

 

HTH

Posted
I want to create a keystroke to hide /show a specific layer, how can i do it?

 

Perhaps use something like:

 

(defun c:[color=green][highlight]aa[/highlight][/color] ( ) (freezethawlayer "[color=red][highlight]MyLayer[/highlight][/color]"))

(defun freezethawlayer ( name / dx en )
   (if (= (strcase (getvar 'clayer)) (strcase name))
       (princ "\nCannot freeze the current layer.")
       (if (setq en (tblobjname "LAYER" name))
           (setq en (entget en)
                 dx (assoc 70 en)
                 en (entmod (subst (cons 70 (boole 6 1 (cdr dx))) dx en))
           )
           (princ (strcat "\nLayer " name " doesn't exist."))
       )
   )
   (princ)
)

Alter the name of the layer in [highlight]red[/highlight] and the command name ('aa') in [highlight]green[/highlight] to suit your requirements.

 

If you need different commands to freeze/thaw different layers, just add another line similar to the first line, e.g.:

 

(defun c:[color=green][highlight]bb[/highlight][/color] ( ) (freezethawlayer "[color=red][highlight]AnotherLayer[/highlight][/color]"))

Here, the command would be '[highlight]bb[/highlight]' and the layer name is '[highlight]AnotherLayer[/highlight]'

 

Here are instructions on how to load & run the code:

 

http://www.cadtutor.net/forum/showthread.php?1390-How-to-use-the-LISP-routines-in-this-archive

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