Author Topic: 'Insert' - Copy to all Tabs  (Read 3519 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
'Insert' - Copy to all Tabs
« on: February 08, 2005, 02:44:43 PM »
I created this routine to copy objects form one layout tab to the remaining layouts.
All is fine except to blocks. I have an insert with attributes I need to copy.
I don't want to use the "Copy" command because you gave to activate each layout to
use it. All I do in this routine is create a new entity list and replace the 410 code
with the next tab name and entmake it.
Anyone have a 'Insert Copy' routine that I can modify to do the same? The routines
I have recreate the Block & not the insert. If not I'll figure it out but I don't have
much time to spare this week.

Code: [Select]
;;;  Copy2Tabs.lsp by Charles Alan Butler
;;;         Copyright 2004
;;;  by Precision Drafting & Design All Rights Reserved.
;;;  Contact at ab2draft@TampaBay.rr.com
;;;
;;;   Version 1.0 Beta  June 19,2004
;;;
;;; DESCRIPTION
;;;  Copy objects in one layout to all layouts
;;;
;;;  Limitations
;;;  Can not use in Model Space
;;;
;;; Command Line Usage
;;; Command: c2t
;;;
;;;  Options: none
;;;
;;;  This software is provided "as is" without express or implied      ;
;;;  warranty.  All implied warranties of fitness for any particular   ;
;;;  purpose and of merchantability are hereby disclaimed.             ;
;;;  You are hereby granted permission to use, copy and modify this    ;
;;;  software without charge, provided you do so exclusively for       ;
;;;  your own use or for use by others in your organization in the     ;
;;;  performance of their normal duties, and provided further that     ;
;;;  the above copyright notice appears in all copies and both that    ;
;;;  copyright notice and the limited warranty and restricted rights   ;
;;;  notice appear in all supporting documentation.                    ;
(defun c:c2t (/ cnt ss ctab omited sslen sscnt elst newent tab)
  ;;  Returns T if Locked
  ;;        nil if Unlocked or not found
  ;;        nil if lname is not a string
  (defun islayerlocked (lname / entlst)
    (and (= 'str (type lname))
         (setq entlst (tblsearch "LAYER" lname))
         (= 4 (logand 4 (cdr (assoc 70 entlst))))
    )
  ); defun
  (defun count ()
    (if (= cnt 0) ; count only once
      ;;  count the omitted from copy
      (setq omited (1+ omited))
    )
  ); defun
  (if (= (getvar "tilemode") 1)
    (alert "\nYou must be in Paper Space to run this routine.\t")
    (progn ; else you are in paper space, ok to proceed
      (if (/= (getvar "cvport") 1) ; a view port is active
        (command "_pspace") ; close the view port
      )
      (prompt "\nSelect objects to copy")
      (if (setq ss (ssget))
        (progn
          (setq ctab (getvar "ctab"))
          (setq cnt    0
                omited 0
                sslen  (sslength ss)
          )
          (foreach tab (layoutlist)
            (if (not (member tab (list "Model" ctab)))
              (progn
                (setq sscnt (sslength ss))
                (while (>= (setq sscnt (1- sscnt)) 0)
                  (setq elst (entget (ssname ss sscnt)))
                  (if (assoc 410 elst)
                    (progn
                      (if (null (islayerlocked (cdr (assoc 8 elst))))
                        (progn ; do not copy if layer is locked
                          (setq newent (subst (cons 410 tab) (assoc 410 elst) elst)
                                newent (strip newent))
                          (if (and (/= (cdr (assoc 0 newent)) "INSERT") ; skip blocks
                                (null(entmake newent)))
                            (count) ; rejected entity
                          )
                        )
                        (count) ; locked layer
                      )
                    )
                    (count) ; no 410 code
                  )
                )
                (setq cnt (1+ cnt))
              )
            )
          )
          (prompt
            (strcat "\n"(itoa cnt)" Layouts Updated with "(itoa sslen)
                         " items selected and "(itoa omited)" items not copied.")
          )
        )
      )
    )
  )
  (princ)
)
(prompt "\ncopy2tabs loaded, enter c2t to run.")
(princ)

;;  function to strip unwanted dxf codes for a new entity
;;  retuens a ent list ready for entmake
(defun strip (entl)
  ;;  ent expected to be an entity name or entlist or ename w/ point list
  (cond
    ((= (type entl) "ENAME")
     (setq entl (entget entl))
    )
    ((= (length entl) 2)
     (setq entl (car entl))
    )
  )
  (foreach n '(-2 -1 5 102 300 330 331 350 360)
    (while (assoc n entl)
      (setq entl (vl-remove (assoc n entl) entl))
    )
  )
  entl
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

whdjr

  • Guest
'Insert' - Copy to all Tabs
« Reply #1 on: February 08, 2005, 03:00:29 PM »
CAB,

Mine here copies blocks with attributes.

copyb

Jeff_M

  • King Gator
  • Posts: 4095
  • C3D user & customizer
'Insert' - Copy to all Tabs
« Reply #2 on: February 08, 2005, 03:06:12 PM »
CAB,
Here's one I put together last year specifically for inserting Title Block blocks into all PS layouts. I think it's more or less what you're after......
Code: [Select]

;;;Insert a block into all PaperSpace Layout Tabs,
;;;all at 0,0,0 & 0 deg. rotation
;;;by Jeff Mishler, January 2004

(defun c:ins2tabs ( / lays bname blk newblk)
  (setq lays (vla-get-layouts
      (vla-get-activedocument
(vlax-get-acad-object)))
bname (getstring "\nBlock to insert in all Layouts?: ")
)
  (if (not (tblsearch "block" bname))
    (progn
      (princ "\nBlock not found, please select block: ")
      (setq bname
    (getfiled "Block Selection for Tab Insert" bname "dwg" 0))
      )
    )
  (vlax-for x lays
    (if (not (= "Model" (vla-get-name x)))
      (progn
(setq blk (vla-get-block x)
     newblk (vlax-invoke-method
      blk
      'insertblock
      (vlax-3d-point
'(0.0 0.0 0.0))
      bname 1.0 1.0 1.0 0.0))
;;;    (vla-add (vla-get-layouts
;;;       (vla-get-activedocument
;;; (vlax-get-acad-object))) "Title")
;;;    (vla-put-layer newblk "Title")
;;; uncomment above to place on layer other than the current one
)
      )
    )
  (princ)
  )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
'Insert' - Copy to all Tabs
« Reply #3 on: February 08, 2005, 03:20:17 PM »
Thanks fellas, :D
 You would think I would remember that thread Will, brain fade.
 Jeff as always you make it look so easy.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
'Insert' - Copy to all Tabs
« Reply #4 on: February 08, 2005, 03:35:26 PM »
Will, your routine worked first try, Thanks.
Feedback: copied to ALL layouts not just the selected ones. [ACAD2000]
no big deal.

Jeff I will explore yours as time permits.
There killing me, can't get enough Swamp Time. :shock:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
'Insert' - Copy to all Tabs
« Reply #5 on: February 08, 2005, 04:42:31 PM »
nice job guys... that is a timesaver
Civil3D 2020

whdjr

  • Guest
'Insert' - Copy to all Tabs
« Reply #6 on: February 09, 2005, 01:37:43 PM »
CAB,

I updated my copyb.lsp prog to allow for tab selection.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
'Insert' - Copy to all Tabs
« Reply #7 on: February 09, 2005, 01:43:27 PM »
Hay, that was quick.
Nice job. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.