Jump to content

Recommended Posts

Posted

I use this macro to close out of drawings when I am finished working on them. It locks the background layer and the border layer and the viewport layer, but I would also like it to lock the viewports. I have someone in my office who like to make changes to model space through the viewport and they never leave it to the right scale or in the right location and half the time they leave it zoomed in so far your cant click outside of the viewport and they also leave it so they are clicked into the viewport editor so when you try to zoom out to fix something you mess up the scale and everything. the code we use is

^C^C_1=1ps z e -la lo *background*,*border*,*viewport*,*rcp*  qsave close 

is there a way to add viewport lock?

Posted

I was going to recommend using something like this:

 

(defun Make_Reactor  ()
   (vl-load-com)
   (if    (not vport:reactor)
   (setq vport:reactor
        (vlr-command-reactor nil '((:vlr-commandWillStart . vpPrompt)))))
   (princ))
(Make_Reactor)

(defun c:vpPrompt  (Reac args/ ss i vEnt)
   (if    (and (= (car args) "QSAVE")
        (setq ss (ssget "X" (list (cons 0 "VIEWPORT")))))
     (progn
     (setq i (sslength ss))
     (while (not (minusp (setq i (1- i))))
   (setq vEnt (entget (ssname ss i)))    
   (if (not (eq 16384 (logand 16384 (cdr (assoc 90 vEnt)))))
     (progn
     (setq vEnt (subst (cons 90 (+ 16384 (cdr (assoc 90 vEnt)))) (assoc 90 vEnt) vEnt))
     (entmod vEnt))))))
 (princ))
     

'till I realised that "entmod" is useless with Viewports... :( :x:oops:

Posted

Which poses the question -

 

Is there a way to modify a Viewport without going through the command prompt interface?

Cheers

Posted

not that i know of. 1 person in my office is pretty good with macros (had LT for a long time and couldnt use lsp) but was stumped on this.

Posted
not that i know of. 1 person in my office is pretty good with macros (had LT for a long time and couldnt use lsp) but was stumped on this.

 

Well with a macro it isnt too hard:

 

^C^C-vports;L;ON;ALL;;

 

So long as its invoked when in a layout tab :thumbsup:

Posted

Or, if you wanted to use a reactor:

 

(defun Make_Reactor ()
 (vl-load-com)
 (if (not vport:reactor)
   (setq vport:reactor
      (vlr-command-reactor nil '((:vlr-commandWillStart . vpPrompt)))))
 (princ))
(Make_Reactor)

(defun vpPrompt (Reac args / ss i vp ent obj)
 (if (and (= (car args) "QSAVE")
          (setq ss (ssget "X" '((0 . "VIEWPORT"))))
          (not (zerop (setq i (sslength ss)))))
   (progn
     (setq vp i)
     (while (not (minusp (setq i (1- i))))
      (setq ent (ssname ss i)
            obj (vlax-ename->vla-object ent))
      (if (not (vl-catch-all-error-p
                  (vl-catch-all-apply
                    'vla-put-DisplayLocked (list obj 1))))
          (princ)))
    (princ (strcat "\n" (rtos vp) " Viewport(s) Locked."))))
 (princ))

The above will lock all viewports upon saving.

Posted

would this work? it moves to paper space first then starts what you wrote. will this affect all layouts or only the one that it is on?

 
^C^C_1=1ps z e -la lo *background*,*border*,*viewport*,*rcp*-vports;L;ON;ALL;;qsave close

Posted

No I don't think it will, there is nothing separating the commands to lock the layers and to lock the viewport.

 

It will only lock the viewport on one of the layouts.

 

I would recommend using the reactor - it can be modified to react upon a command of your choice.

Posted

that changes from model space to paper space and changes all settings to 1-1 so the lts is .375 and so on. its a lisp that we use. we have one for all the usual scales we work with for model space and one for paperspace. is there a way to add the reactor to be called by the macro?

Posted

I think the reactor would need to react on an ACAD command being invoked, so may not work if the macro is invoked as the macro invokes many ACAD commands itself - but, tbh, I have never tried.

 

I suppose you could modify the macro so that it would perform your 1=1ps and another in built ACAD command (i.e. take out the code that locks the viewport in the macro - as the reactor is going to do this for you), and set the reactor to react on the ACAD command invoked by the macro.

 

Again, not sure if this would work or not, but theres no harm in trying :thumbsup:

Posted

^C^C_1=1ps z e make_reactor -la lo *background*,*border*,*viewport*,*rcp*  qsave close

like this?

Posted

No no no no :)

 

Sorry, I did not explain this earlier.

 

You don't "run" a reactor - you purely load it - it runs by itself.

 

Hence it doesn't have a (defun c: ) syntax.

 

To make it react upon an ACAD command you will see this in the reactor:

 

(defun Make_Reactor ()
 (vl-load-com)
 (if (not vport:reactor)
   (setq vport:reactor
      (vlr-command-reactor nil '((:vlr-commandWillStart . vpPrompt)))))
 (princ))
(Make_Reactor)

(defun vpPrompt (Reac args / ss i vp ent obj)
 (if (and (= (car args) "[b][color=Red]QSAVE[/color][/b]")
          (setq ss (ssget "X" '((0 . "VIEWPORT"))))
          (not (zerop (setq i (sslength ss)))))
   (progn
     (setq vp i)
     (while (not (minusp (setq i (1- i))))
      (setq ent (ssname ss i)
            obj (vlax-ename->vla-object ent))
      (if (not (vl-catch-all-error-p
                  (vl-catch-all-apply
                    'vla-put-DisplayLocked (list obj 1))))
          (princ)))
    (princ (strcat "\n" (rtos vp) " Viewport(s) Locked."))))
 (princ))

Hence this reactor reacts upon invoking the "qsave" command.

Posted

so as long as its loaded it will lock viewports all viewports in all layouts upon save.

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