PDA

View Full Version : Turn layers off by selecting an entity



timfrost
2004-11-09, 09:03 PM
I have the following code:


(defun c:O (/ ent lname)
(command ".undo" "begin")
(while (setq ent (nentsel "\nPick layers to turn off."))
(setq lname (cdr (assoc 8 (entget (car ent)))))
(command "._Layer" "_Off" lname "")
) ; while
(command ".undo" "end")
(princ)
) ;defun
princ)

It works fine except on blocks. How do I modify the code so that it also turns off the layer of the block when I select it?

CAB2k
2004-11-10, 03:12 AM
Change nentsel to entsel.

JASONM30395
2004-11-10, 12:06 PM
Why not use the layoff command under the Express tools?

jwanstaett
2004-11-10, 02:58 PM
way not use the -layer command in autocad


Command: -layer
Current layer: "0"
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
off
Enter name list of layer(s) to turn off or <select objects>: {use the enter key here}
Select objects: 1 found

I think the option to select object was add in Autocad 14.

timfrost
2004-11-10, 09:30 PM
If I use entsel instead of nentsel. The off command no longer works on xref. I am greedy I would like it to work on xref as well as blocks.

Tim

timfrost
2004-11-10, 09:32 PM
I have bad luck with express tools. They will not consistently work. Many, times I have to get out of AutoCAD and jump back in.

Besides, inquiring minds want to know. I just want to know how to make a command that works with all entities including xref and blocks.

Tim

P.S. Somebody must know.

timfrost
2004-11-10, 09:35 PM
That does not seem to work for me. Are you choosing xref, blocks and regular entitiies?

Tim

jwanstaett
2004-11-11, 05:40 PM
try this I added a function to check for nested blocks
I made it a sub so you can use in other places



(defun c:LOFF ()
(command ".undo" "begin")
(while (setq ent (nentsel "\nPick layers to turn off."))
(setq entx ent)
(setq testit (ISNESTENTITY ent))
(IF (= (NTH 3 TESTIT) 0)
(SETQ ENT2 (NTH 0 TESTIT));this is a block set ent2 to insterblock
(SETQ ENT2 (CAR ENT));this is a entity or xref set ent2 to the select entity
) ;_ end of IF
(SETQ lname (cdr (assoc 8 (entget ent2))))
(command "._Layer" "_Off" lname "")
) ;_ end of while
(command ".undo" "end")
) ;_ end of defun


;; function ISNESTENTITY(RETURNNENTSEL)
;; INPUT RETURNNENTSEL THE VAULE RETURN BY THE NENTSEL FUNCTION
;; OUT PUT A LIST OF 4 ITEMS
;; ITEM 0 IS A ENTITY NAME OR THE ENTITY NAME OF A INSERTED BLOCK OR XREF
;; ITEM 1 NIL OR THE VAULE RETURN BY TBLSEARCH FOR THE BLOCK NAME
;; This will have the path of the xref in it code 2
;; ITEM 2 NIL OR 1 IF NESTEDENTIYT
;; ITEM 3 NIL OR 0 FOR BLOCK 4 FOR XREF
;;
(DEFUN ISNESTENTITY (RETURNNENTSEL )
(if (= (length RETURNNENTSEL) 4) ;if this a entity in a block or xref
(progn
(setq block (CAR (nth 3 RETURNNENTSEL)))
;GET THE INTER MUST BLOCK

(SETQ BLOCKNAME (CDR (ASSOC 2 (ENTGET BLOCK))))
;GET THE NAME OF THE BLOCK
(SETQ BLOCKREF (tblsearch "BLOCK" BLOCKNAME)) ;GET THE BLOCK
(SETQ X (CDR (ASSOC 70 BLOCKREF))) ;GET THE BLOCK FLAGS
(SETQ X (BOOLE 1 X 4)) ;SET X TO 0 IF BLOCK 4 IF XREF
(setq return (list block blockref 1 x))
;return 'insert block' 'vaule return by tblsearch' 1 '0 or 4 if xref'
) ;_ end of progn
(progn
(setq return (List (car RETURNNENTSEL) nil nil nil))
;return list entity nil nil nil
) ;_ end of progn
) ;_ end of if
) ;_ end of DEFUN
(princ)

timfrost
2004-11-12, 03:43 PM
Well it does not seem to work for me. Maybe I am holding my mouth wrong. :)

I have block in the current drawing and blocks in xref it does not seem to like.

However, thanks for trying to help.

Tim