Tool -Layer name check for number of characters and structure of layer name

Tool -Layer name check for number of characters and structure of layer name

nilesh33
Advocate Advocate
1,020 Views
7 Replies
Message 1 of 8

Tool -Layer name check for number of characters and structure of layer name

nilesh33
Advocate
Advocate

Hi Friends,

I would like to develop utility/tool/cad standard checker which will do following.

1. It will check and report if layer name contains more than 11 digits/letters/characters
2. It will check and report if layer contains characters as per predefined list or not.
Example first two characters in layer name should be from this list (T-, V-, R-, K-, ...etc)

 

What would be an easiest and efficient way to develop this?

 

Thanks,
Nilesh

0 Likes
1,021 Views
7 Replies
Replies (7)
Message 2 of 8

Moshe-A
Mentor
Mentor

@nilesh33 hi,

 

the easiest way to to write a command to do these checking and run it from appload (or acad.lsp)

but in mid session it would be left unchecked (until next open).

 

a complemetry moudle to it, is using activex reactors to online check each change in layers

post some code if you already have?!

 

moshe

 

0 Likes
Message 3 of 8

DannyNL
Advisor
Advisor

Some quick 'n dirty example code.

Running (Test) will return all layer names which do not start with one of the prefixes in the list or with a length larger than 11.

 

(defun Test (/ T_LayerPrefixList T_LayerNameMaxLength T_LayerCollection T_LayerName T_Return)
   (setq T_LayerPrefixList '("K-" "R-" "T-" "V-"))
   (setq T_LayerNameMaxLength 11)
   (setq T_LayerCollection (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
   (vlax-for T_Layer T_LayerCollection
      (if
         (and
            (/= (setq T_LayerName (vla-get-Name T_Layer)) "0")
            (or
               (not (vl-some '(lambda (T_Item) (wcmatch T_LayerName (strcat T_Item "*"))) T_LayerPrefixList))
               (> (strlen T_LayerName) T_LayerNameMaxLength)
            )
         )
         (setq T_Return (cons T_LayerName T_Return))         
      )            
   )
   (vlax-release-object T_LayerCollection)
   T_Return
)
0 Likes
Message 4 of 8

ronjonp
Mentor
Mentor

@DannyNL

FWIW..

;;This
(not (vl-some '(lambda (t_item) (wcmatch t_layername (strcat t_item "*"))) t_layerprefixlist))
;; Could be shortened to this
(not (wcmatch t_layername "K-*,R-*,T-*,V-*"))
Message 5 of 8

Moshe-A
Mentor
Mentor

yes @DannyNL,

 

it's true and works but it is also could be accomplish more simple way - NO?

 

(defun Test (/ T_LayerPrefixList T_LayerNameMaxLength T_LayerCollection T_LayerName T_Return)
   (SETQ T_Layer "[KRTV]-*")
   (setq T_LayerNameMaxLength 11)
   (setq T_LayerCollection (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
   (vlax-for T_Layer T_LayerCollection
      (if
         (and
            (/= (setq T_LayerName (vla-get-Name T_Layer)) "0")
            (or
               (not (wcmatch T_LayerName T_LayerPrefixList))
               (> (strlen T_LayerName) T_LayerNameMaxLength)
            )
         )
         (setq T_Return (cons T_LayerName T_Return))         
      )            
   )
   (vlax-release-object T_LayerCollection)
   T_Return
)
Message 6 of 8

Kent1Cooper
Consultant
Consultant

Investigate the STANDARDS command.

Kent Cooper, AIA
0 Likes
Message 7 of 8

ronjonp
Mentor
Mentor

Even simpler than mine 🙂

(SETQ T_Layer "[KRTV]-*")
0 Likes
Message 8 of 8

DannyNL
Advisor
Advisor

And @Moshe-A.

 

Both correct......I sometimes forget that wcmatch supports bracketing Smiley Happy

0 Likes