Compare and Merge Layers

Compare and Merge Layers

Anonymous
Not applicable
759 Views
3 Replies
Message 1 of 4

Compare and Merge Layers

Anonymous
Not applicable

Hi all,

 

i am new to AutoCAD AutoLISP.  I have a problem that I cannot solve on my own.

 

Is there any way to Automate following process using a Macro / AutoLISP file?

 

There are multiple layers with standardized names.

 

E.g.:

 

Arch1_TXT_NEW

Arch1_TXT_STOCK

Bul1_CMS_NEW

Bul1_CMS_STOCK

 

Is there any way i can wirte a script that compares the layer names, then if it finds a matching pair where the difference is only the text "NEW" and "STOCK" and applies to all elements in the layer "NEW" the layer "STOCK", iterating through all layers and then cleaning the empty "NEW" layers with a purge command?

 

I would be really thankful if somebody could guide me how to do this. Also, if if my text is incomprehensible, please draw my attention to it, i am not a native english speaker.

 

Kind regards,

Robert

0 Likes
Accepted solutions (1)
760 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution

Robert, welcome to the Forums,

try this LISP to see if it works for you.

BTW it's never too late to learn at least some basics of programming. Plenty of people came here to help with learning.

 

 

(defun c:MergeNewToStock ( / d o n)

  (while (setq d (tblnext "LAYER" (null d)))
    (setq o (cdr (assoc 2 d)))
    (if (and (wcmatch o "*_NEW")
	     (setq n (strcat (substr o 1 (- (strlen o) 3)) "STOCK"))
	     (tblsearch "LAYER" n)
	     )
      (command "_.LAYMRG" "_Name" o "" "_N" n "_Y")))
  (princ)
  )

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

Its works very well and the script looks insanely elegegant and short, coud you recommend me ressources to learn such things? I am really willing to learn and if i get better even to help out in the community!

 

Thanks alot for your help!

0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

Glad to hear that.

Two links for you, ONE  and the SECOND 

 

Btw, it's called a LISP. Word "script" has its specific meaning in AutoCAD and it's *.scr file with a sequence of autocad's commands directly working with the command-line.