Jump to content

Help please: Lock Construction, run Stretch, then Unlock Construction


Recommended Posts

Posted

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" "")
)

Posted

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.

Posted

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" "")
)

Posted (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 by mhupp
updated code
Posted (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 by pkenewell
  • Agree 1
Posted

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)
)

Posted (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 by mhupp
Posted

Hi mhupp, thank you for helping me. Is it possible to lock and unlock multiple layers ?

 

"Construction_Layer1, Construction_Layer2, Construction_Layer3"

  • Like 1
Posted (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 by mhupp
Updated Code - ronjonP
  • Like 1
Posted

 

@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)
  )
)

 

  • Like 2
Posted

Mhupp codes work wonderfully! You guys are amazing. Thank you everyone.

Posted

If you have just the 3 construction layers can use a wild card. (command "-layer" "lock" "Construction_Layer*" "")

Posted

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?

Posted (edited)

Maybe add it to the lisp?

 

(command "_.Stretch" "_C")
Edited by mhupp
Posted
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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...