Layer visibility for particular layers starts with "Elect"

Layer visibility for particular layers starts with "Elect"

Anonymous
Not applicable
2,127 Views
18 Replies
Message 1 of 19

Layer visibility for particular layers starts with "Elect"

Anonymous
Not applicable

Dear Helpers,

Could you please help on below code to update to work on only layers starts with "Elect". The below code works on all layers in autocad to turn on each layer separately. But it should create a selection set for Layer names which start with "Elect" Only. 

(defun c:NL()
	(if (= lay nil) (setq num 0))
	(setq entlay (tblnext "layer" num))
	(setq lay (cdr (assoc 2 entlay)))
	(command "layer" "s" lay "off" "*" "" "")
	(setq num nil))
0 Likes
Accepted solutions (1)
2,128 Views
18 Replies
Replies (18)
Message 2 of 19

cadffm
Consultant
Consultant

What you tried, all elec* layers turn off?

 

;; all "ELEC*" Layer off
(defun c:NL()
  (command "_.layer" "_off" "ELEC*" "" "")
 (princ)
)

Check [F1] help
-LAYER (command)
- Wildcards

Sebastian

Message 3 of 19

dbhunia
Advisor
Advisor

Hi

 

Try this....

 

(defun C:NL (/)
  (vl-load-com)
  (command "cmdecho" 0)
  (setq layerslist nil)
  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (wcmatch (setq layername (vla-get-name layer)) "Elect*")
      (setq layerslist (cons layername layerslist))
    )
  )
  (setq layerslist (acad_strlsort layerslist))
  (command "_-layer" "_s" (nth 0 layerslist) "off" "*" "" "")
  (repeat (- (setq N (length layerslist)) 1)
	(command "_-layer" "on" (nth (setq N (- N 1)) layerslist) "")
  )
(command "cmdecho" 1)
(princ)
)

 

If you want  all "Elect*" layers turn on.....


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 4 of 19

Anonymous
Not applicable

Thank you for attending my problem, Sir.

This lisp turning off all layers, excpet name starts with "Elect".

But my requirement should toggle the visibility of all "Elect" named layers.

For suppose I have layers like below

Elect 1
Elect 2
Elect 3
Elect 4
Elect 5
Elect 6
Elect 7
Elect 8

Then The lisp should turnoff all cad layers. Then it should turn on First only "Elect1" layer, then after pressing enter again it should turn on only "Elect2", then  after pressing enter button "Elect3" ...........Like

I think you got my point sir.

0 Likes
Message 5 of 19

Anonymous
Not applicable

Thank you Sir,

Reached to some level.

But this lisp should go through only "Elect" named layers only. It's toggling only Elect named layers as per my requirements. Suppose I have 1000 layers and only 20 layers with Elect named. Then I should not press enter 1000 times to get the visibility of elect named layers. Suppose I have layers like below

Elect 1
Elect 2
Elect 3
Elect 4
Elect 5
Elect 6
Elect 7
Elect 8

The lisp command should stars with Elect 1 and finish with Elect 8 layer with 8 times of enter button pressing. Then the lisp should starts at Elect 1 only.

In your case the lisp rotating through all layers, Sir.

0 Likes
Message 6 of 19

dbhunia
Advisor
Advisor

Try this.....

 

(defun C:NL (/)
  (vl-load-com)
  (command "cmdecho" 0)
  (setq layerslist nil)
  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (wcmatch (setq layername (vla-get-name layer)) "Elect*")
      (setq layerslist (cons layername layerslist))
    )
  )
  (setq layerslist (acad_strlsort layerslist))
  (command "_-layer" "_s" 0 "off" "*" "" "")
  (setq L -1)
  (repeat (setq N (length layerslist))
    (initget 1 "Y N")
    (setq OPT (getkword (strcat "\nWant to Turn on Layer <" (nth (setq L (+ L 1)) layerslist) "> (Y/N): ")))
	(cond ((= OPT "Y")
		(command "_-layer" "on" (nth L layerslist) "")
	      )
	)
  )
