need help shortening my '
(defun c:test ( / LayerLocked LayerFrozen)(vl-load-com) (setq acadObject (vlax-get-acad-object) acadActiveDocument (vla-get-ActiveDocument acadObject) );;;Modify Layer Properties (setq acadLayers (vla-get-Layers acadActiveDocument) ) (vlax-for eachLayer acadLayers (if (= (vla-get-Lock eachLayer) :vlax-true) (progn (setq LayerLocked (cons eachLayer LayerLocked)) (vla-put-Lock eachLayer :vlax-false) ) ) ) (vlax-for eachLayer acadLayers (if (= (vla-get-Freeze eachLayer) :vlax-true) (progn(setq LayerFrozen (cons eachLayer LayerFrozen))(vla-put-Freeze eachLayer :vlax-false) ) ) );;;Restore Layers(foreach eachLayer LayerLocked(vla-put-Lock eachLayer :vlax-true))(foreach eachLayer LayerFrozen(vla-put-Freeze eachLayer :vlax-true))(princ))I need help figuring out how to combine two (vlax-for)
and
the last two (foreach) statments.
I have tried (and), (and or) (progn) and every combination until I am so darn confused I can't think straight.
No matter my combination it wants to juggle the results.
Breaking it down separatly as above works fine but I want to learn how to combine these (for) statements.
Thanks for any advise Hint: You can iterate through the layer collection once by placing both of your conditions in one vlax-for statement.
Also, look at replacing if/progn with and.
As for combining your foreach statements, why not use a mapcar statement? Hi jvill
yes, I am wanting to place both of my conditions into one vlax-for statement but when I do, I lose control of my layers.
If I replace the if/progn with and
will this not be looking for both conditions, frozen and locked on one layer?
My layers can be a combination of:
both thawed and unlocked
one thawed and one locked
one unlocked and one frozen
etc...(any combination)
If I just use (and) doesn't this mean that the layer has to be both locked and frozen? Keep the conditions separated under the same vlax-for statement.
Example:
(and(this is true)(do this)(do this too))(and(this is true)(do this)(do this too)) When you wanna compare your solution, scroll down:(vlax-for eachLayer acadLayers(and (= (vla-get-Lock eachLayer) :vlax-true) (setq LayerLocked (cons eachLayer LayerLocked)) (vla-put-Lock eachLayer :vlax-false) )(and (= (vla-get-Freeze eachLayer) :vlax-true) (setq LayerFrozen (cons eachLayer LayerFrozen)) (vla-put-Freeze eachLayer :vlax-false) ));;;and the mapcar solution:(mapcar(function (lambda (locked frozen) (vla-put-lock locked :vlax-true)(vla-put-freeze frozen :vlax-true)))LayerLocked LayerFrozen) jvill
I can't thank you enough for the method you use in helping me.(I come here looking for hints and techniques, not quick easy answers)but sometimes seeing my failed code written correctly after hours of playing with it really helps.
I nailed the (vlax-for) (and) (and)...but not without your hit in your second post
I failed at getting the mapcar to work...I couldn't figure out the lambda function by the example in help, with what I was trying to do,,,(I couldn't connect the dots)
Here is my failed attempt just to show I was getting close
(defun c:test ( / LayerLocked LayerFrozen)(vl-load-com) (setq acadObject (vlax-get-acad-object) acadActiveDocument (vla-get-ActiveDocument acadObject) );;;Modify Layer Properties (setq acadLayers (vla-get-Layers acadActiveDocument) ) (vlax-for eachLayer acadLayers (and (= (vla-get-Lock eachLayer) :vlax-true) (setq LayerLocked (cons eachLayer LayerLocked)) (vla-put-Lock eachLayer :vlax-false) ) (and (= (vla-get-Freeze eachLayer) :vlax-true) (setq LayerFrozen (cons eachLayer LayerFrozen)) (vla-put-Freeze eachLayer :vlax-false) ));;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Restore Layers ;(mapcar ;'(lambda ()(foreach eachLayer LayerLocked (vla-put-Lock eachLayer :vlax-true)(foreach eachLayer LayerFrozen (vla-put-Freeze eachLayer :vlax-true) )) (princ))
as you can see I gave up on the mapcar and lambda and just used two foreach statements.
seeing your example and then your code really helped me, thank you...I was getting brain tired and frutrated. what does this mean?
(mapcar(function (lambda (locked frozen) (vla-put-lock locked :vlax-true)(vla-put-freeze frozen :vlax-true)))LayerLocked LayerFrozen
Anytime cadman..i like trying it before being given the answer as well.
I'm passing the lists to mapcar there.
Here's a small example with the mapcar statement.
(mapcar'(lambda (Locked Frozen)(do something to Locked)(do something to Frozen))(Locked List) (Frozen List)) never mind I figured it out....
I tell you, I don't think I would have solved the mapcar lambda on my own...
I am looking at and still don't understand it...I will need to study this...
Thanks again Just for fun, here's another way...
(defun foo (/ lst) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (and (eq (vla-get-lock x) :vlax-true) (setq lst (cons (list x 'Lock :vlax-true) lst)) (vla-put-lock x :vlax-false) ) (and (eq (vla-get-freeze x) :vlax-true) (setq lst (cons (list x 'Freeze :vlax-true) lst)) (vla-put-freeze x :vlax-false) ) ) ;; DO STUFF (foreach x lst (apply (function vlax-put-property) x)))
页:
[1]
2