Jump to content

LISP to swap layers between objects


Caracolalbino
 Share

Recommended Posts

Hi, I'm kind of new to the forum, and I was looking for a routine that allows me to select one object and swap its layer with another objects' current one. Is it something that has been done? So far, I haven't found any built-in commands that do this, but I just might haven't searched thoroughly enough. Anyhow, thanks in advance!

Link to comment
Share on other sites

Its easy enough to do but are we talking about one layer or multiple layers? if its multiple layers what layer goes where?

Sorry you said object I was thinking blocks.

;;----------------------------------------------------------------------------;;
;; SWITCH LAYERS BETWEEN OBJECTS
(defun C:SwapLayer (/ OA OB LA LB)
  (setq OA (car (entsel "\nSelect first object: "))
        LA (cdr  (assoc 8 (setq OA (entget OA))))
        OB (car (entsel "\nSelect second object: "))
        LB (cdr  (assoc 8 (setq OB (entget OB))))
  )
  (if (eq LA LB)
    (prompt "\nBoth Entities are on same layer")
    (progn
      (entmod (subst (cons 8 LB) (assoc 8 OA) OA))
      (entmod (subst (cons 8 LA) (assoc 8 OB) OB))
    )
  )
  (princ)
)

 

Edited by mhupp
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Wonderful, works like a charm! I really need to learn how to write lisp routines, what would you say would be the best way for someone to get started on the language/syntax?

  • Like 1
Link to comment
Share on other sites

18 minutes ago, Caracolalbino said:

Wonderful, works like a charm! I really need to learn how to write lisp routines, what would you say would be the best way for someone to get started on the language/syntax?

 

https://www.afralisp.net/ is nice with simple step by step instructions.

https://www.cadtutor.net/tutorials/autolisp/quick-start.php  also good start but one page.

 

Coming to the forums regularly to see how people problem solve.

look for answer from people with high scores. there are multiple ways to code things in lisp. usually it comes down to performance (what runs the fastest)

but depending on user preference or other factors one type of code might win out over a faster code.

 

Reading over the functions to understand how to use them.

https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-4CEE5072-8817-4920-8A2D-7060F5E16547

 

Welcome and hope to see you around.

 

 

  • Like 4
Link to comment
Share on other sites

Get a copy of Notepad++ a text editor has functions built in that helps when writing lisp's. A lot of us use it.

 

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...