Jump to content

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


barristann

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

"Construction_Layer1, Construction_Layer2, Construction_Layer3"

  • Like 1
Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

@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
Link to comment
Share on other sites

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