Hi!
I 've found a lisp it turns 2 layers: layer1 and layer2 (with toggle) on or off.
Now I want instead off layers on-off it must toggle thaw-freeze.
I thought "on"must be "thaw" and "off" must be "freeze".
But that does'nt work.
can you help me?
gr. László
on and off:->
(defun c:layertoggle ()
(if (setq flag (tblsearch "LAYER" "Layer1" ""))
(command "-layer" (if (minusp (cdr (assoc 62 flag))) "on" "off") "Layer1" ""))
(if (setq flag (tblsearch "LAYER" "Layer2" ""))
(command "-layer" (if (minusp (cdr (assoc 62 flag))) "on" "off") "Layer2" ""))
(princ)
)
@Anonymous wrote:Hi!
I 've found a lisp it turns 2 layers: layer1 and layer2 (with toggle) on or off.
Now I want instead off layers on-off it must toggle thaw-freeze.
I thought "on"must be "thaw" and "off" must be "freeze".
But that does'nt work.
....
(command "-layer" (if (minusp (cdr (assoc 62 flag))) "on" "off") "Layer1" ""))
....
Yes, you can change "on" to "thaw" and "off" to "freeze", but you also need to change what it tests for. When a Layer is off, its color number [the 62 code entry] is negative. When it's frozen, it's the 70 code entry that holds that information -- it contains a 1 bit. It won't necessarily be just 1, because the 70 code also includes a 4 bit if the Layer is locked, and may cover some other conditions, too. So you need to check for the 1 bit regardless of whatever other bits may be included. The way to do that is with (logand):
....
(command "-layer" (if (= (logand (cdr (assoc 70 flag)) 1) 1) "thaw" "freeze") "Layer[X]" ""))
....
But there's another way to do this, that doesn't even need to bother checking whether the Layer is frozen or not -- it will freeze it if it's thawed and thaw it if it's frozen, with the same operation, using not (if) but the mysterious yet very powerful (boole) function:
(setq
laydata (entget (tblobjname "layer" "YourLayerName"))
laydata
(subst
(cons 70 (boole 6 (cdr (assoc 70 laydata)) 1))
(assoc 70 laydata)
laydata
); end subst
); end setq
(entmod laydata)
Autocad says: ; error: malformed list on input.
where does it go wrong?
My code:
(defun c:layertogle ()
((setq Laydata (entget (tblobjname "layer" "Layer1"))
laydata
(subst
(cons 70 (boole 6 (cdr (assoc 70 laydata)) 1))
(assoc 70 laydata)
laydata
); end subst
); end setq
(entmod laydata)
(princ)
)
Another question:
Is there a reference manual where I can find codes like: 62 en 70?
@Anonymous wrote:Autocad says: ; error: malformed list on input.
where does it go wrong?
My code:
(defun c:layertogle ()
((setq Laydata (entget (tblobjname "layer" "Layer1"))....
Another question:
Is there a reference manual where I can find codes like: 62 en 70?
There's an extra left parenthesis before the setq function name. Change ((setq... to (setq....
Search the Discussion Group for things like DXF Reference, or association list codes, to find a lot of leads to sources of information about what the different entries mean.
Now its'working thank you!
(defun c:layertogle ()
(setq Laydata (entget (tblobjname "layer" "Layer1"))
laydata
(subst
(cons 70 (boole 6 (cdr (assoc 70 laydata)) 1))
(assoc 70 laydata)
laydata
); end subst
); end setq
(entmod laydata)
(princ)
)
And for both layers?
For Layer2. Can I type: (setq Laydata (entget (tblobjname "layer" "Layer1" "layer2")) or something??
@Anonymous wrote:Now its'working thank you!
....
And for both layers?
For Layer2. Can I type: (setq Laydata (entget (tblobjname "layer" "Layer1" "layer2")) or something??
No -- you don't want to set two Layers' worth of information into one variable, even if (tblobjname) would accept two Layer names [which it won't], because the remainder of the routine will only "find" the first 70-code entry, and (entmod) couldn't change both Layers from one list, anyway.
Personally, I would do two Layers by having a generic sub-routine [and that layertogle name is already appropriately generic], and then calling it up for both Layers via a command that uses that sub-routine for each Layer name, this way [untested]:
(defun layertoggle (layname / laydata); <-- note no C:, and a pre-slash argument
(setq
laydata (entget (tblobjname "layer" layname))
laydata
(subst
(cons 70 (boole 6 (cdr (assoc 70 laydata)) 1))
(assoc 70 laydata)
laydata
); end subst & 2nd laydata
); end setq
(entmod laydata)
); end defun - layertoggle
(defun C:LayerToggle-1-2 ()
(layertoggle "Layer1"); feeds Layer name as argument to sub-routine, to be used where layname occurs
(layertoggle "Layer2")
); end defun
Thank you,
But it doesnt work when I typ in the autocad prompt the command:
layertoggle or layertoggle1-2.
I'm trying to learn autolisp and visualisp. What is the fasted way to learn it?
gr. László