Author Topic: Layers LISP routine  (Read 4252 times)

0 Members and 1 Guest are viewing this topic.

jrr114

  • Newt
  • Posts: 21
Layers LISP routine
« on: October 06, 2020, 04:51:31 PM »
I used a routine at a previous office that did what I am going to ask of the forum.  Below are samples of layers that I am using now.  The N = New, E = Existing and D = Demolition.  I want the ability to select multiple objects from N layers and switch to corresponding E layers, N and E to D.  I welcome any help that can be provided.

G-D-Case-Flor   G-E-Case-Flor    G-N-Case-Flor
G-D-Door         G-E-Door            G-N-Door
G-D-Wall-Full    G-E-Wall-Full      G-N-Wall-Full

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Layers LISP routine
« Reply #1 on: October 06, 2020, 05:09:40 PM »
Here's a quick one.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/)
  2.   (or *foodef* (setq *foodef* "D"))
  3.   (initget 0 "D E N")
  4.   (setq *foodef* (cond ((getkword (strcat "\n[Demo/Existing/New] <" *foodef* ">: ")))
  5.                        (*foodef*)
  6.                  )
  7.   )
  8.   (ssget (list (cons 8 (strcat "G-" *foodef* "*"))))
  9.   (princ)
  10. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jrr114

  • Newt
  • Posts: 21
Re: Layers LISP routine
« Reply #2 on: October 06, 2020, 05:26:56 PM »
Thanks.  I will try this first thing tomorrow morning.  I am amazed how fast you came up with this.  It's all Greek to me.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layers LISP routine
« Reply #3 on: October 06, 2020, 06:10:25 PM »
I am amazed how fast you came up with this.

Hardly surprising -> RJP is awesome. 👍

It's all geek to me.

FTFY
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Layers LISP routine
« Reply #4 on: October 06, 2020, 08:28:10 PM »
I dont use initget any more

Code: [Select]
(defun c:foo2 (/)
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not but)(setq but 1))
(setq *foodef* (ah:butts but "V"   '("Please choose  " "N" "E" "D")) )
    (ssget (list (cons 8 (strcat "G-" *foodef* "*"))))
  (princ)
)


« Last Edit: October 07, 2020, 07:25:45 PM by BIGAL »
A man who never made a mistake never made anything

jrr114

  • Newt
  • Posts: 21
Re: Layers LISP routine
« Reply #5 on: October 07, 2020, 08:54:05 AM »
Big Al,
I enter FOO2 as my command.  This is the message I get.


Command: FOO2
AHbutts : dialog     {
 label ="Please choose  " ;
 : row       {
 : boxed_radio_column   {
 width = 25 ;
 : radio_button  {
key = "Rb1";
label = "N";
 }
spacer_1 ;
 : radio_button  {
key = "Rb2";
label = "E";
 }
spacer_1 ;
 : radio_button  {
key = "Rb3";
label = "D";
 }
spacer_1 ;
 }
 }
spacer_1 ;
 ok_only;
 }
; error: bad argument type: streamp nil

jrr114

  • Newt
  • Posts: 21
Re: Layers LISP routine
« Reply #6 on: October 07, 2020, 08:57:10 AM »
ronjonp,

I enter FOO as my command.  I am able to select objects that are on a selected group of layers (E, D, or N).  I am unable to switch to the new status for these objects.

jrr114

  • Newt
  • Posts: 21
Re: Layers LISP routine
« Reply #7 on: October 07, 2020, 09:34:23 AM »
Hey Guys,

I did some digging and found the original.  I hope this might help you in converting it to the layer system I am currently using.  Thanks again for your help.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Layers LISP routine
« Reply #8 on: October 07, 2020, 10:46:40 AM »
I am amazed how fast you came up with this.

Hardly surprising -> RJP is awesome. 👍
..
Thanks Michael  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Layers LISP routine
« Reply #9 on: October 07, 2020, 11:11:08 AM »
ronjonp,

I enter FOO as my command.  I am able to select objects that are on a selected group of layers (E, D, or N).  I am unable to switch to the new status for these objects.
Give this a try. I consolidated all your options into one function.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ e nl s)
  2.   ;; RJP » 2020-10-07
  3.   (or *foodef* (setq *foodef* "DE"))
  4.   (initget 0 "DE DN ED EN NE ND")
  5.   (setq *foodef* (cond ((getkword (strcat "\nDE/DN/ED/EN/NE/ND]: <" *foodef* ">: ")))
  6.                        (*foodef*)
  7.                  )
  8.   )
  9.   (if (setq s (ssget ":L" (list (cons 8 (strcat "G-" (substr *foodef* 1 1) "*")))))
  10.     (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  11.       (setq nl (strcat "G-" (substr *foodef* 2) (substr (cdr (assoc 8 (entget e))) 4)))
  12.       (entmod (append (entget e) (list (cons 8 nl))))
  13.     )
  14.   )
  15.   (princ)
  16. )
« Last Edit: October 07, 2020, 11:15:10 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

jrr114

  • Newt
  • Posts: 21
Re: Layers LISP routine
« Reply #10 on: October 07, 2020, 01:41:09 PM »
RJP you are AWESOME!!!!!!!!!  Thank you so much!!  This is what I was looking for.  Stay well and stay safe.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Layers LISP routine
« Reply #11 on: October 07, 2020, 02:44:11 PM »
RJP you are AWESOME!!!!!!!!!  Thank you so much!!  This is what I was looking for.  Stay well and stay safe.
Glad to help  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Layers LISP routine
« Reply #12 on: October 07, 2020, 07:28:02 PM »
Please re download Multi Radio Buttons.lsp from above as I had made a change to it and forgot to change back, Cadtutor is nice as only 1 copy of code is saved on the site so up to date version.

Code: [Select]
this is correct writes a temporary dcl file.
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
;(setq fo (open (setq fname "D:\\acadtemp\\test.dcl") "w"))
A man who never made a mistake never made anything

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layers LISP routine
« Reply #13 on: October 08, 2020, 08:57:53 AM »
Thanks Michael  :-)

Just here reporting facts sir. :police:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Layers LISP routine
« Reply #14 on: October 08, 2020, 09:02:01 AM »
RJP you are AWESOME!!!!!!!!!

Fun fact: The swamp has 6110 registered members. RJP was the 5th, registering the same month the swamp was born, 17 years ago.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst