Jump to content

Selecting multiple destination layers in Copytolayer command.


Recommended Posts

Posted

Dear experts,

 

The Copy objects to New layer command in AutoCAD 2011 only lets you select one destination layer. Is there a way or a lisp to select multiple destination layers at once?

 

Your help would be greatly appreciated.

 

Thank you! :)

Posted

How would the program know which objects to copy to which layers?

Posted

@Lee - that should be able to be done. You are not just moving the objects there, but copying them to multiple layers. Kind of like copying a selection set, but right after that you would change the layer of those new objects.

Posted

Oh I see, so you mean multiple copies, a set of objects to each layer?

Posted (edited)

I'm not sure why someone would want to do this, but perhaps the OP want to select a group of objects, and copy them (all) to multiple layers.

 

(defun c:C2ML () (c:CopyToMLayers))
(defun c:CopyToMLayers  (/ *error* dosFlag ss oldCmdecho layerList copyToLayers)
 (princ "\rCOPY TO MULTIPLE LAYERS ")
 (vl-load-com)

 (defun *error*  (msg)
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** "))))                 ; Fatal error, display it
   (and oldCmdecho (setvar 'cmdecho oldCmdecho))
   (princ))

 (if (and (setq dosFlag (dos_version))
          (setq ss (ssget ":L")))
   (progn
     (and (setq oldCmdecho (getvar 'cmdecho)) (setvar 'cmdecho 0))
     (vlax-for x  (vla-get-layers
                    (vla-get-activedocument
                      (vlax-get-acad-object)))
       (setq layerList (cons (vla-get-name x) layerList)))
     (setq copyToLayers
            (dos_checklist
              "Select layers"
              "Layers to copy selection"
              (mapcar
                '(lambda (layer)
                   (cons layer 0))
                (vl-sort layerList '<))))
     (foreach item  copyToLayers
       (if (= 1 (cdr item))
         (command "_copytolayer" ss "" (car item) 0 0)))
     (setvar 'cmdecho oldCmdecho))
   (cond (dosFlag (prompt "\n** Nothing selected ** "))
         ((prompt "\n** DOSLib is not loaded ** "))))
 (princ))

 

Note - This code presumes DOSLib 8.6 is loaded.

Edited by BlackBox
Added DOSLib check
Posted

Quickly written code... ListBox sub was already written.

 

(defun c:CopytoLayerm ( / d l s )

 (while (setq d (tblnext "LAYER" (null d)))
   (setq l (cons (cdr (assoc 2 d)) l))
 )

 (if
   (and
     (princ "\nSelect Objects to Copy: ")
     (ssget "_:L")
     (setq l (LM:ListBox "Select Layer(s) to Copy to" (acad_strlsort l) t))
   )
   (progn
     (vlax-for o
       (setq s
         (vla-get-activeselectionset
           (vla-get-activedocument (vlax-get-acad-object))
         )
       )
       (foreach x l (vla-put-layer (vla-copy o) x))
     )
     (vla-delete s)
   )
 )
 (princ)
)

;;-----------------------=={ List Box }==---------------------;;
;;                                                            ;;
;;  Displays a List Box allowing the user to make a selection ;;
;;  from the supplied data.                                   ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  title    - List Box Dialog title                          ;;
;;  data     - List of Strings to display in the List Box     ;;
;;  multiple - Boolean flag to determine whether the user     ;;
;;             may select multiple items (T=Allow Multiple)   ;;
;;------------------------------------------------------------;;
;;  Returns:  List of selected items, else nil.               ;;
;;------------------------------------------------------------;;

(defun LM:ListBox ( title data multiple / file tmp dch return )  
 (cond
   (
     (not
       (and (setq file (open (setq tmp (vl-filename-mktemp nil nil ".dcl")) "w"))
         (write-line
           (strcat "listbox : dialog { label = \"" title
             "\"; spacer; : list_box { key = \"list\"; multiple_select = "
             (if multiple "true" "false") "; } spacer; ok_cancel;}"
           )
           file
         )
         (not (close file)) (< 0 (setq dch (load_dialog tmp))) (new_dialog "listbox" dch)
       )
     )
   )
   (
     t     
     (start_list "list")
     (mapcar 'add_list data) (end_list)

     (setq return (set_tile "list" "0"))
     (action_tile "list" "(setq return $value)")

     (setq return
       (if (= 1 (start_dialog))
         (mapcar '(lambda ( x ) (nth x data)) (read (strcat "(" return ")")))
       )
     )          
   )
 )
 (if (< 0 dch) (unload_dialog dch))
 (if (setq tmp (findfile tmp)) (vl-file-delete tmp))
 return
)

(vl-load-com) (princ)

Posted

So quick, but not include items in block, dimension ^^.

Btw,Thank you Lee. I like yours post

(How can i tick thanks for one post ? )

P/S :

In VietNam, alot of man "thần tượng" you, Lee

Posted

Awesome!

Thank you all for your quick reply.

RenderMan's code didn't quite work, I guess DOSLib 8.6 is not loaded in my computer but thanks a lot for replying.

Lee Mac's code worked perfect! thank you!

 

I would had sent a thank you card and a cake to all but I am broke.

 

You guys are truly amazing!!

Posted

You're welcome Mierkina :)

 

Make mine a chocolate cake please :P

Posted
Awesome!

Thank you all for your quick reply.

RenderMan's code didn't quite work, I guess DOSLib 8.6 is not loaded in my computer but thanks a lot for replying.

Lee Mac's code worked perfect! thank you!

 

I would had sent a thank you card and a cake to all but I am broke.

 

You guys are truly amazing!!

 

You're welcome; that is very kind of you to say. :)

 

You are correct - the code I posted will not work without DOSLib being loaded. I've since added a check for this, so others aren't tripped up.

 

Cheers! :beer:

  • 2 years later...
Posted

Lee Mac,

 

Thank you for posting this program! Whenever I search for a way to do something in Autocad that isn't built in, I'm always finding your programs that do exactly what I'm looking for.

 

I'm curious though if it would be possible to allow selecting multiple layers that are not adjacent to each other in the list of layers.

 

The built in copytolayer allows you to type in the layername or select from a list. Perhaps being able to type in layers separated by commas or semicolin.

 

Ex. I'm trying to copy some framing from layer 1_A to 2_A, 3_A, 4_A and so on but these items are not next to each other in the list of layers so using shift to select multiple layers will not work.

Posted

You should be able to hold Ctrl to pick multiple layers from the dialog :thumbsup:

Posted

Wonderful! Thanks for the super quick reply and thanks for being an awesome person! You're work really makes me look much more efficient then my coworkers :D (They wont use lisp routines!)

Posted
Wonderful! Thanks for the super quick reply and thanks for being an awesome person!

 

Thanks! :D

 

You're work really makes me look much more efficient then my coworkers :D (They wont use lisp routines!)

 

Haha! - the fools! :lol:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...