Jump to content

AutoLISP to lock viewports, change visualstyle and set to specific layer


SuperCAD

Recommended Posts

Let me start by saying that I have NO AutoLISP programming knowledge at all.

 

I'm having a bit of trouble getting all of my people to do a few specific things with their viewports. I've asked them numerous times to do the following:

 

 

  1. Lock all viewports
  2. Change all viewport visual styles to 2D wireframe
  3. Put all viewports on the "VIEWPORTS" layer

 

It may be that I'm asking too much, but a couple of my guys still have unlocked viewports that won't print properly due to the visual style. They've gotten better, but a few will creep up every now and then, so I'm looking for a code that would complete the tasks I've listed above. I've tried searching for a code already but it doesn't look like one exists.

 

Would one of you LISP guru's be so kind as to help a fellow CAD monkey out?

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    10

  • Lee Mac

    6

  • SuperCAD

    4

  • BlackBox

    4

Top Posters In This Topic

For the layer issue, I wrote a reactor that will place Viewports/Images/XRefs on the defined layers. Interested in that? It wouldn't be too terribly difficult to code what you want.

Link to comment
Share on other sites

Sketched this up pretty quick, Alan, could you check the line that I marked?

 

(defun c:test ( / doc ss vl )
 (vl-load-com)

 (setq vl "VIEWPORTS") ;; VP Layer
 
 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (or (tblsearch "LAYER" vl)
     (vla-Add (vla-get-layers doc) vl)
 )

 (cond
   ( (ssget "_X" '((0 . "VIEWPORT")))

     (vlax-for vport (setq ss (vla-get-ActiveSelectionSet doc))
       (vla-put-VisualStyle vport 1)
       (vla-put-layer vport vl)
       (vla-put-DisplayLocked vport :vlax-true)
     )

     (vla-delete ss)
   )
 )

 (princ)
)

vla-put-VisualStyle doesn't seem to be documented either. :(

Edited by Lee Mac
Link to comment
Share on other sites

When the issue with Visual Styles is perhaps ironed out, maybe as a save reactor?

 

(defun c:VPortFix ( / doc ss vl )
 (vl-load-com)

 (setq vl "VIEWPORTS") ;; VP Layer
 
 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (or (tblsearch "LAYER" vl)
     (vla-Add (vla-get-layers doc) vl)
 )

 (cond
   ( (ssget "_X" '((0 . "VIEWPORT")))

     (vlax-for vport (setq ss (vla-get-ActiveSelectionSet doc))
       (vla-put-VisualStyle vport 1)
       (vla-put-layer vport vl)
       (vla-put-DisplayLocked vport :vlax-true)
     )

     (vla-delete ss)
   )
 )

 (princ)
)

(defun c:VPortReactor nil
 (vl-load-com)

 (  (lambda ( data foo / react )
      (if (setq react
            (vl-some
              (function
                (lambda ( reactor )
                  (if (eq data (vlr-data reactor)) reactor)
                )
              )
              (cdar (vlr-reactors :vlr-editor-reactor))
            )
          )
        (if (vlr-added-p react)
          (vlr-remove react)
          (vlr-add react)
        )
        (setq react
          (vlr-editor-reactor data
            (list
              (cons :vlr-beginsave foo)
            )
          )
        )
      )
      (princ
        (if (vlr-added-p react)
          "\n** Reactor Activated **"
          "\n** Reactor Deactivated **"
        )
      )
      react
    )
   "VPort-Reactor"
   'VPort-CallBack
 )

 (princ)
)

(defun VPort-CallBack ( reactor arguments ) (c:VPortFix))

(c:VPortReactor)

Reactor is initiated upon loading, can be toggled off by typing "VPortReactor"

Edited by Lee Mac
Link to comment
Share on other sites

Works on my end. 1 is 2dwireframe and 2 is 3dhidden. Set the property, activate the viewport and type VSCurrent.

 

Oh right - not sure what I was doing then :?

 

Thanks for testing.

Link to comment
Share on other sites

If I may offer a minor enhancement, for polygonal viewports, which includes Alan's suggestion:

I was only saying that for testing purposes.

 

BTW, what are you going to do about viewports existing in a layout other that the one you occupy?

Link to comment
Share on other sites

I would make this change to account for clipped viewports...

 

(defun c:VPortFix (/ doc ss vl)
 (vl-load-com)

 (setq vl "VIEWPORTS")
 ;; VP Layer

 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

 (or (tblsearch "LAYER" vl)
     (vla-Add (vla-get-layers doc) vl)
 )

 (cond
   ((ssget "_X" '((0 . "VIEWPORT")))

    (vlax-for vport (setq ss (vla-get-ActiveSelectionSet doc))
      (vla-put-VisualStyle vport 1)
      (vla-put-layer vport vl)
      (vla-put-DisplayLocked vport :vlax-true)
      ;; AT edit begin
[color=red]       (if (eq (vla-get-Clipped vport) :vlax-true)
        (vla-put-layer
          (vlax-ename->vla-object (cdr (assoc 340 (entget (vlax-vla-object->ename vport)))))
          vl
        )
      )[/color]
      ;; AT edit end
    )

    (vla-delete ss)
   )
 )

 (princ)
)

Link to comment
Share on other sites

(ssget "_X" '((0 . "VIEWPORT")))

 

BTW, what are you going to do about viewports existing in a layout other that the one you occupy?

 

 

Err? :?

 

(pointless text so I can post my reply)

Link to comment
Share on other sites

Err? :?

 

(pointless text so I can post my reply)

(ssget "_X") will select everything, regardless of layout location. You would have to use the 410 variable to filter layouts.

Link to comment
Share on other sites

Wow, thanks for the fast replies! It works almost perfectly. However, I do have one problem when I test it.

 

If I set the visualstyle to anything but 2D wireframe, and then use the LISP to change it, I get this weird zoom/pan thing going on in the viewport. For example, if I zoom in with my mouse wheel the viewport will start to zoom twice as much as everything outside of the viewport, even though the viewport scale is locked. Also if I pan up or down it will zoom in when I reach the top or bottom of my screen.

Link to comment
Share on other sites

For example, if I zoom in with my mouse wheel the viewport will start to zoom twice as much as everything outside of the viewport, even though the viewport scale is locked.

 

 

I hope I am not being overly critical, as I mistype things too, but for the purposes of clarity....

 

One cannot lock the scale, one can only set the scale, and lock the display (i.e., Display locked).

 

Are you saying that with Display Lock = Yes, that the viewports are still zooming, etc.?

Link to comment
Share on other sites

BTW, what are you going to do about viewports existing in a layout other that the one you occupy?

 

(ssget "_X") will select everything, regardless of layout location. You would have to use the 410 variable to filter layouts.

 

 

Again, I ask... Err? :?

 

Does your second response not answer your first, given (ssget "_x" '((0 . "VIEWPORT")))...?

Link to comment
Share on other sites

Kind of. The veiwport is locked (VP locked, scale locked, we're debating semantics) but when I zoom in beyond a certain point, the image IN the viewport will enlarge. Also, when I pan the paperspace towards the top or bottom of the screen, the image in the viewport will again enlarge. I'm trying to do a video capture to better explain the problem.

Link to comment
Share on other sites

Kind of. The veiwport is locked (VP locked, scale locked, we're debating semantics)

 

 

I don't mean to argue semantics, but assuming gets me in trouble; better to just clarify and move on.

 

This could just be my inexperience with using Visual Styles other than 2D Wireframe (as it pertains to AutoCAD). For 3D environment modeling, I typically use Maya. I look forward to the screen capture.

Link to comment
Share on other sites

Well, AutoCAD just made a liar out of me. I shut down ACAD, opened it and tried to recreate the problem but now it works just fine. Next time it happens, I'll grab a video capture of it and post it, but for now the LISP works perfectly.

 

Thank you so much. This will help me keep my monkeys in line.

Link to comment
Share on other sites

Again, I ask... Err? :?

 

Does your second response not answer your first, given (ssget "_x" '((0 . "VIEWPORT")))...?

Sorry, I meant your command calls. I can't reference the post since you deleted it.
Link to comment
Share on other sites

Can't follow this thread at all :?

LoL

It's become pretty congested and confusing.

 

Did you see my post/mod about clipped viewports?

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