Author Topic: Duplicado Layer - Review please.. [comments desired]  (Read 883 times)

0 Members and 1 Guest are viewing this topic.

ScottMC

  • Newt
  • Posts: 193
Duplicado Layer - Review please.. [comments desired]
« on: August 26, 2022, 09:44:12 PM »
coagulation of ronjonp and giles engineering! [THANKS!!] it seems to work and makes me wonder if it
has any oops. Only possible, but not needed, is prompt for the layer name if making/naming is needed.

Code: [Select]
(defun c:nl (/ cnt lay nlay pt ss sse ssl ssn)
  (vl-load-com)        ;; http://www.theswamp.org/index.php?topic=21028.msg254990#msg254990
  (setvar 'cmdecho 0)
  (setq nlay "TEMP") ;; could..prompt for new layer name /\
  (setq lay (getvar "clayer")) ;; get current active layer
              (if
                (/= lay nlay)
                 (command "_layer" "m" nlay "c" 7 "" "") ;; make new nlay/TEMP layer if none..
               )
       (command "_layer" "off" nlay "") ;; turn off new TEMP..
 
  (defun sl (/ ssg ent) ;; http://www.theswamp.org/index.php?topic=53238.msg579886#msg579886
      (if
        (or         ;;      gile  [ Here's a way which honors pickfirst and can also be used within a ]
                      ;;              [     "Select object" prompt (entering (sl) expression).                       ]
          (and
            (setq ssg (cadr (ssgetfirst)))
            (= 1 (sslength ssg))
            (setq ent (ssname ssg 0))
          )
          (and
            (sssetfirst nil nil)
            (setq ent (car (entsel)))
          )
        )
        (ssget "_X" (list (assoc 8 (entget ent))))
      )
    )

    (princ "\n Copy ALL on Layer of Object TO: New Layer: \"TEMP\"..")
      (sssetfirst nil (sl))                         
     (setq ss (ssget ssg))            ;; works but.. just wonder if this local/transition is correct/simplifiable.....
                                  ;;(setq ss (ssget "x" '((8 . "0")))) ;; was..
    (setq ssl (sslength ss)) ;; make list from ss
    (setq cnt 0)      ;; reset item count
          (repeat   ;; start copy each item to TEMP..
            ssl
             (setq ssn (ssname ss cnt))
             (setq sse (entget ssn))
                            ;(setq etyp (cdr (assoc 0 sse))) ;; <-- no idea
             (setq pt (cdr (assoc 10 sse)))
             (setvar "clayer" nlay) ;; change layer to 'nlay/TEMP'
             (command "_copy" ssn "" pt pt) ;; enter removed..
             (vla-put-Layer (vlax-ename->vla-object (entlast)) "TEMP") ;; items copied/moved 1.by.1 to TEMP
           (setq cnt (1+ cnt)) ;; work item number
          ) ; repeat/item
        (setvar "clayer" lay) ;; revert to layer before..
                                                                ;(setq cnt  (1- cnt))       ;; count confusion as PS is included at times??
        (princ (strcat "**< " (itoa cnt)" >** Items Copied to Layer: \""(strcase nlay)"\" <PS Included>\n" ))
        (setvar 'cmdecho 1)                     ;; post total items copied to TEMP
  (princ)
) ; defun
 

mhupp

  • Bull Frog
  • Posts: 250
Re: Duplicado Layer - Review please.. [comments desired]
« Reply #1 on: August 30, 2022, 11:12:30 AM »
Updated the code a bit to be a little more efficient.

Will prompt you for layer name. you can enter one or hit enter and it will default to "TEMP"

--edit
updated so layer names can have spaces if you want.
« Last Edit: August 30, 2022, 11:33:59 AM by mhupp »

ScottMC

  • Newt
  • Posts: 193
Re: Duplicado Layer - Review please.. [comments desired]
« Reply #2 on: August 30, 2022, 02:51:57 PM »
EXCELLANT! I stuck the Layer/off back in after the first if.. (learning..) Thanks
Another I've been on today is to single click on an object to copy@ while avoiding
/ refusing frozen layers. The here's the one I've mixed together but gets an error :(

Code: [Select]
(defun-q c:kk ( / *error* cc1 ) ;; ^C^CMULTIPLE;_KK < shortcut scrip !
          (setvar 'cmdecho 0)
          (defun *error* ( msg )
            (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
            (if qaf (setvar 'qaflags qaf))
            (if msg (prompt msg))
              (setvar "nomutt" 0)  ;; <--WORKS to restore on pre-finish esc..
            (princ)
          ) ;; end of *error*           
          (princ "\n ** Copy@ ** \n")
        (princ "\n Select Object to Copy:")
            (setvar 'nomutt 1)
        (setq ss1 ;;               \/ express tool selection
                                 (ai_ssget (ssget "_:S")) ;; filters out LOCKED object selection..
        )                           ;; but.. sends error when filtering ?%@
                ;; until error trap above !
         (setq cc1 (getvar "lastpoint"))
              ;; --  /\   /\   IFFY.......  gets wrong/last basepoint.. how can I just get where/on object clicked
            (vl-cmdf "_copybase" cc1 ss1 "" "_pasteclip" cc1) ;; copy + paste using cc1 basepoint
          (setvar 'cmdecho 1)
        (setvar 'nomutt 0)
    (princ)
)

   ** NON LOCKED SOLUTION [:L] WORKS PERFECT **
The purpose is to simply copy@ avoiding frozen - working on using Lee Mac's filter tool but still not right.
https://www.theswamp.org/index.php?PHPSESSID=956293a41cfd402d23b924e492f230a1&topic=56173.msg600892#msg600892
« Last Edit: August 30, 2022, 03:29:51 PM by ScottMC »

mhupp

  • Bull Frog
  • Posts: 250
Re: Duplicado Layer - Review please.. [comments desired]
« Reply #3 on: August 30, 2022, 03:02:49 PM »
:S is single selection
:L is to ignore locked

Good read
http://www.lee-mac.com/ssget.html

--edit
If copybase and pastclip are using the same point just pick a random point no need to keep recalculating it.
also use "_non" in front of points if you are using command depending on zoom level it could snap to other things.
Code - Auto/Visual Lisp: [Select]
  1. (vl-cmdf "_copybase" "_non" '(0 0 0) ss1 "" "_pasteclip" "_non" '(0 0 0)) ;; copy + paste using cc1 basepoint
« Last Edit: August 30, 2022, 03:08:26 PM by mhupp »

ScottMC

  • Newt
  • Posts: 193
Re: Duplicado Layer - Review please.. [comments desired]
« Reply #4 on: August 30, 2022, 03:12:33 PM »
OMH..  when locked selected.. removed ai_.. and made (ssget "_:L:S")
oops.. removed [:S] and works fine.
Really simple! Now, getting a 'nearer' basepoint.. had it originally
[0,0,0] but not fool-proof so am tryin to get a real, as selecting
object, basepoint.
When needed, would rether have a nearer basepoint if possible.
Wish lastpoint or something could get where I click/select.
« Last Edit: August 30, 2022, 04:19:03 PM by ScottMC »

JohnK

  • Administrator
  • Seagull
  • Posts: 10652
Re: Duplicado Layer - Review please.. [comments desired]
« Reply #5 on: August 30, 2022, 03:34:17 PM »
I was in a meeting and I thought I would play with the getting the layer name part. Here is what I came up with (not sure about the "allow spaces" but...).

Code - Auto/Visual Lisp: [Select]
  1. (defun getstr (message initial default)
  2.   (cond
  3.     ((eq initial "") default)
  4.     (initial initial)
  5.     ((getstr message (getstring T message) default))
  6.     )
  7.   )
  8.  
  9. (setq new-layername (getstr "Specify a layer name [\"TEMP\"]:" nil "TEMP"))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ScottMC

  • Newt
  • Posts: 193
Re: Duplicado Layer - Review please.. [comments desired]
« Reply #6 on: August 30, 2022, 03:42:03 PM »
Guess I'm gonna have to get use-to another click.. here's what will work.
*** updated 7pm..  ***

Code: [Select]
(defun-q c:kk ( / *error* cc1 ) ;; ^C^CMULTIPLE;_KK < shortcut scrip !
          ;(setvar 'cmdecho 0)
          (defun *error* ( msg )
            (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
            (if qaf (setvar 'qaflags qaf))
            (if msg (prompt msg))
              (setvar "nomutt" 0)  ;; <--WORKS to restore on pre-finish esc..
            (princ)
          ) ;; end of *error*           
           (princ "\n Select Object(s) to Copy@:") ;(princ "\n ** Copy@ **")   
          (setq cc1 (getpoint "\n Basepoint"))   ;(setq cc1 (getvar "lastpoint")) ;; <- IFFY....
           ;;(setq cc1 (0,0,0)) ;; (getpoint "\n Basepoint"))   ;(setq cc1 (getvar "lastpoint")) ;; <- IFFY....
          ; (setvar 'nomutt 1)
                (setq ss1 (ssget "_:L"))
                ;; until error trap!
            (vl-cmdf "_copybase" cc1 ss1 "" "_pasteclip" cc1) ;; copy + paste using cc1 basepoint
          (setvar 'cmdecho 1)
       ; (setvar 'nomutt 0)
    (princ)
)
« Last Edit: August 30, 2022, 08:00:29 PM by ScottMC »