TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: memerson on April 29, 2010, 07:27:00 PM
-
Hi from a Lisp newbie. I have written the following routine to change to target layer "PL1" using the chprop command.
I would like to be able to choose the target layer (from a list of existing layers) from within the routine. If the drawing contains layers PL1, PL2, PL3 etc. how can I choose the target layer, instead of defining a single layer. I guess it will involve some "if" or "while" or "cond" statements?
; Changes selected objects to Layer PL1
(defun c:setpl1 ()
(command "_.chprop"
(ssget ) "" "LA" "PL1" "")
)
Thanks
-
Perhaps look into the getstring function to prompt the user for a layer, or maybe getkword if you want to restrict the user to a selection to choose from. :-)
-
You'll need initget also, if you go the getkword route.
-
Thanks guys - I can see that way forward.
However I was wondering if I could include a list of target layers to choose from, within the Lisp routine?
Thanks again.
Mike
-
Taking it slowly, perhaps this is the next stepping stone :-)
(defun c:test ( / layers layer ss )
(setq layers '("L1" "L2" "L3" "L4"))
(initget 1 "L1 L2 L3 L4")
(setq layer (getkword "\nChoose Target Layer [L1/L2/L3/L4] : "))
(setq layer (car (member layer layers)))
(if (setq ss (ssget "_:L"))
(command "_.chprop" ss "" "_LA" layer ""))
(princ))
Note that it doesn't check if the chosen layer exists.
-
Why not allow the user to pick an entity on that layer instead of typing?
(defun c:foo (/ layer ss)
(setq layer(cdr (assoc 8 (entget(car (entsel "\n Pick New Current Layer: "))))))
(if (setq ss (ssget "_:L"))
(command "_.chprop" ss "" "_LA" layer "")
)(princ)
)
-
I knew I had one of these somewhere :wink:
;;; ------------------------------------------------------------------------
;;; LAYER_MPL.LSP Version 1.1
;;;
;;; Copyright© NOVEMBER, 2001
;;; Timothy G. Spangler
;;;
;;; Permission to use, copy, modify, and distribute this software
;;; for any purpose and without fee is hereby granted, provided
;;; that the above copyright notice appears in all copies and
;;; that both that copyright notice and the limited warranty and
;;; restricted rights notice below appear in all supporting
;;; documentation.
;;;
;;; Moves Selected Entity(s) to picked Layer
;;;
;;; ------------------------------------------------------------------------
(defun c:MPL (/ Clayer OldCmdEcho SS Counter EntList)
(setq OldCmdEcho (getvar "cmdecho"))
(setvar "cmdecho" 0)
(prompt "\nSelect entities to change...\n")
(setq SS (ssget))
(prompt "\nSelect object on destination layer: ")
(setq Clayer (cdr (assoc 8 (entget (car (entsel))))))
(setq Counter (- (sslength SS) 1 ))
(while (/= Counter -1)
(setq EntList (entget (ssname SS Counter)))
(setq EntList (subst (cons 8 Clayer)(assoc 8 EntList) EntList))
(entmod EntList)
(setq Counter (1- Counter))
)
(setvar "cmdecho" OldCmdEcho)
(princ)
)
;;;
;;; Echos to the command line
(princ "\nMoves Selected Entity(s) to picked Layer v1.1© \n Timothy Spangler, \n November, 2009....loaded.")
(terpri)
(princ "C:MPL")
(print)
;;; End echo
-
Why not allow the user to pick an entity on that layer instead of typing?
(defun c:foo (/ layer ss)
(setq layer(cdr (assoc 8 (entget(car (entsel "\n Pick New Current Layer: "))))))
(if (setq ss (ssget "_:L"))
(command "_.chprop" ss "" "_LA" layer "")
)(princ)
)
Just so you know, LayMch will do the same thing. :-)
-
I would recommend the CHPROP approach due to the fact that if you (entmod) just the header of a POLYLINE it doesn't change the sequential vertices. My $0.02 -David
-
I would recommend the CHPROP approach due to the fact that if you (entmod) just the header of a POLYLINE it doesn't change the sequential vertices. My $0.02 -David
just a second. does this mean a "real" polyline can have multiple layers?
-
just a second. does this mean a "real" polyline can have multiple layers?
Unfortunately, 'Yes, it can'. After (entmod )the polyline header, try a CHPROP LAyer on the entity. ACAD will respond with <varies> as to the current layer status. I've done it on purpose at times for PFACE meshes but I would not recommend it as a good habit. You can also assign different colors, ltypes etc to vertices. -David
-
just a second. does this mean a "real" polyline can have multiple layers?
Unfortunately, 'Yes, it can'. After (entmod )the polyline header, try a CHPROP LAyer on the entity. ACAD will respond with <varies> as to the current layer status. I've done it on purpose at times for PFACE meshes but I would not recommend it as a good habit. You can also assign different colors, ltypes etc to vertices. -David
Wild, I had no idea. I guess it's kind of like being able to freeze the current layer with entmod.
-
Why not allow the user to pick an entity on that layer instead of typing?
...
What if the layer doesn't exist ?? Another words, the user wants to add a block to a layer that is not yet there. I've run into this quite a few times when editing an existing drawing.
Here's what I currently have for allowing the user to choose a layer:
...
(setq LayrSel (strcase (getkword "\nType in the layer you want to make current: (<?> for list of layers) ")))
(if (/= LayrSel "?")
(setq LayrRep 1)
)
(if (= LayrSel "?")
(progn
(textscr)
(prompt "\n\n*Layers not currently in the drawing will be created*\n")
(prompt "\n**CAUTION** If layer exists but has different settings,")
(prompt "\n this command will not override the existing layer.\n")
(prompt "\nIf selected layer is currently in the drawing,")
(prompt "\nit will be thawed, turned on, & set as current.\n")
(prompt "\nTyping <*> will create all the listed layers.\n\n")
(prompt "\nLayers and their abbreviations: ")
(prompt "
0 = 0 or Z ELC Text = ET
PIP Text = PT CIV Text = CT")
(prompt "
Defpoints = DF Revision = REV
Viewports = V XRef-Flatshot = XF
XRefs = XR\n")
);end progn
);end if
...
Notice, I didn't put the INITGET in there, it's better you read up on it from the Help file.
Just so you know, LayMch will do the same thing.
LayMch --> Changes the layer of a selected object to match the destination layer.
LayCur --> Changes the layer property of selected objects to the current layer.
LayMCur --> Sets the current layer to that of a selected object.
There's too much to remember.
-
Why not allow the user to pick an entity on that layer instead of typing?
...
What if the layer doesn't exist ?? Another words, the user wants to add a block to a layer that is not yet there. I've run into this quite a few times when editing an existing drawing.
< ... >
There's too much to remember.
In that case, just use the built-in LAYMCH command ... no headaches !!!
-
Not trying to spoil the fun, but, perhaps the OP was using this as more of a learning example, perhaps not so much for a practical purpose? I could be wrong of course. :-)
-
perhaps, but I wasn't responding to the OP. :|
it was related to the statement that 'There's too much to remember'
-
No worries :-)
-
Thanks Guys - I now have a routine that does what is required!
Your help is/was appreciated.
One day I wonder if it might be upgraded to a dialogue box where I can click on a Layer Name drop down list???
But I'm just getting greedy. It aint broke, so . . .
Thanks again - you guys ROCK! :mrgreen:
-
DosLib has a few list box options. Could fill in the gaps while you're starting out.
-
Why not allow the user to pick an entity on that layer instead of typing?
...
What if the layer doesn't exist ?? Another words, the user wants to add a block to a layer that is not yet there. I've run into this quite a few times when editing an existing drawing.
< ... >
There's too much to remember.
In that case, just use the built-in LAYMCH command ... no headaches !!!
Now see Kerry, there's one more thing to remember danged'it all !! :-D
-
Hey guys,
I'm all new to lisp commands but really need a favor
I'm using layer translator to convert all layers conaining
"*DIM" to layer 0"
"*BAS" to layer "basewall"
"*EQP" to layer "equipment"
etc. etc. etc.
is it possible to create a lisp, because i have over 100 drawings to do....
i don't won't to open laytr every time and type all the "*xxx" and select the new layer from my .dws file...
every drawing has different layer names but the layers contain the letters "*DIM" /*BAS" "*XXX"
thanks for help in advance!!!
-
I would consider this lisp/script generator..
http://www.lee-mac.com/scriptwriter.html