Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Object Layers

  1. #1
    Member
    Join Date
    2017-06
    Posts
    3
    Login to Give a bone
    0

    Default Object Layers

    Hello.
    I need help with a lisp to select objects (text, multilines, lines, polylines, etc.) From various layers and move them to other defined layers within a drawing.
    E.g.
    UG_CONDUIT_NEW to UG_CONDUIT_EXIST
    UG_HV_NEW to UG_HV_EXIST
    TEXT_2.5_NEW to TEXT_2.5_EXIST
    UG_LV_NEW to UG_LV_EXIST
    UG_PL_NEW to UG_PL_EXIST
    UG_LVS_NEW to UG_LVS_EXIST
    ASSETS_NEW to ASSETS_EXIST
    I only want one selection set but includes the 7 layers with one execution.

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Object Layers

    Quote Originally Posted by thaberries752224 View Post
    I only want one selection set but includes the 7 layers with one execution.
    Hi,

    This is an example for you to get started.


    Code:
    (setq ss (ssget "_:L" '((0 . "LINE,MTEXT,ARC") ;; Name of objects that you'd like to select.
                            (8 . "Layer1,Layer2")  ;; Replace current example with your Layer names.
                            )
                    )
          )

  3. #3
    I could stop if I wanted to
    Join Date
    2005-06
    Location
    CORDOBA-ARGENTINA
    Posts
    275
    Login to Give a bone
    0

    Default Re: Object Layers

    Please upload a sample DWG , in ACAD 2007 or less.

  4. #4
    Member
    Join Date
    2017-06
    Posts
    3
    Login to Give a bone
    0

    Default Re: Object Layers

    Thankyou for the responses.

    Please see attached file Object Layers.dwg (2007).

    I have copied the section of civil works so that it shows the initial drawing and then the end result (layer changes from NEW to EXIST).

    Object Layers.dwg

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Object Layers

    OK here is one way to do it.

    I used the command pipe to decrease the number of library functions.

    For my own code I would use a ActiveX based solution.

    I like the function SelectionSetToList because LISP selection sets are a pain.

    Lists of objects are much easier to manipulate using mapcar.

    P=

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Written By: Peter Jamtgaard copyright 2017 All Rights Reserved
    ;___________________________________________________________________________________________________________|
    ;
    ; Any use by unauthorized person or business is strictly prohibited.
    ;___________________________________________________________________________________________________________|
    ;
    ; Abstract: This routine will create various existing layers and transfer objects from the new version of the layer the the exist.
    ;___________________________________________________________________________________________________________|
    ;
    ; Command Line Function Header List
    ;___________________________________________________________________________________________________________|
    
    ;  Function and Description
    
    ;* C:ToExisting
    ;* Command line Function to transfer objects on a new layer to an existing layer
    
    ;* C:ToX 
    ;* Command line Function to transfer objects on a new layer to an existing layer
     
    ;___________________________________________________________________________________________________________|
    ;
    ; General Function Header List 
    ;___________________________________________________________________________________________________________|
    
    ;  Function, Arguments and Description
    
    ;* (SelectionSetToList ssSelections)
    ;* Function to convert a lisp selectionset to a list of objects
    
    ;$ End Header
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Command line Function to transfer objects on a new layer to an existing layer
    ;___________________________________________________________________________________________________________|
    
    (defun C:ToX ()(C:ToExisting))
    
    (defun C:ToExisting (/ lstSublist)
     (vl-cmdf "layer" "u" "*" "")
     (foreach lstSublist (list (list "UG_CONDUIT_NEW" "UG_CONDUIT_EXIST")
                               (list "UG_HV_NEW"      "UG_HV_EXIST")
                               (list "TEXT_2.5_NEW"   "TEXT_2.5_EXIST")
                               (list "UG_LV_NEW"      "UG_LV_EXIST")
                               (list "UG_PL_NEW"      "UG_PL_EXIST")
                               (list "UG_LVS_NEW"     "UG_LVS_EXIST")
                               (list "ASSETS_NEW"     "ASSETS_EXIST")
                         )
      (if (and (vl-cmdf "layer" "m" (cadr lstSublist) "")
               (setq ssSelections (ssget (list (cons 8 (car lstSublist))))); <- revised to allow for selecting items
               (setq lstSelections (SelectionSetToList ssSelections))
          )
       (mapcar '(lambda (X)(vla-put-layer X (cadr lstSublist))) lstSelections)
      )  
     ) 
    )
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to convert a lisp selectionset to a list of objects
    ;___________________________________________________________________________________________________________|
    
    (defun SelectionSetToList (ssSelections / entSelection intCount lstObjects objSelection )
     (repeat (setq intCount (sslength ssSelections))
      (and
       (setq intCount (1- intCount))
       (setq entSelection (ssname ssSelections intCount))
       (setq objSelection (vlax-ename->vla-object entSelection))
       (setq lstObjects   (cons objSelection lstObjects))
      )
     )
     lstObjects
    )
    
    (princ "!")
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2017-07-02 at 01:46 AM.
    AutomateCAD

  6. #6
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Object Layers

    Quote Originally Posted by peter View Post
    OK here is one way to do it.

    I used the command pipe to decrease the number of library functions.

    For my own code I would use a ActiveX based solution.

    I like the function SelectionSetToList because LISP selection sets are a pain.

    Lists of objects are much easier to manipulate using mapcar.

    Code:
    (mapcar '(lambda (X)(vla-put-layer X (cadr lstSublist))) lstSelections)
    You make this look too easy, I've put SelectionSetToList in my library.
    Good reference for mapcar & lambda peter used in line 52 above: http://www.afralisp.net/autolisp/tut...and-lambda.php
    Using your SelectionSetToList function I'll be using mapcar & lambda a lot more in the future.

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Object Layers

    Hi,

    Here you go.


    Code:
    (defun c:Test (/ *error* lst doc lck sel ent get)
      ;;------------------------------------;;
      ;; Author: Tharwat - Date: 30.Jun.2017;;
      ;; Move objects from layer to another	;;
      ;; as indicated in the 'lst' variable.;;
      ;;					;;
      ;;------------------------------------;;
      (defun *error* (msg)
        (and doc (vla-endundomark doc))
        (if lck (mapcar '(lambda (u) (vla-put-lock u :vlax-true)) lck))
        (and msg (not (wcmatch (strcase msg) "*CANCEL*,*EXIT*,*BREAK*"))
          (princ (strcat "\nError =>: " msg))
        )
        (princ)
      )
      ;;				;;
      (setq lst '(("UG_CONDUIT_NEW" "UG_CONDUIT_EXIST")
                  ("UG_HV_NEW" "UG_HV_EXIST")
                  ("TEXT_2.5_NEW" "TEXT_2.5_EXIST")
                  ("UG_LV_NEW" "UG_LV_EXIST")
                  ("UG_PL_NEW" "UG_PL_EXIST")
                  ("UG_LVS_NEW" "UG_LVS_EXIST")
                  ("ASSETS_NEW" "ASSETS_EXIST")
                 )
            doc (vla-get-activedocument (vlax-get-acad-object))
      )
      (vlax-for layer (vla-get-layers doc)
        (if (eq :vlax-true (vla-get-lock layer))
          (vla-put-lock (car (setq lck (cons layer lck))) :vlax-false)
        )
      )
      ;;				;;
      (vla-endundomark doc)
      (vla-startundomark doc)
      (if (setq sel (ssget "_X" (list (cons 8 (apply 'strcat
                                                     (mapcar (function (lambda (x) (strcat x ",")))
                                                             (mapcar 'car lst)
                                                             )
                                                     )
                                            )
                                      )
                           )
                )
        (while (setq ent (ssname sel 0))
          (entmod (subst
                     (cons 8 (cadr (assoc (cdr (assoc 8 (setq get (entget ent)))) lst)))
                     (assoc 8 get)
                     get
                     )
          )
          (ssdel ent sel)
        )
      )
      (*error* nil)
      (princ)
    ) (vl-load-com)

  8. #8
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Object Layers

    You make this look too easy, I've put SelectionSetToList in my library.
    Good reference for mapcar & lambda peter used in line 52 above: http://www.afralisp.net/autolisp/tut...and-lambda.php
    Using your SelectionSetToList function I'll be using mapcar & lambda a lot more in the future.
    Programming LISP is easy...

    If everyone follows my AutoLISP 101 they should be able to code just as elegantly.

    Later in the course I want to present my toobject and toobjects expressions which transform just about everything into objects and lists of objects.

    P=
    AutomateCAD

  9. #9
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    0

    Default Re: Object Layers

    We use the same thing but a step further with setting layer and linetypes I have a text file with around 150 names in it layold laynew colour linetype. makes setting company standards much easier and we have some dwgs that must match state authority setting so can change colours etc very easy.

  10. #10
    Member
    Join Date
    2017-06
    Posts
    3
    Login to Give a bone
    0

    Default Re: Object Layers

    Tharwat, this works well however, I want to be able to select the objects.

    In the drawing provided not all items change to EXIST (see top and then bottom drawing) yes, some items change but not all so I want a selection box so that the items I wish to stay as NEW can remain and the items/objects I wish to change can be selected. Does that make sense?

Page 1 of 2 12 LastLast

Similar Threads

  1. 2015: Object Layers - How to utilized to the fullest?
    By Iceberg in forum Civil 3D Styles Library
    Replies: 1
    Last Post: 2014-05-22, 06:19 PM
  2. Access Object Sub-entity Layers via the API
    By civil3d.wishlist1941 in forum Civil 3D Wish List
    Replies: 1
    Last Post: 2009-07-24, 06:57 PM
  3. Pasted object come in on Bound layers
    By cadconcepts in forum AutoCAD Customization
    Replies: 1
    Last Post: 2009-02-25, 03:45 PM
  4. Select object on layers with certain linetype
    By bsanada in forum AutoLISP
    Replies: 1
    Last Post: 2007-12-20, 12:14 AM
  5. Flatshot to Maintain Object Layers
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-06-20, 11:50 AM

Posting Permissions

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