Author Topic: Place prefix in front Layer name  (Read 10068 times)

0 Members and 1 Guest are viewing this topic.

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Place prefix in front Layer name
« Reply #15 on: November 08, 2016, 02:23:01 PM »
Hi guys,


That code is amazing, I've been using a lot ...

I'm using that code to add - as a prefix of my layers.

I'd like to make a little change at the code.
Remove - of all selected layers.


Thanks in advance


If I understood correctly and if the code passed your tests... (untested)

Code: [Select]
(defun c:foo ( / _ss->list f-MR e el l ll ss )
  (defun _ss->list ( ss / n out )
    (repeat (setq n (sslength ss)) (setq out (cons (ssname ss (setq n (1- n))) out)))
  )
  (defun f-MR ( d s / d1 dl k ss c pl z l )
    (while (and (setq d1 (substr d 1 1)) (/= d1 ""))
      (setq d (substr d 2))
      (setq dl (cons d1 dl))
    )
    (foreach d1 dl
      (setq k -1 ss s)
      (while (and (setq c (substr ss 1 1)) (/= c ""))
        (setq ss (substr ss 2))
        (setq k (1+ k))
        (if (= c d1)
          (setq pl (cons k pl))
        )
      )
    )
    (if pl
      (progn
        (setq pl (vl-sort pl '<))
        (foreach p pl
          (if (null z)
            (setq z 1)
          )
          (setq l (cons (substr s z (1+ (- p z))) l))
          (setq z (+ p 2))
        )
        (setq l (cons (substr s z) l))
        (vl-remove "" (reverse l))
      )
      s
    )
  )
  (if (setq ss (ssget))
    (foreach e (_ss->list ss)
      (setq l (cdr (assoc 8 (entget e))))
      (setq el (entget (tblobjname "layer" l)))
      (if (vl-string-search "-" l)
        (progn
          (setq ll (f-MR "-" l))
          (setq ll (apply 'strcat ll))
          (entmod (subst (cons 2 ll) (assoc 2 el) el))
        )
      )
    )
  )
  (princ)
)

Regards...

Thank you very much!!!

Worked perfect!!!

Regards

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: Place prefix in front Layer name
« Reply #16 on: November 08, 2016, 03:11:50 PM »
This request inspired me to create this new program: Layer Prefix/Suffix

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Place prefix in front Layer name
« Reply #17 on: November 09, 2016, 05:06:46 AM »
This request inspired me to create this new program: Layer Prefix/Suffix

Hi my old friend Lee Mac

Your web site is amazing!!

I'm happy with my request had inspired you create a new code.  :-D

Thank you very much!

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: Place prefix in front Layer name
« Reply #18 on: November 09, 2016, 07:59:08 AM »
Thank you for your compliments for my site - I'm pleased that you like the new program.  :-)

Lee

M. Khateeb

  • Mosquito
  • Posts: 3
Re: Place prefix in front Layer name
« Reply #19 on: December 07, 2016, 11:24:17 AM »
Hello,
Can this, please, be modified to have a dialogue box with a list of the suffixes for each layer I pick. and away to add or remove them.
I attached a dialogue box to explain what I mean. (was modified by photo editor to match the situation I am explaining)
For example.
I have a layer named C1650.
and the "codes" or suffixes to be added or removed, are always numbers with "_" before each number, but could be anything for general use.
In a certain situation, the layer is C1650_0
When I pick the layer, the "0" should appear in the list of suffixes in the dialogue box, I can remove it by pressing "Del" or add another code, like 1;
then the layer should be renamed to
C1650_0_1

I appreciate any help.
Lee's code for layer prefix/suffix is great, Thank you very much for your efforts.
But I need a friendly way to do this since I have a lot of such cases....
Thank you
M.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Place prefix in front Layer name
« Reply #20 on: December 07, 2016, 12:17:42 PM »
suffixes to be added or removed, are always numbers with "_" before each number, but could be anything for general use.
If "anything" applies and the layername is "C1650_0" the list of suffixes must be:
Code: [Select]
1650_0
650_0
50_0
0_0
_0
0
?

M. Khateeb

  • Mosquito
  • Posts: 3
Re: Place prefix in front Layer name
« Reply #21 on: December 08, 2016, 01:58:48 AM »
The layer name is constant, the list of suffixes is managed.
For instance:

C1650_0_1_2_3    (list of suffixes : 0 1 2 3 )

When you remove 3, the result is C1650_0_1_2  and the list now : 0 1 2

What I meant by "anything" is the suffix could be anything like : C1650_XX_YY_ZZ  and when you remove ZZ, you stay with C1650_XX_YY

Thanks for your concern.
       

danallen

  • Guest
Re: Place prefix in front Layer name
« Reply #22 on: December 08, 2016, 04:42:30 PM »
M. Khateeb,

Sounds like this should be a new discussion topic since it is not adding prefixes.

Are you looking for renaming only one layer at a time? My pseudo code of my pseudo understanding of your request is:
run program
a) get layer name, or perhaps run on current layer
b) parse layer name into list of strings using "_" as a separator (see https://www.theswamp.org/index.php?topic=32845.0)
c) use dialog with check boxes, see image below, from doslib using the dos_checklist function. https://wiki.mcneel.com/doslib/home
d) recombine string based on selection, and rename layer

Dan
« Last Edit: December 12, 2016, 09:41:39 PM by dan allen »

GDF

  • Water Moccasin
  • Posts: 2081
Re: Place prefix in front Layer name
« Reply #23 on: December 08, 2016, 05:04:48 PM »
Nicely done LeeMac and Ronjonp
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Place prefix in front Layer name
« Reply #24 on: December 08, 2016, 05:07:47 PM »
Nicely done LeeMac and Ronjonp
Thanks  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

M. Khateeb

  • Mosquito
  • Posts: 3
Re: Place prefix in front Layer name
« Reply #25 on: December 11, 2016, 07:18:55 AM »
Sorry for putting it in the wrong thread, but I was led here while I was looking for prefix and suffix adding and removing.
The other thread is very nice. With a string parser, it would be perfect, combining all the work done and getting what I want.
Thanks a lot.

Lee Mac

  • Seagull
  • Posts: 12910
  • London, England
Re: Place prefix in front Layer name
« Reply #26 on: December 11, 2016, 05:28:19 PM »
Nicely done LeeMac and Ronjonp

Thanks Gary.  :-)

danallen

  • Guest
Re: Place prefix in front Layer name
« Reply #27 on: December 12, 2016, 06:09:04 PM »
No problem, feel free to start a new thread and post your code draft if you need input/help.

-Dan

Sorry for putting it in the wrong thread, but I was led here while I was looking for prefix and suffix adding and removing.
The other thread is very nice. With a string parser, it would be perfect, combining all the work done and getting what I want.
Thanks a lot.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Place prefix in front Layer name
« Reply #28 on: December 12, 2016, 06:15:08 PM »
Hi Dan,
Just a quick question: where did you got that dialog from?
I mean I was about to ask in the DCL section is this thing possible: list_box with toggle buttons inside (just like the picture you uploaded).
Not sure if this is doable with pure DCL.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

danallen

  • Guest
Re: Place prefix in front Layer name
« Reply #29 on: December 12, 2016, 09:40:18 PM »
The dialog, specifically dos_checklist, is from doslib, https://wiki.mcneel.com/doslib/home, a free add-on that has been around for years, and hopefully many more. The pros here tend to create their own, I don't know if pure DCL can do it.