+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
  1. #1
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Aug 2010
    Posts
    6

    Exclamation generate layers based on color?

    Registered forum members do not see this ad.

    hey guys i have a file with 2 dozen layers each with objects in 12 different colors and i need to sort them out into layers depending on the objects color. e.g. all the objects with color "yellow" in one layer, all the objects with color "magenta" in another layer etc. can this be done with a lisp? can anyone help me i now nothing about writing lisp's

  2. #2
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,948

    Default

    This should get you started:

    Code:
    ((lambda (i / ss e c)
      (setq ss (ssget))
      (while (setq e (ssname ss (setq i (1+ i))))
        (cond 
          ((= 1 (setq c (cdr (assoc 62 (entget e)))))
            ;; <- Code for red objects
            )
          ((= 2 c)
            ;; <- Code for yellow objects
            )
          ((= 3 c)
            ;; <- Code for green objects
            )
          ((= 4 c)
            ;; <- Code for cyan objects
            )
          ;; <- Additional colors here
        ))
      (princ))
    -1)
    "Potential has a shelf life." - Margaret Atwood

  3. #3
    Forum Newbie
    Using
    AutoCAD 2011
    Join Date
    Aug 2010
    Posts
    6

    Default

    thanks RenderMan i will try it out, all dough i have no experience with writing lisp, if you could fill in some of the blancks foor me that would be great!

  4. #4
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,627

    Default

    This may help you and the main idea of the routine is inspired by RenderMan .

    Code:
    (defun c:test (/ ss)
    (if (setq ss (ssget "_:L" ))
     (
      (lambda (i / ss1 e col)
       (while
         (setq ss1 (ssname ss (setq i (1+ i))))
           (setq e (entget ss1))
             (setq col (cdr (assoc 62 e)))
             (cond ((eq 1 col)
                (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Layer1")(assoc 8 e) e))))))
               ((eq 2 col)
                    (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Layer2")(assoc 8 e) e))))))
               ((eq 3 col)
                       (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Layer3")(assoc 8 e) e))))))
                )
              )
            )
         -1
        )
       (princ)
        )
      (princ)
      )
    Tharwat

  5. #5
    Full Member Smirnoff's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Location
    Riga, Latvia
    Posts
    57

    Default

    This will distribute all entities with non 'By Layer' color to layers named 'Color N'. Entities which have 'By Layer' color or on locked or frozen layers will be passed.

    Code:
    (defun c:colay(/ aSet lCol cLay)
      
      (vl-load-com)
      
      (if(setq aSet(ssget "_X"))
        (progn
          (setq lCol(vla-get-Layers
    		  (vla-get-ActiveDocument
    		    (vlax-get-acad-object))))
        (foreach e(vl-remove-if 'listp(mapcar 'cadr(ssnamex aSet)))
          (if(setq cCol(cdr(assoc 62(entget e))))
    	   (setq cLay(strcat "Color " (itoa cCol))
    		 cFlg T)
    	   (setq cFlg nil)
    	); end if
         (if cFlg
           (progn
            (if(vl-catch-all-error-p
    	    (vl-catch-all-apply
    	     'vla-Item (list lCol cLay)))
    	  (vla-Add lCol cLay)
    	); and if
    	(vl-catch-all-error-p
    	    (vl-catch-all-apply
    	     'vla-put-Layer (list e cLay)))
           ); end progn
           ); end if
          ); end foreach
         ); end progn
        ); end if
      (princ)
      ); end of c:colay

  6. #6
    Super Member David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    1,926

    Default

    Or something fairly simple should work as well:

    Code:
    (defun c:enc (/ ss en ed clr)
      (and (setq ss (ssget))
           (while (setq en (ssname ss 0))
                  (setq ed (entget en))
                  (if (setq clr (cdr (assoc 62 ed)))
                      (entmod (subst (cons 8 (strcat "C" (itoa clr)))
                                     (assoc 8 ed) ed)))
                 (ssdel en ss)))
      (prin1))

    Bylayer entities are not affected. New layer name is "C" and the color number. -David
    R12 (Dos) - A2K

  7. #7
    Full Member Smirnoff's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Location
    Riga, Latvia
    Posts
    57

    Default

    Code:
    (entmod (subst (cons 8 (strcat "C" (itoa clr)))(assoc 8 ed) ed))
    Here is very good solution. Entmod entity and create layer at once.

  8. #8
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,587

    Default

    Are you back, friend???
    Knock my door

    Oleg
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  9. #9
    Full Member Smirnoff's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Location
    Riga, Latvia
    Posts
    57

    Default

    Are you back, friend??
    Hi Oleg. Yes I'm back working in AutoCAD and will sometimes coming here.

    Alexander.

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,732

    Default

    Registered forum members do not see this ad.

    ASMI, is that you? Good to see you back if so
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

Similar Threads

  1. Routine to generate layouts based on rectangles in a larger drawing
    By ABuckingham in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 9th Dec 2012, 08:37 am
  2. creating layers by color
    By gib65 in forum AutoCAD Drawing Management & Output
    Replies: 6
    Last Post: 7th Jul 2011, 12:50 am
  3. Change Layers Based On Text Height
    By peterk92 in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 1st Oct 2010, 11:08 am
  4. layers color and printing
    By hamedo_kool in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 13th Mar 2009, 03:25 pm
  5. disable 'reconcile layers' dialogue based on autocad version
    By P Zero in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 23rd Jul 2008, 09:20 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts