barristann Posted December 7, 2022 Share Posted December 7, 2022 Hi all. I would like to: 1. Lock my Construction Layer (before running Stretch command) 2. Run Stretch command 3. Unlock my Construction Layer after finishing Stretch I don't know why the I do #1 & #2 but could not unlock after finishing. (defun C:S () (command "-layer" "_LO" "Construction_Layer" "") (command "_.stretch") (command "-layer" "Unlock" "Construction_Layer" "") ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 7, 2022 Share Posted December 7, 2022 When you do two commands straight after each other what you have will fail as stretch needs to be completed 1st then run unlock. Just look at what you have to do for stretch and maybe add pause to the command for inputs. Quote Link to comment Share on other sites More sharing options...
barristann Posted December 7, 2022 Author Share Posted December 7, 2022 I've added "pause", but it's still not working (defun C:S () (command "-layer" "_LO" "Construction_Layer" "") (command "_.stretch" "pause") (command "-layer" "Unlock" "Construction_Layer" "") ) Quote Link to comment Share on other sites More sharing options...
mhupp Posted December 7, 2022 Share Posted December 7, 2022 (edited) its just pause "pause" is a string and its like you typing that into the command line. Here is also the visual lisp way. (defun C:S (/ layer) (vl-load-com) (vla-put-lock (setq layer (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "Construction_Layer")) :vlax-true) (command "_.Stretch") (while (< 0 (getvar 'CMDACTIVE)) (command pause) ) (vla-put-lock layer :vlax-false) ) Edited December 8, 2022 by mhupp updated code Quote Link to comment Share on other sites More sharing options...
pkenewell Posted December 7, 2022 Share Posted December 7, 2022 (edited) If more than 1 select is done during the stretch command, or if a "C", "W", "CP", etc. modifier is used, then you need to loop the pause until the command is ended. See my small modification to mhupp's code. (defun C:S (/ layer) (vla-put-lock (setq layer (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "Construction_Layer") :vlax-true) (command "_.Stretch") ;; Loop until command has ended. (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (vla-put-lock layer :vlax-false) ) Edited December 7, 2022 by pkenewell 1 Quote Link to comment Share on other sites More sharing options...
barristann Posted December 8, 2022 Author Share Posted December 8, 2022 Hi guys, thank you for helping me. For some reason, I've tried both codes, but it's not activating. I thought the we're missing a parenthesis after :vlax-true), because I counted 29. But it's not working. I'll continue to try to figure out what I've done wrong. (defun C:S (/ layer) (vla-put-lock (setq layer (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) "Construction_Layer") :vlax-true) ) (command "_.Stretch") ;; Loop until command has ended. (while (= (logand (getvar "cmdactive") 1) 1) (command pause) ) (vla-put-lock layer :vlax-false) ) Quote Link to comment Share on other sites More sharing options...
mhupp Posted December 8, 2022 Share Posted December 8, 2022 (edited) vla commands need vl-load-com to run sorry forgot to add it to the code. updated my origional code. Also right about the mising ) added (setq layer so the 2nd call to unlock was shorter. Edited December 8, 2022 by mhupp Quote Link to comment Share on other sites More sharing options...
barristann Posted December 8, 2022 Author Share Posted December 8, 2022 Hi mhupp, thank you for helping me. Is it possible to lock and unlock multiple layers ? "Construction_Layer1, Construction_Layer2, Construction_Layer3" 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted December 8, 2022 Share Posted December 8, 2022 (edited) There might be a better way to do it but this should work. (defun C:S (/ lst) (vl-load-com) (setq lst '("Construction_Layer" "Construction_Layer2" "Construction_Layer3")) ;layers you want to lock and unlock (foreach lay lst (if (setq e (tblobjname "layer" la)) (vla-put-lock (vlax-ename->vla-object e) :vlax-true) ) ) (command "_.Stretch" pause) (foreach lay lst (if (setq e (tblobjname "layer" la)) (vla-put-lock (vlax-ename->vla-object e) :vlax-false) ) ) ) Edited December 10, 2022 by mhupp Updated Code - ronjonP 1 Quote Link to comment Share on other sites More sharing options...
ronjonp Posted December 8, 2022 Share Posted December 8, 2022 @mhupp FWIW, This would be quite a bit more efficient since it's not iterating all the layers: (foreach la '("Construction_Layer" "Construction_Layer2" "Construction_Layer3") (if (setq e (tblobjname "layer" la)) (vla-put-lock (vlax-ename->vla-object e) :vlax-true) ) ) 2 Quote Link to comment Share on other sites More sharing options...
barristann Posted December 9, 2022 Author Share Posted December 9, 2022 Mhupp codes work wonderfully! You guys are amazing. Thank you everyone. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 9, 2022 Share Posted December 9, 2022 If you have just the 3 construction layers can use a wild card. (command "-layer" "lock" "Construction_Layer*" "") Quote Link to comment Share on other sites More sharing options...
mstb Posted December 10, 2022 Share Posted December 10, 2022 By adding pause, we lose the usual select objects, and for example, when selecting, we must press C. Is there a way to prevent this from happening? Quote Link to comment Share on other sites More sharing options...
mhupp Posted December 10, 2022 Share Posted December 10, 2022 See if any of these apply @mstb https://www.youtube.com/watch?v=dHflFd7YiFw Quote Link to comment Share on other sites More sharing options...
mstb Posted December 10, 2022 Share Posted December 10, 2022 4 hours ago, mhupp said: See if any of these apply @mstb https://www.youtube.com/watch?v=dHflFd7YiFw No, I mean, I don't want to use any keyboard buttons when selecting objects Because by running the above lisp, it goes to single selection mode Quote Link to comment Share on other sites More sharing options...
mhupp Posted December 10, 2022 Share Posted December 10, 2022 (edited) Maybe add it to the lisp? (command "_.Stretch" "_C") Edited December 11, 2022 by mhupp Quote Link to comment Share on other sites More sharing options...
mstb Posted December 12, 2022 Share Posted December 12, 2022 On 12/11/2022 at 1:56 AM, mhupp said: Maybe add it to the lisp? (command "_.Stretch" "_C") Yes, that's right, thank you very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.