+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21
  1. #1
    Junior Member
    Discipline
    Structural
    Using
    AutoCAD 2017
    Join Date
    Jun 2018
    Posts
    17

    Default code that select all object and convert in to mentioned layer

    Registered forum members do not see this ad.

    Hello every one i need help on completing below code.


    Basically i need code that select objects and after selecting objects convert layer "obj2" into "obj1" layer and "dim" into "0" layer


    (defun c: autolayerchange ()
    (if (setq ss (ssget))
    (prong (setq i (1- (sslength ss)))
    (while (<= 0 i)
    (setq e (ssname ss i)
    x (cdr (assoc 8 (entget e)))
    i (1- i)
    ) ; it is returning object layer name
    (foreach x "obj2" convert to layer "obj1")
    (foreach x "dim" convert to layer "0")


    ))))


    i am stuck at red marked text. thank you for your help

  2. #2
    Senior Member satishrajdev's Avatar
    Computer Details
    satishrajdev's Computer Details
    Operating System:
    Windows 7 - 64bit
    Computer:
    DELL
    RAM:
    8 GB
    Primary Storage:
    500 GB
    Monitor:
    DELL
    Discipline
    Surveying
    satishrajdev's Discipline Details
    Occupation
    CAD Engineer
    Discipline
    Surveying
    Details
    Design Survey Utilities (i.e. Bathymetry & Geophysical Survey) Design of Survey Planning. Preparation of Alignment Sheets. Programming in AutoCAD.
    Using
    AutoCAD 2014
    Join Date
    Apr 2012
    Location
    Aamchi Mumbai, India
    Posts
    451

    Default

    Something like this?

    Code:
    (defun c:test ( / e i l ss)
      (if (setq ss (ssget))                       ; <- add your ssget filter here
        (repeat (setq i (sslength ss))
          (setq e (entget (ssname ss (setq i (1- i)))))
          (setq l (cdr (assoc 8 e)))
          (cond ((eq l "obj2") (entmod (subst (cons 8 "obj1") (assoc 8 e) e)))
    	    ((eq l "dim") (entmod (subst (cons 8 "0") (assoc 8 e) e)))
          )
        )
      )
      (princ)
    )
    Best Regards,
    Satish Rajdev

    If you ride like there is no tomorrow... Don't worry, there won't be !!!!
    www.facebook.com/satish.rajdev

  3. #3
    Senior Member ziele_o2k's Avatar
    Discipline
    Construction
    Using
    AutoCAD 2018
    Join Date
    Jun 2014
    Location
    Poland
    Posts
    137

    Default

    Another:
    Code:
    (defun c:autolayerchange ( / _in _ss _obj)
      (if
        (setq _ss (ssget (list (cons 8 "obj2,dim"))));; <- change your ssget filter
        (repeat (setq _in (sslength _ss))
          (setq _obj (vlax-ename->vla-object (ssname _ss (setq _in (1- _in))))); get 
          (if (= (vla-get-layer _obj) "obj2")
            (vla-put-layer _obj "obj1")
            (vla-put-layer _obj "0")
          )
        )
      )
    )

  4. #4
    Junior Member
    Discipline
    Structural
    Using
    AutoCAD 2017
    Join Date
    Jun 2018
    Posts
    17

    Default

    i added layer selection filter but its not working...

  5. #5
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,478

    Default

    Another:
    Code:
    (defun C:AutoLayerChange ( / L _LayersList _Recapitalise lyrs SS i enx lyr tmp )
      
      (setq L ; Note: layer names are case insensitive - assoc list of: (<old layer> . <new layer>)
        '( ; Place your inputs here:
          ("obj2" . "obj1")
          ("dim" . "0")
        ); list
      ); setq L
      
      (defun _LayersList ( / d L )
        (while (setq d (tblnext "LAYER" (not d)))
          (setq L (cons (cdr (assoc 2 d)) L))
        )
      )
      
      (defun _Recapitalise ( itm L )
        (vl-some (function (lambda (x) (if (= (strcase itm) (strcase x)) x))) L)
      )
      
      (and
        (setq lyrs (_LayersList))
        (or
          (setq L (apply (function append) (mapcar (function (lambda (x / tmp) (if (setq tmp (_Recapitalise (car x) lyrs)) (list (cons tmp (cdr x)))))) L)))
          (prompt "\nNo valid layers were found.")
        ); or
        (or
          (prompt "\nSelect objects to change layers: ")
          (setq SS (ssget "_:L-I" (list (cons 8 (setq tmp (substr (apply (function strcat) (mapcar (function (lambda (x) (strcat "," (car x)))) L)) 2))))))
          (prompt (strcat "\nNo objects were found on \"" tmp "\"  layers."))
        ); or
        (repeat (setq i (sslength SS))
          (setq enx (entget (ssname SS (setq i (1- i)))))
          (setq lyr (assoc 8 enx))
          (entmod (subst (cons 8 (cond ( (cdr (assoc (setq tmp (cdr lyr)) L)) ) ( tmp ) )) lyr enx))
        ); repeat
      ); and
      (princ) 
    ); defun C:AutoLayerChange

  6. #6
    Senior Member satishrajdev's Avatar
    Computer Details
    satishrajdev's Computer Details
    Operating System:
    Windows 7 - 64bit
    Computer:
    DELL
    RAM:
    8 GB
    Primary Storage:
    500 GB
    Monitor:
    DELL
    Discipline
    Surveying
    satishrajdev's Discipline Details
    Occupation
    CAD Engineer
    Discipline
    Surveying
    Details
    Design Survey Utilities (i.e. Bathymetry & Geophysical Survey) Design of Survey Planning. Preparation of Alignment Sheets. Programming in AutoCAD.
    Using
    AutoCAD 2014
    Join Date
    Apr 2012
    Location
    Aamchi Mumbai, India
    Posts
    451

    Default

    What objects are you trying to select? Post your code here so that we can check it
    Best Regards,
    Satish Rajdev

    If you ride like there is no tomorrow... Don't worry, there won't be !!!!
    www.facebook.com/satish.rajdev

  7. #7
    Junior Member
    Discipline
    Structural
    Using
    AutoCAD 2017
    Join Date
    Jun 2018
    Posts
    17

    Default

    (defun c:test ( / e i l ss)
    (if (setq ss (ssget (list (cons 8 "dim,obj2")))) ; <- add your ssget filter here
    (repeat (setq i (sslength ss))
    (setq e (entget (ssname ss (setq i (1- i)))))
    (setq l (cdr (assoc 8 e)))
    (cond ((eq l "obj2") (entmod (subst (cons 8 "obj1") (assoc 8 e) e)))
    ((eq l "dim") (entmod (subst (cons 8 "0") (assoc 8 e) e)))
    )
    )
    )
    (princ)
    )


    it is not working ...


    and code which is shared by ziele is working but it is converting both layer to "0" layer it should converted (obj2 to obj1 and dim to 0)

  8. #8
    Junior Member
    Discipline
    Structural
    Using
    AutoCAD 2017
    Join Date
    Jun 2018
    Posts
    17

    Default

    Quote Originally Posted by Grrr View Post
    Another:
    Code:
    (defun C:AutoLayerChange ( / L _LayersList _Recapitalise lyrs SS i enx lyr tmp )
      
      (setq L ; Note: layer names are case insensitive - assoc list of: (<old layer> . <new layer>)
        '( ; Place your inputs here:
          ("obj2" . "obj1")
          ("dim" . "0")
        ); list
      ); setq L
      
      (defun _LayersList ( / d L )
        (while (setq d (tblnext "LAYER" (not d)))
          (setq L (cons (cdr (assoc 2 d)) L))
        )
      )
      
      (defun _Recapitalise ( itm L )
        (vl-some (function (lambda (x) (if (= (strcase itm) (strcase x)) x))) L)
      )
      
      (and
        (setq lyrs (_LayersList))
        (or
          (setq L (apply (function append) (mapcar (function (lambda (x / tmp) (if (setq tmp (_Recapitalise (car x) lyrs)) (list (cons tmp (cdr x)))))) L)))
          (prompt "\nNo valid layers were found.")
        ); or
        (or
          (prompt "\nSelect objects to change layers: ")
          (setq SS (ssget "_:L-I" (list (cons 8 (setq tmp (substr (apply (function strcat) (mapcar (function (lambda (x) (strcat "," (car x)))) L)) 2))))))
          (prompt (strcat "\nNo objects were found on \"" tmp "\"  layers."))
        ); or
        (repeat (setq i (sslength SS))
          (setq enx (entget (ssname SS (setq i (1- i)))))
          (setq lyr (assoc 8 enx))
          (entmod (subst (cons 8 (cond ( (cdr (assoc (setq tmp (cdr lyr)) L)) ) ( tmp ) )) lyr enx))
        ); repeat
      ); and
      (princ) 
    ); defun C:AutoLayerChange

    working for me thank you... but need to understand your code

  9. #9
    Senior Member satishrajdev's Avatar
    Computer Details
    satishrajdev's Computer Details
    Operating System:
    Windows 7 - 64bit
    Computer:
    DELL
    RAM:
    8 GB
    Primary Storage:
    500 GB
    Monitor:
    DELL
    Discipline
    Surveying
    satishrajdev's Discipline Details
    Occupation
    CAD Engineer
    Discipline
    Surveying
    Details
    Design Survey Utilities (i.e. Bathymetry & Geophysical Survey) Design of Survey Planning. Preparation of Alignment Sheets. Programming in AutoCAD.
    Using
    AutoCAD 2014
    Join Date
    Apr 2012
    Location
    Aamchi Mumbai, India
    Posts
    451

    Default

    Quote Originally Posted by Solitechcadsolutions View Post
    (defun c:test ( / e i l ss)
    (if (setq ss (ssget (list (cons 8 "dim,obj2")))) ; <- add your ssget filter here
    (repeat (setq i (sslength ss))
    (setq e (entget (ssname ss (setq i (1- i)))))
    (setq l (cdr (assoc 8 e)))
    (cond ((eq l "obj2") (entmod (subst (cons 8 "obj1") (assoc 8 e) e)))
    ((eq l "dim") (entmod (subst (cons 8 "0") (assoc 8 e) e)))
    )
    )
    )
    (princ)
    )


    it is not working ...


    and code which is shared by ziele is working but it is converting both layer to "0" layer it should converted (obj2 to obj1 and dim to 0)
    This code working fine at my end. Please check properly.

    I checked zilele's code also that also works fine. something is wrong are your end
    Best Regards,
    Satish Rajdev

    If you ride like there is no tomorrow... Don't worry, there won't be !!!!
    www.facebook.com/satish.rajdev

  10. #10
    Junior Member
    Discipline
    Structural
    Using
    AutoCAD 2017
    Join Date
    Jun 2018
    Posts
    17

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by satishrajdev View Post
    This code working fine at my end. Please check properly.

    I checked zilele's code also that also works fine. something is wrong are your end


    Well sathish I am sorry but its not working on my pc .. I tried many times... if you could help me on this ...

Similar Threads

  1. Convert to autolisp code
    By gS7 in forum AutoLISP, Visual LISP & DCL
    Replies: 11
    Last Post: 5th Feb 2013, 08:51 am
  2. Select one object/entity, gripped all same entity within the layer
    By Ahmeds in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 21st Nov 2012, 01:40 pm
  3. How to convert to G-code?
    By nainuad in forum AutoCAD 3D Modelling & Rendering
    Replies: 5
    Last Post: 6th Sep 2008, 03:53 am
  4. Replies: 1
    Last Post: 26th Jun 2008, 06:32 am
  5. How to convert the VBA code to VB?
    By fenny in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 26th Jan 2005, 08:41 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