Author Topic: Challenge!  (Read 2232 times)

0 Members and 1 Guest are viewing this topic.

Dave M

  • Newt
  • Posts: 196
Challenge!
« on: April 04, 2014, 04:35:13 PM »
I would like to know if anyone has, or knows of a routine that will allow the user to select an object on a layer and move the object to a layer of the same name with a suffix?  Ideally, the routine could create the layer if it doesn't already exist.
For example, select an object on layer C-ROAD-CURB, and the object gets moved to layer C-ROAD-CURB-DEMO.  It would be nice if the new layer could take on all the attributes of the original layer.
It's a lot to ask I know, so anything that would get me close would be great!
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

ymg

  • Guest
Re: Challenge!
« Reply #1 on: April 04, 2014, 07:01:33 PM »
Dave,

Here a snippet:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:addsuffix ( )
  2.     (setq suf (getstring "\nEnter Suffix to Append: "))              
  3.     (while (setq en (car (entsel "\nSelect an entity: ")))
  4.        (setq ent  (entget en)
  5.              lay  (cdr (assoc 8 ent))
  6.              ent  (subst (cons 8 (strcat lay suf)) (assoc 8 ent) ent)
  7.        )
  8.        (entmod ent)
  9.     )
  10.     (princ)
  11. )
  12.  

If you need the new layer to have same color, ltype etc.
you will have to entmod the layer also.
ymg
« Last Edit: April 04, 2014, 07:14:19 PM by ymg »

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Challenge!
« Reply #2 on: April 05, 2014, 09:04:26 AM »
To match the layer properties, perhaps something like:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:laysuff ( / a d e i l n s x )
  2.    
  3.     (setq a "-DEMO") ;; Layer Suffix
  4.    
  5.     (if (setq s (ssget "_:L" (list (cons 8 (strcat "~*" a)))))
  6.         (repeat (setq i (sslength s))
  7.             (setq e (entget (ssname s (setq i (1- i))))
  8.                   x (assoc 8 e)
  9.                   n (strcat (cdr x) a)
  10.             )
  11.             (entmod (subst (cons 8 n) x e))
  12.             (if (not (member n l))
  13.                 (progn
  14.                     (setq l (cons n l)
  15.                           e (entget (tblobjname "layer" (cdr x)))
  16.                           d (entget (tblobjname "layer" n))
  17.                     )
  18.                     (foreach k '(-1 2 5)
  19.                         (setq e (subst (assoc k d) (assoc k e) e))
  20.                     )
  21.                     (entmod e)
  22.                 )
  23.             )
  24.         )
  25.     )
  26.     (princ)
  27. )

Dave M

  • Newt
  • Posts: 196
Re: Challenge!
« Reply #3 on: April 07, 2014, 11:53:51 AM »
Thanks for the help!  I am no programmer, but I will give these a try, and modify as necessary!
Cheers
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

ymg

  • Guest
Re: Challenge!
« Reply #4 on: April 07, 2014, 01:59:20 PM »
Dave,

Main difference between the two is:

Mine will ask you for a suffix then loop asking you to select
one entity at a time, add the suffix to the layer name then entmod
the selected entity.  This continues in a loop until you do not select
anything.

Lee's has a fixed suffix (This can be easily modified by adding (setq a (getstring "\nEnter Suffix to Append: "))
then asked you for a selection set of entity, (filtering out the entity on Locked Layers)
then proceed to modify the entity, and the new layer with all the attributes of the old one.

Now if you want to go one by one as your original post seems to suggest you could go
this way (Inserting Lee's code into the loop of First snippet):

Code - Auto/Visual Lisp: [Select]
  1. (defun c:addsuffix (/ a d e en l n x)
  2.     (setq a (getstring "\nEnter Suffix to Append: "))              
  3.     (while (setq en (car (entsel "\nSelect an entity: ")))
  4.        (setq e (entget en)
  5.              x  (assoc 8 e)
  6.              n (strcat (cdr x) a)
  7.        )
  8.        (entmod (subst (cons 8 n) x e))
  9.        
  10.        (if (not (member n l))
  11.           (progn
  12.               (setq l (cons n l)
  13.                     e (entget (tblobjname "layer" (cdr x)))
  14.                     d (entget (tblobjname "layer" n))
  15.               )
  16.               (foreach k '(-1 2 5)
  17.                   (setq e (subst (assoc k d) (assoc k e) e))
  18.               )
  19.               (entmod e)
  20.           )
  21.        )
  22.     )
  23.     (princ)
  24. )
  25.