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

Thread: Lisp to swap value of layer name and layer description

  1. #1
    100 Club
    Join Date
    2015-09
    Posts
    154
    Login to Give a bone
    0

    Default Lisp to swap value of layer name and layer description

    Hi,
    I am working in an international firm, we have a layer structure where the layer name is in the local language and the layer description is the layer name in english.

    Does anyone know of a routine that would allow a user to swap these values?

    ie.

    Layer Name Layer Description
    Schraffur Hatch

    run code

    result

    Layer Name Layer Description
    Hatch Schraffur

    I know the layer translator exists but this would probably suit our needs better.

    Thanks.

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    Only little problem was layer "0", so I skipped that...

    Code:
    (defun c:swaplayn-layd ( / adoc laycoll layn layd)
    (vl-load-com)
    (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
    (setq laycoll (vla-get-layers adoc))
    (vlax-for lay laycoll
     (setq layn (vla-get-Name lay))
     (setq layd (vla-get-Description lay))
     (if (/= layn "0") 
      (progn
      (vla-put-Name lay layd)
      (vla-put-Description lay layn)
      )
     )
    )
    (princ)
    )
    M.R.
    Last edited by marko_ribar; 2011-06-28 at 09:48 AM. Reason: forgot to localize variables...

  3. #3
    100 Club
    Join Date
    2015-09
    Posts
    154
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    Hi Mark,

    Thanks for the quick response

    Civil 3d 2010 is returning the following on the command line after running the command.

    ; Fehler: Automatisierungsfehler Ungültige Eingabe

    Translation is

    ;Error: Automation error Invalid input

    any ideas?

    I thought it might be due to the defpoints layer so I added that to the code by copying what you had for layer 0 and replacing 0 with defpoints but the command returns the same as above


    I saw that you updated the code but unfortunately it is still returning the same error message
    Last edited by feargt; 2011-06-28 at 10:22 AM. Reason: used updated code

  4. #4
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    This isn't an ideal way to approach it (I call it 'lazy-man's error trapping') but it should swap the name/description for the layer if possible, else it will skip the layer.

    Code:
    (defun c:test nil (vl-load-com)
      (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (vl-catch-all-apply
          (function
            (lambda ( / ln ld )
              (setq ln (vla-get-name layer)
                    ld (vla-get-description layer)
              )
              (vla-put-description layer ln)
              (vla-put-name layer ld)
            )
          )
        )
      )
      (princ)
    )
    Last edited by Lee Mac; 2011-06-28 at 03:01 PM. Reason: Added 'layer' variable - thanks Marko

  5. #5
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    try with

    Code:
    (if (or (/= layn "0") (/= layn "Defpoints"))
    but I think it won't help... Error is due to Civil 3d you are using... In Acad 2011 it works...
    M.R.

    Lee, seeing your code looks fine to me, but haven't you forgot :
    Code:
    (vla-put-name layer ld)
    Last edited by marko_ribar; 2011-06-28 at 10:48 AM. Reason: revision of Lee code

  6. #6
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    Quote Originally Posted by marko_ribar View Post
    try with

    Code:
    (if (or (/= layn "0") (/= layn "Defpoints"))
    but I think it won't help... Error is due to Civil 3d you are using... In Acad 2011 it works...
    M.R.
    My guess is there are also invalid characters in the description string.

  7. #7
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    Quote Originally Posted by Lee Mac View Post
    This isn't an ideal way to approach it (I call it 'lazy-man's error trapping') but it should swap the name/description for the layer if possible, else it will skip the layer.
    Probably not ideal either, but removes the usage of vl-catch* and checks validity of a swap...

    Code:
    (defun c:test (/ desc)
      (vl-load-com)
      (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (if (and (snvalid (setq desc (vla-get-description layer)))
                 (not (tblobjname "LAYER" desc))
            )
          (progn (vla-put-description layer (vla-get-name layer))
                 (vla-put-name layer desc)
          )
        )
      )
      (princ)
    )
    I'd probably take your route since it's most like the faster one, but I don't know. I do know that tblobjname has proven to be faster than tblsearch.
    Last edited by alanjt; 2011-06-28 at 03:09 PM.

  8. #8
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    Little mistake Alan...

    Code:
    (defun c:test (/ desc)
      (vl-load-com)
      (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (if (and (snvalid (setq desc (vla-get-description layer)))
                 (not (tblobjname "LAYER" desc))
            )
          (progn (vla-put-description layer (vla-get-name layer))
                 (vla-put-name layer desc)
          )
        )
      )
      (princ)
    )
    M.R.

  9. #9
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    Quote Originally Posted by marko_ribar View Post
    Little mistake Alan...

    Code:
    (defun c:test (/ desc)
      (vl-load-com)
      (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        (if (and (snvalid (setq desc (vla-get-description layer)))
                 (not (tblobjname "LAYER" desc))
            )
          (progn (vla-put-description layer (vla-get-name layer))
                 (vla-put-name layer desc)
          )
        )
      )
      (princ)
    )
    M.R.
    Oops. Thanky, thanky.

  10. #10
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Lisp to swap value of layer name and layer description

    Quote Originally Posted by marko_ribar View Post
    Lee, seeing your code looks fine to me, but haven't you forgot :
    Code:
    (vla-put-name layer ld)
    Thanks Marko - corrected above

    Quote Originally Posted by alanjt View Post
    I'd probably take your route since it's most like the faster one, but I don't know. I do know that tblobjname has proven to be faster than tblsearch.
    Also, entmod'ing the tblobjname entity will return nil if invalid and won't throw the error. But then modifying the Description could be annoying since its deep in the xData

Page 1 of 2 12 LastLast

Similar Threads

  1. Rename Layer based on Layer Description
    By David Prontnicki in forum AutoLISP
    Replies: 1
    Last Post: 2014-12-05, 08:15 PM
  2. LISP to create layer, hatch and set layer back to original.
    By jpcadconsulting347236 in forum AutoLISP
    Replies: 1
    Last Post: 2013-12-11, 07:22 PM
  3. Replies: 8
    Last Post: 2007-05-16, 01:29 AM
  4. Replies: 4
    Last Post: 2006-09-28, 07:25 PM
  5. Swap Layer settings via a button
    By davidbassford in forum AutoCAD Customization
    Replies: 3
    Last Post: 2006-05-09, 01:39 PM

Posting Permissions

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