Author Topic: (beta test) Change to current layer app  (Read 3272 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(beta test) Change to current layer app
« on: June 08, 2005, 09:54:25 AM »
I need some beta testers please.

I wanted to create a program that will allow me to change an item to the current layer. Something quick and simple. But I havent written a program in a long time so... Could someone break this. (Im looking for its "limits") Once I think its to an acceptable level, I'll re-write it so I can have cleaner code and a bit more optomized progy.

ChangeLayer.lsp
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(beta test) Change to current layer app
« Reply #1 on: June 08, 2005, 10:24:57 AM »
No can review --



Grrr. Here's a quick one off for ideas --

Code: [Select]
(defun c:ToCLayer ( / _GetLockedLAyers _MakeLayerFilter _Main )

    (defun _GetUnLockedLayers ( document / result )
        (vlax-for layer (vla-get-layers document)
            (if (eq :vlax-false (vla-get-lock layer))
                (setq result
                    (cons
                        (vla-get-name layer)
                        result
                    )
                )
            )
        )
    )
   
    (defun _MakeLayerFilter ( layers )
        (if layers
            (append
               '((-4 . "<or"))
                (mapcar '(lambda (layer) (cons 8 layer)) layers)
               '((-4 . "or>"))
            )
        )    
    )
   
    (defun _Main ( document / ss i unlocked clayer )
        (cond
            (  
                (and
                    (setq unlocked (_GetUnLockedLayers document))
                    (setq
                        clayer   (getvar "clayer")
                        ss       (ssget (_MakeLayerFilter unlocked))
                    )
                )    
                (repeat (setq i (sslength ss))
                    (vla-put-layer
                        (vlax-ename->vla-object    
                            (ssname ss
                                (setq i (1- i))
                            )
                        )
                        clayer
                    )
                )
            )
            (   (null unlocked)
                (princ
                    (strcat
                        "All layers are locked, thus "
                        "you can't do anything."
                    )    
                )
            )
        )
        (princ)        
    )
   
    (_Main
        (vla-get-activedocument
            (vlax-get-acad-object)
        )
    )
   
)

Nominally tested, cheers.

Edit: Tested for all layers locked scenario.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(beta test) Change to current layer app
« Reply #2 on: June 08, 2005, 10:30:59 AM »
Cut and paste ma-friend.

Thanx, i'll look at it now.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
(beta test) Change to current layer app
« Reply #3 on: June 08, 2005, 10:33:20 AM »
Here was my cheap button I made...I was so proud of it *tear*
Code: [Select]
(setq clay (getvar "clayer"));(setq ent (ssget));\\;(command "chprop" ent "" "LA" clay "");

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(beta test) Change to current layer app
« Reply #4 on: June 08, 2005, 10:33:56 AM »
...locked layer?! Good one.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(beta test) Change to current layer app
« Reply #5 on: June 08, 2005, 10:36:17 AM »
Thanks John. I updated it to deal with the scenario of all layers locked.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(beta test) Change to current layer app
« Reply #6 on: June 08, 2005, 10:36:49 AM »
Dommy,  Nice, but a button isnt what i wanted. I also supose i could have used the express tool and made a keyboard shortcut, but i this is more fun.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
(beta test) Change to current layer app
« Reply #7 on: June 08, 2005, 10:39:36 AM »
Oh...I know...just showing how I'm humbled by everyone's abilities here.

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(beta test) Change to current layer app
« Reply #8 on: June 08, 2005, 10:42:18 AM »
Oh got cha buddy.

*Psst!* No one should feel "less then" cause we all have our strengths and we all start somewhere.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
(beta test) Change to current layer app
« Reply #9 on: June 08, 2005, 11:28:55 AM »
John
Here is my take on the routine.
It does not need the Undo, on my system anyway.
I gave the option of pickfirst or entsel or ssget.

Code: [Select]
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
;;; FUNCTION
;;;   To filter a preselected selection set for object types
;;;   listed in the variable list lst
;;;
;;; ARGUMENTS
;;;   lst -> a list of object types like ("TEXT" "MTEXT")
;;;          nil will allow all types
;;;
;;; USAGE
;;;   (setq ss (getpickfirst typs))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2004 Charles Alan Butler  
;;;          Co-author S. Madsen
;;;   ab2draft@TampaBay.rr.com
;;;
;;; VERSION
;;; 1.1 Sep. 18, 2004
;;;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
(defun getpickfirst (lst / ss a ent)
  ;;  lst is a list of object types like ("TEXT" "MTEXT")
  (cond ((and (setq ss (cadr (ssgetfirst))) ; get previously selected sel set
              lst ; nil will allow all types
         )
         (setq a 0) ; set pointer
         (repeat (sslength ss) ; foreach object in sel set
           (setq ent (ssname ss a) ; get obj name
                 a   (1+ a)
           ) ; increment counter
           ;; is obj not a member of the list ?
           (and (not (member (cdr (assoc 0 (entget ent))) lst))
                (ssdel ent ss) ; if not a member remove it from ss
                (setq a (1- a)) ; and deincrement pointer
           ) ; and
         ) ; repeat
        ) ; end cons 1
  ) ; end cond stmt
  ;; if ss is a pick set and has objects then return the selection set
  (if (and (= (type ss) 'pickset) (/= 0 (sslength ss)))
    ss
  )
  ;;  else return nil because when IF fails it returns nil
) ; end defun

(defun IsLocked (lname)
  (= (vlax-get-property
       (vla-item
         (vla-get-Layers
           (vla-get-ActiveDocument
             (vlax-get-acad-object)
           )
         )
         lname
       ) ; layer name
       'Lock
     )
     :vlax-true
  )
)

(defun c:ent2lyr (/ ent ss obj lyr i)
  (if
    (or (setq ss (getpickfirst nil))
        (setq ent (entsel "\nSelect entity to move to current layer."))
        (null (prompt "\nSelect a group of objects to move to current layer."))
        (setq ss (ssget))
    )
     (cond
       (ent
        (if (IsLocked
              (setq lyr (vlax-get-property
                          (setq obj (vlax-ename->vla-object (car ent)))
                          'LAYER
                        )
              )
            )
          (prompt (strcat "\n**  Locked Layer -->" lyr " **"))
          (vlax-put-property obj 'LAYER (getvar "clayer"))
        )
       )
       (T
        (setq i -1)
        (while (setq ent (ssname ss (setq i (1+ i))))
          (if (IsLocked
                (setq lyr (vlax-get-property
                            (setq obj (vlax-ename->vla-object ent))
                            'LAYER
                          )
                )
              )
            (prompt (strcat "\n**  Locked Layer -->" lyr " **"))
            (vlax-put-property obj 'LAYER (getvar "clayer"))
          )
        )
       )
     )
  )
  (princ)
)
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.