+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 27
  1. #1
    Super Member SuperCAD's Avatar
    Computer Details
    SuperCAD's Computer Details
    Operating System:
    Win7 Professional 64bit
    Computer:
    Some POS given to my by corporate...
    RAM:
    16G :-(
    Graphics:
    NVIDIA 2000
    Primary Storage:
    500G
    Discipline
    Manufacture
    SuperCAD's Discipline Details
    Occupation
    CAD Manager
    Discipline
    Manufacture
    Details
    Drawings for an exhibit fixture manufacturer.
    Using
    AutoCAD 2014
    Join Date
    Sep 2008
    Location
    WI, USA
    Posts
    728

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

    Registered forum members do not see this ad.

    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?
    Trying to explain the benefits of SolidWorks to a devout AutoCAD user is like trying to explain evolution to a creationist.

  2. #2
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,149

    Default

    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.
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  3. #3
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,962

    Default

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

    Code:
    (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.
    Last edited by Lee Mac; 4th Oct 2010 at 08:59 pm.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,962

    Default

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

    Code:
    (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"
    Last edited by Lee Mac; 4th Oct 2010 at 08:59 pm.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,149

    Default

    Works on my end. 1 is 2dwireframe and 2 is 3dhidden. Set the property, activate the viewport and type VSCurrent.
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,962

    Default

    Quote Originally Posted by alanjt View Post
    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.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,149

    Default

    Quote Originally Posted by Lee Mac View Post
    Oh right - not sure what I was doing then

    Thanks for testing.
    Sure thing.
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  8. #8
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,149

    Default

    Quote Originally Posted by RenderMan View Post
    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?
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  9. #9
    Luminous Being alanjt's Avatar
    Using
    Civil 3D 2013
    Join Date
    Apr 2008
    Posts
    6,149

    Default

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

    Code:
    (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
           (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
             )
           )
           ;; AT edit end
         )
    
         (vla-delete ss)
        )
      )
    
      (princ)
    )
    DropBox | finding the light...
    Seann: ...it went crazy ex-girlfriend on me...
    eric_monceaux...its pretty funny seeing two AutoCAD Gods give each other flak...

  10. #10
    Forum Deity BlackBox's Avatar
    Computer Details
    BlackBox's Computer Details
    Operating System:
    Windows 8.1 Professional, Server 2012 R2 Datacenter
    Computer:
    Dell Precision T3600
    CPU:
    Hex-Core Intel Xeon 3.2Ghz
    RAM:
    32GB
    Graphics:
    3GB NVIDIA Quadro K4000
    Primary Storage:
    256GB SSD
    Secondary Storage:
    1TB Western Digital VelociRaptor 10K RPM
    Monitor:
    Dual 24" Dell Ultrasharp Widescreen Monitors
    Using
    Civil 3D 2015
    Join Date
    Nov 2009
    Posts
    4,838

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by Lee Mac View Post
    (ssget "_X" '((0 . "VIEWPORT")))
    Quote Originally Posted by alanjt View Post
    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)
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD, and Civil 3D Certified Professional | Autodesk Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

Similar Threads

  1. Lock/Unlock viewports tool
    By bobsy852 in forum AutoCAD General
    Replies: 2
    Last Post: 28th Jul 2010, 02:29 pm
  2. Script to lock all viewports.
    By Small Fish in forum AutoLISP, Visual LISP & DCL
    Replies: 7
    Last Post: 8th Sep 2009, 10:56 pm
  3. Lock all paperspace viewports with VBA..
    By hardwired in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 31st Jan 2008, 01:20 pm
  4. Visualstyle & AutoLisp
    By HofCAD in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 18th Sep 2006, 02:47 pm
  5. Forcing AutoCAD to open a specific template using AutoLISP
    By jshel101 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 13th Jul 2006, 02:05 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts