Viewport Overrides

Viewport Overrides

zph
Collaborator Collaborator
1,012 Views
10 Replies
Message 1 of 11

Viewport Overrides

zph
Collaborator
Collaborator

Good day!

 

I found the routine below, RVO.  The result is successful for what it claims to do (remove viewport overrides):

 

http://cadtips.cadalyst.com/layer-properties/remove-viewport-overrides

 

(defun c:RVO () (c:RemoveViewportOverrides))
 
(defun c:RemoveViewportOverrides (/ *error* oldCmdecho)
  (princ "\rREMOVEVIEWPORTOVERRIDES ")
 
  (defun *error* (msg)
    (and oldCmdecho (setvar 'cmdecho oldCmdecho))
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (princ)
  )
 
  (if (/= 1 (getvar 'tilemode))
    (progn
      (setq oldCmdecho (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (command "._vplayer" "reMoveoverrides" "all" "*" "all" "")
      (*error* nil)
    )
    (*error* "Command not allowed in Model Tab")
  )
  (princ)
)

 

 

However, I'd like this routine to remove the viewport overrides on all viewports in the entire drawing file.

 

I've messed around with it, but haven't been successful in modifying it to do so.

 

Any of you guys help me out?

 

Thanks!

0 Likes
1,013 Views
10 Replies
Replies (10)
Message 2 of 11

ВeekeeCZ
Consultant
Consultant

Maybe just like this?

 

(defun c:RVO () (c:RemoveViewportOverrides))
 
(defun c:RemoveViewportOverrides (/ *error* oldCmdecho)
  (princ "\rREMOVEVIEWPORTOVERRIDES ")
 
  (defun *error* (msg)
    (and oldCmdecho (setvar 'cmdecho oldCmdecho))
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (princ)
  )

  (setq oldCmdecho (getvar 'cmdecho))
  (setvar 'cmdecho 0)

  (foreach e (layoutlist)
    (setvar 'CTAB e)
    (command "._vplayer" "reMoveoverrides" "all" "*" "all" "")
    )
  (setvar 'cmdecho oldCmdecho )
  (princ)
)
Message 3 of 11

rkmcswain
Mentor
Mentor

This is a bare bones version. I just tried it on a drawing with overrides in multiple layouts and it worked.

 

Your mileage may vary...

 

(foreach item (layoutlist)
  (vl-cmdf "layout" "_set" item)
  (vl-cmdf "._vplayer" "_reMoveoverrides" "_all" "*" "_all" "")
) 

 

 

 

R.K. McSwain     | CADpanacea | on twitter
Message 4 of 11

zph
Collaborator
Collaborator

Thank you for your replies, rkmcswain and BeeKeeCZ.

 

One of my tries looked a lot like your solutions.  ...and yours' do work.

 

However, it is slow; and I know that is the "set" function of the "layout" command that is slowing it down.

 

I've used code before that utilizes the vlax-for capability and the routines that previously needed to use the "layout" command no longer needed to do so, and afterwards, were lightning fast accomplishing the same result.

 

(setq acapp (vlax-get-acad-object))
(setq acdoc (vla-get-activedocument acapp))

(vlax-for layout (vla-get-layouts acdoc) (vla-put-activelayout acdoc layout)  
(vl-cmdf "._vplayer" "_reMoveoverrides" "_all" "*" "_all" "") ) ;vlax-for

I'm not as comfortable with vla functions, but this routine effectively accomplishes the same goal as before, but at the same rate as the original code.  I suspect this is due to the code highlited in red.  The red code takes the place of the "layout" command.

 

 

Anyways, enough of my blabbering.  Do you guys know of a way to speed up this routine?

0 Likes
Message 5 of 11

rkmcswain
Mentor
Mentor

If you're going to push the .vplayer command, then you have to graphically be in the layout.

I suspect the majority of time spent by this routine is switching to each layout.

 

If you wanted to dig deeper into the drawing database and remove the overrides with code (as opposed to pushing a command), then you can probably gain a lot of speed. Here is a sample I ran across.

 

 

 

 

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 6 of 11

ВeekeeCZ
Consultant
Consultant

This should be enough.

 

(vl-load-com)

(defun c:RVO ( / adoc )
    (setq adoc (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for layt (vla-get-layouts adoc)
        (if (not (= (vla-get-name layt) "Model"))
            (vl-cmdf "._vplayer" "_reMoveoverrides" "_all" "*" "_all" "")
        )
    )
  (princ)
)

And yes, it's much faster.

(part seen /Edit: took from / Henrique's code)

Message 7 of 11

zph
Collaborator
Collaborator
Thanks BeekeeCZ,

However, this form of the routine only removes the overrides from the current layout tab.
0 Likes
Message 8 of 11

zph
Collaborator
Collaborator

Here is the information I found on http://m.arch-pub.com/Removing-Viiewport-Overrides_10729831.html:

 

I am unfamiliar with the code language and structure.

 

public static void RemoveOverrides()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Collection of our selected entities and their sub-ent paths
ObjectIdCollection ids;
List<FullSubentityPath> paths;
// Flag for whether a REGEN will be required
bool regenRequired = false;
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
if (SelectNestedEntities(ed, out ids, out paths) &&
ids.Count > 0)
{
for (int i = 0; i < ids.Count; i++)
{
Entity ent = tr.GetObject(ids[i], OpenMode.ForRead) as Entity;
if (ent != null)
{
regenRequired = true;
string layerName = ent.Layer;
LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(lt[layerName], OpenMode.ForWrite);
if (!ltr.IsLocked)
{
LayerViewportProperties lvpo = ltr.GetViewportOverrides(ed.CurrentViewportObjectI​d);
ltr.RemoveAllOverrides();
}
else
{
ed.WriteMessage("\nLayer {0} is locked. Override removal not completed.", ltr.Name);
}
}
}
}
UnhighlightSubEntities(paths);
tr.Commit();

 

 

Help, please?

0 Likes
Message 9 of 11

ВeekeeCZ
Consultant
Consultant

@zph wrote:
Thanks BeekeeCZ,

However, this form of the routine only removes the overrides from the current layout tab.

Sorry, I checked the result too quickly. Then I am nothing better with vl* funtions then you are 😞

0 Likes
Message 10 of 11

zph
Collaborator
Collaborator

No worries. I appreciate that you are willing to put yourself out there anyway.  Cheers!

 

I don't know why, but I've had a much harder time learning vl than AutoLISP.

0 Likes
Message 11 of 11

zph
Collaborator
Collaborator

I ran some simple code in an attempt to see what vla can do with viewports and viewport overrides.

 

Again, my understanding of vl* functions is less than basic.  I know RVO does remove the overrides so I ran a "vlax-dump" on the viewport before and after RVO:

 

Spoiler

***viewport prior to running rvo

Command: (vlax-dump-object (vlax-ename->vla-object (car (entsel))))

Select object: ; IAcadPViewport: IAcadPViewport Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 0000000140429110>
;   ArcSmoothness = 1000
;   Center = (20.0 13.998 0.0)
;   Clipped (RO) = 0
;   CustomScale = 1.0
;   Direction = (0.0 0.0 56.4692)
;   DisplayLocked = 0
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000003ba35c58>
;   EntityTransparency = "ByLayer"
;   GridOn = 0
;   Handle (RO) = "795C"
;   HasExtensionDictionary (RO) = -1
;   HasSheetView (RO) = 0
;   Height = 27.0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 00000000350d5f08>
;   LabelBlockId = 0
;   Layer = "VIEWPORTS"
;   LayerPropertyOverrides (RO) = 0
;   LensLength = 50.0
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   ModelView = nil
;   ObjectID (RO) = 42
;   ObjectName (RO) = "AcDbViewport"
;   OwnerID (RO) = 43
;   PlotStyleName = "ByLayer"
;   ShadePlot = 0
;   SheetView = nil
;   SnapBasePoint = (0.0 0.0)
;   SnapOn = 0
;   SnapRotationAngle = 0.0
;   StandardScale = 34
;   StandardScale2 = 2
;   Target = (19.5 13.5 0.0)
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 00000000350d5720>
;   TwistAngle = 0.0
;   UCSIconAtOrigin = -1
;   UCSIconOn = -1
;   UCSPerViewport = -1
;   ViewportOn = -1
;   Visible = -1
;   VisualStyle = 1
;   Width = 39.0
T

***viewport after rvo has been run

Command: (vlax-dump-object (vlax-ename->vla-object (car (entsel))))

Select object: ; IAcadPViewport: IAcadPViewport Interface
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 0000000140429110>
;   ArcSmoothness = 1000
;   Center = (20.0 13.998 0.0)
;   Clipped (RO) = 0
;   CustomScale = 1.0
;   Direction = (0.0 0.0 56.4692)
;   DisplayLocked = 0
;   Document (RO) = #<VLA-OBJECT IAcadDocument 000000003ba35c58>
;   EntityTransparency = "ByLayer"
;   GridOn = 0
;   Handle (RO) = "795C"
;   HasExtensionDictionary (RO) = -1
;   HasSheetView (RO) = 0
;   Height = 27.0
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 000000003ea4a5e8>
;   LabelBlockId = 0
;   Layer = "VIEWPORTS"
;   LayerPropertyOverrides (RO) = 0
;   LensLength = 50.0
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Material = "ByLayer"
;   ModelView = nil
;   ObjectID (RO) = 42
;   ObjectName (RO) = "AcDbViewport"
;   OwnerID (RO) = 43
;   PlotStyleName = "ByLayer"
;   ShadePlot = 0
;   SheetView = nil
;   SnapBasePoint = (0.0 0.0)
;   SnapOn = 0
;   SnapRotationAngle = 0.0
;   StandardScale = 34
;   StandardScale2 = 2
;   Target = (19.5 13.5 0.0)
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 000000003ea4a700>
;   TwistAngle = 0.0
;   UCSIconAtOrigin = -1
;   UCSIconOn = -1
;   UCSPerViewport = -1
;   ViewportOn = -1
;   Visible = -1
;   VisualStyle = 1
;   Width = 39.0
T

 

I expected the results (that I highlited red) to be different before and after RVO, but they aren't.

 

EDIT:  I did the same using standard AutoLISP and received similar results.

Spoiler

*** viewport before RVO

((-1 . <Entity name: 7fffd611540>) (0 . "VIEWPORT") (5 . "795C") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 7fffd611550>) (102 . "}") (330 . <Entity name: 7fffd641db0>) (100 . "AcDbEntity") (67 . 1) (410 . "Layout 5") (8 . "VIEWPORTS") (100 . "AcDbViewport") (10 20.0 13.998 0.0) (40 . 39.0) (41 . 27.0) (68 . 2) (69 . 2) (12 160.0 0.0 0.0) (13 0.0 0.0 0.0) (14 0.5 0.5 0.0) (15 0.5 0.5 0.0) (16 0.0 0.0 56.4692) (17 19.5 13.5 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 27.0) (50 . 0.0) (51 . 0.0) (72 . 1000) (90 . 819296) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Entity name: 7fffd60adf0>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))

*** viewport after RVO

((-1 . <Entity name: 7fffd611540>) (0 . "VIEWPORT") (5 . "795C") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 7fffd611550>) (102 . "}") (330 . <Entity name: 7fffd641db0>) (100 . "AcDbEntity") (67 . 1) (410 . "Layout 5") (8 . "VIEWPORTS") (100 . "AcDbViewport") (10 20.0 13.998 0.0) (40 . 39.0) (41 . 27.0) (68 . 2) (69 . 2) (12 160.0 0.0 0.0) (13 0.0 0.0 0.0) (14 0.5 0.5 0.0) (15 0.5 0.5 0.0) (16 0.0 0.0 56.4692) (17 19.5 13.5 0.0) (42 . 50.0) (43 . 0.0) (44 . 0.0) (45 . 27.0) (50 . 0.0) (51 . 0.0) (72 . 1000) (90 . 819296) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0) (111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5) (348 . <Entity name: 7fffd60adf0>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63 . 250) (421 . 3355443))

0 Likes