Visual LISP, AutoLISP and General Customization

Reply
Member
Posts: 5
Registered: ‎01-01-2014
Message 1 of 12 (338 Views)
Accepted Solution

New layer for selected objects

338 Views, 11 Replies
01-01-2014 10:00 AM

I need a LISP that create a new layer

and ask me for the name and the other properties (color,lw,lt..)

ask me if I want move the selected object for the new layer (yes is the default value)

 

thanks

Mentor
Posts: 1,682
Registered: ‎03-14-2004
Message 2 of 12 (315 Views)

Re: New layer for selected objects

01-01-2014 01:31 PM in reply to: majdov24

 Not as you ask, but it can serve you , use MAKE option at LAYER COMMAND 

 

(if (wcmatch (getvar 'locale) "en*" )


(alert " Design by Gabo CALOS DE VIT from CORDOBA ARGENTINA
\n Copyleft 1995-2013 by Gabriel Calos De Vit
DEVITG@GMAIL.COM
\n Put \n M2L \n at the command line")


(alert
" \n Hecho por Gabo CALOS DE VIT de CORDOBA ARGENTINA
\n Copyleft 1995-2013 por Gabriel Calos De Vit
\n DEVITG@GMAIL.COM
\n Poner \n M2L \n en la linea de comando")

)


(defun C:M2L ()
(command "._layer")
(while (> (getvar 'CmdActive) 0) (command pause))
(setq new-layer (getvar 'clayer))
(prompt (strcat"\n select the ent to move to layer < " new-layer " > " ))
(setq ent-to-move-ss (ssget))
(command "_chprop" ent-to-move-ss "" "la" new-layer "")

)

 

Member
Posts: 5
Registered: ‎01-01-2014
Message 3 of 12 (288 Views)

Re: New layer for selected objects

01-02-2014 12:55 AM in reply to: majdov24

is good but I want something like his

 

commande: m2nl
new layer name<layers1>
move selected to new layer? [Yes No] <yes> :

Mentor
Posts: 1,682
Registered: ‎03-14-2004
Message 4 of 12 (278 Views)

Re: New layer for selected objects

01-02-2014 02:19 AM in reply to: majdov24

It is as far as I can go .

Sorry.

 

*Expert Elite*
Kent1Cooper
Posts: 4,968
Registered: ‎09-13-2004
Message 5 of 12 (264 Views)

Re: New layer for selected objects

01-02-2014 07:29 AM in reply to: majdov24

majdov24 wrote:

I need a LISP that create a new layer

and ask me for the name and the other properties (color,lw,lt..)

ask me if I want move the selected object for the new layer (yes is the default value)

 

....

I want something like his

 

commande: m2nl
new layer name<layers1>
move selected to new layer? [Yes No] <yes>


Perhaps something like this?  It leaves you in the Layer command after asking for a new-Layer name, to assign any other property or properties you want, if any, so you need to tell it when you're done.  If you prefer, it could be altered to always ask for certain properties [e.g. color, linetype], but that would sometimes be asking questions you don't want to answer, when defaults are acceptable.

 

(defun C:MNLC ; = Make New Layer, Change pre-selected objects into it if desired
  (/ inc layname ss change)
  (setq
    inc 0; for default Layer name offering
    ss (ssget "_I"); pre-selected objects, if any
  ); setq
  (while (tblsearch "layer" (strcat "NewLayer" (itoa inc)))edit base string as desired
    (setq inc (1+ inc)); until it finds one not yet used
  ); while
  (setq layname (getstring (strcat "\nNew Layer name <" (strcat "NewLayer" (itoa inc)) ">: ")))
  (if (= layname "") (setq layname (strcat "NewLayer" (itoa inc)))); Enter for default
  (command "_.layer" "_make" layname)
  (while (> (getvar 'cmdactive) 0) (command pause)); allow color, linetype, etc., settings as desired
  (if ss ; were there any pre-selected objects?
    (progn ; then
      (sssetfirst nil ss); re-highlight
      (initget "Yes No")
      (setq change (getkword "\nMove selected objects to new Layer? [Y/N] <Y>: "))
      (sssetfirst nil); un-highlight
      (if (/= change "No") (command "_.chprop" ss "" "_layer" layname ""))
    ); progn
  ); if
  (princ)
); defun

 

It doesn't yet have any of the usual other controls, etc. [error handling, locked-Layer check, etc.], but see what you think.

Kent Cooper
Valued Mentor
gccdaemon
Posts: 444
Registered: ‎09-14-2010
Message 6 of 12 (257 Views)

Re: New layer for selected objects

01-02-2014 08:33 AM in reply to: Kent1Cooper

You might be able to make a more simple routine by using these 3 basic functions:

 

1. Create a selection set.

2. Create the layer using "-layer" (easier for single command string)

3. Use command copytolayer to move selection set. (built in error handling)

Andrew Ingram

Civil 3D x64 2012
Win 7 x64 Ultimate
I7 3820 (3.6ghz quad core with HT)
32gig RAM (Corsair XMS3 4x8g)
Intel x z79 mobo (BOXDX79TO 2011 socket)
Radeon HD 7850 2gb GDDR5
*Expert Elite*
Kent1Cooper
Posts: 4,968
Registered: ‎09-13-2004
Message 7 of 12 (248 Views)

Re: New layer for selected objects

01-02-2014 09:47 AM in reply to: gccdaemon

gccdaemon wrote:

You might be able to make a more simple routine by using these 3 basic functions:

 

1. Create a selection set.

2. Create the layer using "-layer" (easier for single command string)

3. Use command copytolayer to move selection set. (built in error handling)


1. Mine does create a selection set, and I don't see how it could do so any more simply.  The selection presumably already exists, if there is to be one, at least as I interpreted the wording of Messages 1 & 3.

 

2. If this is about using the hyphen, that is not needed in a (command "_.layer" ....) function, which works the command without the dialog box, without the need for the hyphen.  [When using (command), you don't need to suppress the dialog box, but rather need to force it if you want one -- see the (initdia) function.]

 

3. CopyToLayer doesn't move things to the designated Layer as they asked, but makes copies of them there, which means they're also left on their original Layer(s).  The OP would have to say whether that might be wanted, maybe as an option, but that's not what the original question asks for.

 

If I misunderstood any of your suggestions, a more detailed description would help.

Kent Cooper
Valued Mentor
gccdaemon
Posts: 444
Registered: ‎09-14-2010
Message 8 of 12 (236 Views)

Re: New layer for selected objects

01-02-2014 01:10 PM in reply to: Kent1Cooper

I must have had my head somewhere else, I not only did I misunderstand the original post, but I didn't correctly comprehend the script. I believe a "My Bad" is in order...lol.:smileyembarrassed:

Andrew Ingram

Civil 3D x64 2012
Win 7 x64 Ultimate
I7 3820 (3.6ghz quad core with HT)
32gig RAM (Corsair XMS3 4x8g)
Intel x z79 mobo (BOXDX79TO 2011 socket)
Radeon HD 7850 2gb GDDR5
*Expert Elite*
Posts: 2,369
Registered: ‎11-24-2009
Message 9 of 12 (215 Views)

Re: New layer for selected objects

01-02-2014 10:01 PM in reply to: Kent1Cooper

Kent1Cooper wrote:

majdov24 wrote:

I need a LISP that create a new layer

and ask me for the name and the other properties (color,lw,lt..)

ask me if I want move the selected object for the new layer (yes is the default value)

 

....

I want something like his

 

commande: m2nl
new layer name<layers1>
move selected to new layer? [Yes No] <yes>


Perhaps something like this?  It leaves you in the Layer command after asking for a new-Layer name, to assign any other property or properties you want, if any, so you need to tell it when you're done.  If you prefer, it could be altered to always ask for certain properties [e.g. color, linetype], but that would sometimes be asking questions you don't want to answer, when defaults are acceptable.

 

 ...... 

 


 

In addition to kents' code, to account for space <" "> and to catch invalid characters on the layer name 

 

(while (not (snvalid layname))
  (initget "Yes No")
  (setq	opt (getkword (strcat "\nInvalid name, use pre-set value? \""
			      (setq ln (strcat "NewLayer" (itoa inc)))
			      "\" [Y/N] <Y>: "
		      )
	    )
  )
  (setq	layname	(if (/= opt "No")
		  ln
		  layname
		)
  )
)
(command "_.-layer" "_make" (princ layname))

 

HTH

Member
Posts: 5
Registered: ‎01-01-2014
Message 10 of 12 (195 Views)

Re: New layer for selected objects

01-03-2014 01:28 AM in reply to: Kent1Cooper
Perfect! Thank you so much for the massive effort. This is fantastic

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community