(command "cmdecho" 1)
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 7 of 19

Shneuph
Collaborator
Collaborator

Do you need to do this with LISP?  Seems like LAYWALK command may suite your needs?

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 8 of 19

Anonymous
Not applicable

Thank you Very much,

I know this command, but for 1000 no.of layers, it's very difficult to check in that command.

0 Likes
Message 9 of 19

Anonymous
Not applicable

Thank you very much for your efforts.

The code is working like, it showing one by one Elect named layers.

Nearly reached my requirement. But my exact requirement is, at a time one Elect named layer only displayed and remaining layers should be turned off.

 

0 Likes
Message 10 of 19

dbhunia
Advisor
Advisor

Hi

 

Try This.....

 

(defun C:NL (/)
  (vl-load-com)
  (command "cmdecho" 0)
  (setq layerslist nil)
  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (wcmatch (setq layername (vla-get-name layer)) "Elect*")
      (setq layerslist (cons layername layerslist))
    )
  )
  (setq layerslist (acad_strlsort layerslist))
  (command "_-layer" "_s" 0 "off" "*" "" "")
  (setq L -1)
  (repeat (setq N (length layerslist))
    (initget 1 "Y N")
    (setq OPT (getkword (strcat "\nWant to Turn on Layer <" (nth (setq L (+ L 1)) layerslist) "> (Y/N): ")))
	(cond ((= OPT "Y")
		(command "_-layer" "_s" (nth L layerslist) "off" "*" "" "")
	      )
	)
  )
(command "cmdecho" 1)
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 11 of 19

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

Thank you Very much,

I know this command, but for 1000 no.of layers, it's very difficult to check in that command.


 

You know that the LAYWALK has a filter option on the top of the list?

Just type Elect*<enter> and you'll see only those.

 

BTW what are you going to do with those isolated layers next?

Message 12 of 19

Anonymous
Not applicable

Command: NL
cmdecho
Enter new value for CMDECHO <1>: 0
Usage: (acad_strlsort <list of strings>)

 

I am getting above error in autocad while giving command after lisp loading. Can you please help me?.

0 Likes
Message 13 of 19

Anonymous
Not applicable

I have lot of 11kV Voltage networks areas wise in one state of India. So I have to do quality check. So it is most usable to check area wise. The same area should not be repeated at 2 diifferent locations. Thank you Very much Sir.

0 Likes
Message 14 of 19

Anonymous
Not applicable

And also Zoom command will not work while LAYWALK is working.

0 Likes
Message 15 of 19

dbhunia
Advisor
Advisor

Hi

 

Can not say why you are getting this error message?....................

 

I am not getting any such error message?....................

 

Capture.PNG

 

Try in other system or give a sample drawing.............. 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 16 of 19

Anonymous
Not applicable

In new drawing it's working fentastic.

But every time it's asking for "Y" Option to go to next layer as below

"Want to Turn on Layer <Elect 7> (Y/N): Y"

Could you please make it without entering any keyword for each time. and also the in place of "Elect", can I feed any user input?.

 

Thank you very much for your hard efforts.

 

0 Likes
Message 17 of 19

dbhunia
Advisor
Advisor
Accepted solution

Try this.....

 

(defun C:NL (/)
  (vl-load-com)
  (command "cmdecho" 0)
  (setq layerslist nil)
  (setq LAN (getstring "\nEnter Layer Name (Few Matching Word from Prefix it's Case sensitive): "))
  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if (wcmatch (setq layername (vla-get-name layer)) (strcat LAN "*"))
      (setq layerslist (cons layername layerslist))
    )
  )
  (setq layerslist (acad_strlsort layerslist))
  (command "_-layer" "_s" 0 "off" "*" "" "")
  (setq L -1)
  (repeat (setq N (length layerslist))
    (initget "Y N")
    (setq OPT (getkword (strcat "\nWant to Turn on Layer <" (nth (setq L (+ L 1)) layerslist) "> [Y/N]<Y>: ")))
	(if (or (= OPT "Y") (= OPT nil))
		(command "_-layer" "_s" (nth L layerslist) "off" "*" "" "")
	)
  )
(command "cmdecho" 1)
(princ)
)

If you hit enter it will consider that as "Yes" otherwise press "N" and hit enter........


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 18 of 19

Anonymous
Not applicable

Perfectly Suited to my requirement. Thank you So much.

0 Likes
Message 19 of 19

ВeekeeCZ
Consultant
Consultant

Well, as I see it, the only advantage that this routine offers over the regular LayWalk command is the ability to ZOOM.

IMHO that's unnecessarily limited. I'll want to do more than that - the ability to do something with objects... select them, check the types, check the length, move them to a different layer, remove them for good... or whatever.

So my solution would be different. My routine does not stay active during the whole process. You will need to recall the routine to move to the next layer. But that is quite easy because the command is the last one, so just hit <enter>. When you need to run another command during the process - you're good to go... after you're done, recall the routine and you'll move to the next layer.

Well, to be honest, I wrote it according to my own idea of preferable workflow, for my own usage. But if you find that this makes sense to you as well, your welcome to use it. Feel free to rename it.

 

(vl-load-com)

; Funtions of LayerWalkOnebyOne
; LWOneByOne or NL - main funtion. Set the mask if any, command will show the first layer.
;                                  For next layer run the command again.
;                                  The run next to the last layer will reset layer state.
; LW_RestoreLayerState - restore layer state from "$NL-TMP" which will be erase. But you can still continue in LWOneBeOne
; LW_NewWalkRestoreLayerState - restore layer state from "$NL-TMP" which will be erase. You will start over.

; BeekeeCZ 2018-11

;-----
(defun c:LW_RestoreLayerState ()
  (and (layerstate-restore "$NL-TMP" nil)
       (layerstate-delete "$NL-TMP"))
  (princ))

;-----
(defun c:LW_NewWalk ()
  (and (layerstate-restore "$NL-TMP" nil)
       (layerstate-delete "$NL-TMP"))
  (setq *lw1-lst* nil)
  (princ "\nType to run 'LWOnebyOne'")
  (princ))

;-----
(defun c:NL nil (c:LWOnebyOne))
(defun c:LWOnebyOne (/ *error* cmd :GetLayers doc flt)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if cmd (setvar 'cmdecho cmd))
    (princ))
  
  (defun :GetLayers (doc flt / layname lst)
    (vlax-for layer (vla-get-layers doc)
      (if (and (not (wcmatch (setq layname (vla-get-name layer)) "*|*"))
	       (wcmatch (strcase layname) (strcase (strcat "*" flt "*")))
	       )
	(setq lst (cons layname lst))))
    (vl-sort lst '<))
  
  
  (setq cmd (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  
  (if (cond (*lw1-lst*)
	    
	    ((layerstate-restore "$NL-TMP" nil)
	     (layerstate-delete "$NL-TMP")
	     *lw1-lst*)
	    
	    ((setq flt (getstring T "\nFilter layer by mask <all>: ")
		   doc (vla-get-activedocument (vlax-get-acad-object))
		   *lw1-lst* (:GetLayers doc flt))
	     (vl-cmdf "_.-LAYER" "_stAte" "_Save" "$NL-TMP" "" "" "")
	     (not (graphscr))))
    (progn
      (command "_.-LAYER" "_Thaw" (car *lw1-lst*) "_Set" (car *lw1-lst*) "_Freeze" "*" "")
      (princ (strcat "\rCurrent layer: " (car *lw1-lst*) "   >> next " (itoa (length (setq *lw1-lst* (cdr *lw1-lst*)))) " layers "))))
  
  (*error* "end")
  )
0 Likes