+ Reply to Thread
Results 1 to 3 of 3

Thread: Help with code

  1. #1
    Forum Newbie
    Using
    AutoCAD 2008
    Join Date
    Oct 2007
    Posts
    1

    Default Help with code

    Registered forum members do not see this ad.

    I have some code that I came across that needs a little updating. It was created by a gentlemen named Paul Mofers back in 2001. The only problem is it's now 2008 and I cannot find him or figure this thing out. Honestly I'm a LISP newbie and the more I search the more dead ends I hit. This code actually works great, but I noticed it's not changing the layers for HATCHES, SOLIDS, and MTEXT, and possibly others. Bascially I want it to change everything if possible. Thanks in advance!


    Code:
    ;;; Paul Mofers
    ;;; 27-11-2001
    ;;;
     
    (defun c:clkc ()
    (ChangeLayerKeepColor)
    (princ)
    )
     
    (defun ChangeLayerKeepColor ( / SelectionSet LayerName counter EntData
    EntLayer EntColor Color)
    (prompt "\nSelect the entitie(s) you want to change the layer of... ")
    (setq SelectionSet (ssget))
    (if (not SelectionSet)
    (prompt "\n There was nothing selected! ")
    (progn
    (setq LayerName (getstring "\nLayer name (Enter to exit): "))
    (if (= LayerName "")
    (prompt "\nProgram ended... ")
    (if (tblsearch "LAYER" LayerName)
    (progn
    (setq counter 0)
    (repeat (sslength SelectionSet)
    (setq EntData (entget (ssname SelectionSet counter))
    EntLayer (cdr (assoc 8 EntData))
    EntColor (cdr (assoc 62 EntData))
    )
    (if (= EntColor nil)
    (setq EntColor (cdr (assoc 62 (tblsearch "LAYER" EntLayer)))
    Color T
    )
    (setq Color nil)
    )
    (setq EntData (subst (cons 8 LayerName)(assoc 8 EntData) EntData))
    (if Color
    (setq Entdata (cons (cons 62 EntColor) Entdata))
    (setq EntData (subst (cons 62 EntColor) (assoc 62 EntData) EntData))
    )
    (entmod EntData)
    (setq counter (1+ counter))
    )
    )
    (prompt (strcat "\nLayername " LayerName " does not exist ! "))
    )
    )
    )
    )
    )

  2. #2
    Senior Member bsamc2000's Avatar
    Computer Details
    bsamc2000's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP Z400
    CPU:
    Intel Xeon 2.66GHz
    Graphics:
    NVIDIA GeForce 9500 GT
    Monitor:
    E228WFP (2x)
    Using
    AutoCAD 2011
    Join Date
    Mar 2007
    Location
    Columbus, Ohio
    Posts
    120

    Default

    Can you please post a drawing that it does not change. It could be helpful.

    Thanks,
    Brian

  3. #3
    Junior Member
    Using
    AutoCAD 2002
    Join Date
    Oct 2007
    Location
    Nhatrang, Vietnam
    Posts
    10

    Default

    Registered forum members do not see this ad.

    Maybe this program is conformable to your wishes:
    Code:
    ;;;CHANGE LAYER, KEEP COLORS PROGRAM
    ;;;Written by ssg - October 16th, 2007
    
    ;;;------------------------------------------------------------------------
    (defun GetLay(/ Lay Laylist) ;;;Get all layers in drawing. Return string
    (setq Lay (tblnext "LAYER" T) Laylist "")
    (While Lay (setq Laylist (strcat Laylist (cdr (assoc 2 Lay)) "/") Lay (tblnext "LAYER")))
    Laylist
    )
    ;;;------------------------------------------------------------------------
    (defun getc(e / color tbl) ;;;Get color of entity e
    (if (not (setq color (cdr (assoc 62 (entget e)))))
        (setq
            tbl (tblsearch "layer" (cdr (assoc 8 (entget e))))
            color (cdr (assoc 62 tbl))
        )
    )
    color
    )
    ;;;------------------------------------------------------------------------
    (defun claykc(e lay / color) ;;;Change e to lay, keep color
    (setq color (getc e))
    (command "change" e "" "p" "la" lay "c" color "")
    )
    ;;;=======================================
    (defun C:CLK( / ss mylay e) ;;;Change layer, keep color. All objects selected by user
    (setq ss (ssget))
    (if (not ss)
        (prompt "\nThere was nothing selected!")
        (progn
            (setq mylay (getstring (strcat "\nLayer name " (getlay) " <Enter to exit>:")))
            (if (= mylay "") (exit))
            (if (tblsearch "LAYER" mylay)
                (while (setq e (ssname ss 0)) (claykc e mylay) (ssdel e ss))
                (prompt (strcat "\nLayername " mylay " does not exist!"))
            )
        )
    )
    (princ)
    )
    ;;;=======================================

Similar Threads

  1. DXF code 410 VBA solutions?
    By P Zero in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 11th Aug 2007, 10:13 am
  2. My first code...
    By Seann in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 2nd Feb 2007, 08:09 pm
  3. code
    By rahul in forum AutoCAD 3D Modelling & Rendering
    Replies: 3
    Last Post: 20th Jul 2006, 06:19 am
  4. drawing an arc using VBA code
    By kanyakumari_t in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 28th Oct 2005, 02:11 am
  5. VBA Code????
    By acatalin2003 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 4th Oct 2005, 11:20 am

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