Help needed - Duplicate existing layouts, rename them to xxx-Suffix from a predefined list, and VPFreeze layers other than the layer containing corresponding suffix.

Help needed - Duplicate existing layouts, rename them to xxx-Suffix from a predefined list, and VPFreeze layers other than the layer containing corresponding suffix.

PkostrzewaM3SXC
Participant Participant
1,632 Views
20 Replies
Message 1 of 21

Help needed - Duplicate existing layouts, rename them to xxx-Suffix from a predefined list, and VPFreeze layers other than the layer containing corresponding suffix.

PkostrzewaM3SXC
Participant
Participant

Hello everyone,

I'm trying my best to use my limited knowledge about lisp routines and create a lisp routine that would make my life a lot easier but I'm failing miserably.
I attempted combining some of the lisp routines that I found on this forum with no success and at this point I feel like I don't know what to try anymore.

The routine I need would do the following:

 

For every existing layout in the drawing it would generate multiple identical layouts with specified suffixes.
I assume it would be some sort of a list at the beginning of the routine.
Then in these layouts a viewport freeze action would be performed on all the layers other than the layer containing the suffix.

Could you guys guide me a bit or help me out please?
Thank you!

0 Likes
Accepted solutions (2)
1,633 Views
20 Replies
Replies (20)
Message 2 of 21

hmsilva
Mentor
Mentor

@PkostrzewaM3SXC 


This is quick and dirty, and minimally tested, but it may get you started:

 

(defun c:demo (/ i lay layt_lst lay_lst lay_n n new_layt suf_lst)
  (setq suf_lst '("123-" "456-"));; <<< suffixes from a predefined list
  (setq layt_lst (layoutlist))
  (setq lay (tblnext "LAYER" T))
  (while lay
    (setq lay_n (cdr (assoc 2 lay)))
    (foreach suf suf_lst
      (if (wcmatch lay_n (strcat suf "*"))
	(setq lay_lst (cons (cons suf lay_n) lay_lst))
      )
    )
    (setq lay (tblnext "LAYER"))
  )
  (setq lay_lst (reverse lay_lst))
  (setq n (length lay_lst))
  (foreach layt	layt_lst
    (setq i 0)
    (while (< i n)
      (setq new_layt (strcat (car (nth i lay_lst)) layt))
      (command "-layout" "_C" layt new_layt)
      (setvar 'CTAB new_layt)
      (command "_.mspace")
      (command "_.vplayer" "_t" "*" "" "")
      (setvar 'CLAYER (cdr (nth i lay_lst)))
      (command "_.vplayer" "_f" "*" "" "_t" (cdr (nth i lay_lst)) "" "")
      (command "_.pspace")
      (setvar 'CTAB "Model")
      (setq i (1+ i))
    )
  )
  (princ)
)

 

Hope this helps,
Henrique

 

EESignature

Message 3 of 21

Sea-Haven
Mentor
Mentor

Nice solution maybe rather than coding list read a csv file, pretty easy to make using excel etc.

0 Likes
Message 4 of 21

PkostrzewaM3SXC
Participant
Participant

Thank you @hmsilva .
I tried loading it as a lisp and nothing happens when I execute the command.
I will try to play around and see what's going on - at the moment it does not indicate what might be wrong - the command line stays empty after executing.
Any ideas why?
Thank you again for a prompt response !

Kind regards,
Patrick

0 Likes
Message 5 of 21

hmsilva
Mentor
Mentor

@Sea-Haven wrote:

Nice solution maybe rather than coding list read a csv file, pretty easy to make using excel etc.


Agree!
The OP as stated "I'm trying my best to use my limited knowledge about lisp routines and create a lisp routine"
and I just wrote it in the simplest way I could, to be more understandable to the OP.

It could have been written to read a file, without command calls and to reorder the tabs at the end, but it wouldn't be so easy to understand...

 

Henrique

EESignature

0 Likes
Message 6 of 21

hmsilva
Mentor
Mentor

@PkostrzewaM3SXC wrote:

Thank you @hmsilva .
I tried loading it as a lisp and nothing happens when I execute the command.
I will try to play around and see what's going on - at the moment it does not indicate what might be wrong - the command line stays empty after executing.
Any ideas why?
Thank you again for a prompt response !

Kind regards,
Patrick


@PkostrzewaM3SXC 

in this line

(setq suf_lst '("123-" "456-"));; <<< suffixes from a predefined list

you will have to change '("123-" "456-") to the correct sufixes

If you can't, share with us the sufixes list, so we can change the code

 

Hope this helps,
Henrique

 

EESignature

0 Likes
Message 7 of 21

PkostrzewaM3SXC
Participant
Participant

That was the first thing I did - nothing happened.
Then I started doubting myself and I used the ones you used to see if it will throw an error - still nothing

0 Likes
Message 8 of 21

hmsilva
Mentor
Mentor

@PkostrzewaM3SXC wrote:

That was the first thing I did - nothing happened.
Then I started doubting myself and I used the ones you used to see if it will throw an error - still nothing


Share with us a dwg 

 

Henrique

EESignature

0 Likes
Message 9 of 21

PkostrzewaM3SXC
Participant
Participant

I attach the drawing I tested it in.
The suffixes im trying to use are Gas, Water etc. Basically all of the layers that end with *Rte - GasRte , WaterRte etc.

0 Likes
Message 10 of 21

hmsilva
Mentor
Mentor

If layer is "Pr_70_75_72-TrafficManageRte"  and layout "46599-01A" what would be the new layout name?

 

Henrique

EESignature

0 Likes
Message 11 of 21

PkostrzewaM3SXC
Participant
Participant

46599-01A-Traffic

0 Likes
Message 12 of 21

hmsilva
Mentor
Mentor

@PkostrzewaM3SXC wrote:

46599-01A-Traffic


This is not easy for me, because I would have to know all the keywords to compare with the layer names...
One option is to remove everything to the last "-" and "Rte" from the layer name, would be left "TrafficManage".

I'll have to leave the office, but when I come back I'll change the demo to work in that way

It would be ok for you?

 

And by the way, it's not a prefix, it's a suffix

 

Henrique

 

EESignature

0 Likes
Message 13 of 21

hmsilva
Mentor
Mentor
Accepted solution

Revised...

(defun c:demo (/ i lay layt_lst lay_lst lay_n n new_layt)
  (setq layt_lst (layoutlist))
  (setq lay (tblnext "LAYER" T))
  (while lay
    (setq lay_n (cdr (assoc 2 lay)))
      (if (wcmatch lay_n "*Rte")
	(setq lay_lst (cons lay_n lay_lst))
    )
    (setq lay (tblnext "LAYER"))
  )
  (setq lay_lst (reverse lay_lst))
  (setq n (length lay_lst))
  (foreach layt	layt_lst
    (setq i 0)
    (while (< i n)
      (setq lay_n (nth i lay_lst))
      (setq lay_n (vl-string-right-trim "Rte" lay_n))
      (setq new_layt (strcat layt "-" (substr lay_n (+ 2 (vl-string-position (ascii "-") lay_n nil T)))))
      (command "-layout" "_C" layt new_layt)
      (setvar 'CTAB new_layt)
      (command "_.mspace")
      (command "_.vplayer" "_t" "*" "" "")
      (setvar 'CLAYER (nth i lay_lst))
      (command "_.vplayer" "_f" "*" "" "_t" (nth i lay_lst) "" "")
      (command "_.pspace")
      (setvar 'CTAB "Model")
      (setq i (1+ i))
    )
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 14 of 21

PkostrzewaM3SXC
Participant
Participant

I really appreciate your help @hmsilva 
Preferably I would want the layers to stay the way they are, but if there is no way around it at this point then I'll take it 🙂 

0 Likes
Message 15 of 21

PkostrzewaM3SXC
Participant
Participant

Wow that's amazing!
There is no way I could've done it myself.
Where are you based @hmsilva ? Can I get you something as a thank you?

0 Likes
Message 16 of 21

hmsilva
Mentor
Mentor

@PkostrzewaM3SXC wrote:

Wow that's amazing!
There is no way I could've done it myself.
Where are you based @hmsilva ? Can I get you something as a thank you?


Thank you, it is enough...

I'm in Portugal.


Glad I could help
Henrique

EESignature

0 Likes
Message 17 of 21

PkostrzewaM3SXC
Participant
Participant

Thank you @hmsilva 
You are a star 🙂

0 Likes
Message 18 of 21

hmsilva
Mentor
Mentor

@PkostrzewaM3SXC wrote:

Thank you @hmsilva 
You are a star 🙂


You're welcome, @PkostrzewaM3SXC 

Henrique

EESignature

0 Likes
Message 19 of 21

PkostrzewaM3SXC
Participant
Participant

Sorry to bother you again @hmsilva 
The routine seems to be cutting letters R E and T from the words before the "Rte" itself but not in all cases - Water for example stays as it should.
I can see that the routine is set to trim the string for "Rte" but nothing other than this 
(setq lay_n (vl-string-right-trim "Rte" lay_n))

PkostrzewaM3SXC_0-1625220083955.png

Any ideas as to why it is doing it?
Thanks



0 Likes
Message 20 of 21

hmsilva
Mentor
Mentor
Accepted solution

Change

(setq lay_n (vl-string-right-trim "Rte" lay_n))

to

(setq lay_n (substr lay_n 1 (- (strlen lay_n) 3)))

 

Hope this helps,
Henrique

 

EESignature

0 Likes