Author Topic: Routine to change layer settings on multiple viewports in multiple tabs  (Read 2938 times)

0 Members and 1 Guest are viewing this topic.

damn

  • Mosquito
  • Posts: 15
Hi,

I work with drawings often with 200+ layouts.  They are drawings supplied by our client.  Each of the layouts has 2 viewports, 1 large & 1 small.  The drawings can take 6-8hrs to plot.  If I can freeze/turn off all (120 layers) but 3 layers on the small viewport in ea layout I believe I can reduce the plot times  by 40%+. Any suggestions?  Thanks.

Damian.

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Routine to change layer settings on multiple viewports in multiple tabs
« Reply #1 on: November 01, 2018, 03:25:52 AM »
Post a sample dwg so can check the viewports, just need to make sure they are always created in same order, the extra bit would be to check for large and small.

Does not need to many say 2-3 and a few layers.

Some of the properties allow to work out big or small
Select object: ; IAcadPViewport: IAcadPViewport Interface
; Property values:
;   Center = (397.414 301.03 0.0)
;   CustomScale = 0.485444
;   Height = 473.195
;   ObjectName (RO) = "AcDbViewport"
;   StandardScale = 1
;   StandardScale2 = 1
;   Target = (610.872 453.508 0.0)
;   Width = 776.284

« Last Edit: November 01, 2018, 07:55:29 AM by BIGAL »
A man who never made a mistake never made anything

damn

  • Mosquito
  • Posts: 15
Re: Routine to change layer settings on multiple viewports in multiple tabs
« Reply #2 on: November 02, 2018, 12:28:37 AM »
Say in this example in the small viewport (key) I would only have 141, Grid layers an possible 1 more.

ronjonp

  • Needs a day job
  • Posts: 7526

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

damn

  • Mosquito
  • Posts: 15
Re: Routine to change layer settings on multiple viewports in multiple tabs
« Reply #4 on: January 21, 2019, 09:43:54 PM »
Bump....no other takers?

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Routine to change layer settings on multiple viewports in multiple tabs
« Reply #5 on: January 22, 2019, 09:03:09 AM »
Bump....no other takers?
Supply a drawing that has the linework in modelspace with the starting point and the desired result.
« Last Edit: January 22, 2019, 09:13:10 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

damn

  • Mosquito
  • Posts: 15
Re: Routine to change layer settings on multiple viewports in multiple tabs
« Reply #6 on: January 22, 2019, 06:11:02 PM »
Attached.  Layout [001 Key plan all layers] the small viewport (Key Plan) has all layers on.
Layout [001 Key plan Desired layers] the small viewport has all but GRID & L141 Cadastre have been frozen.
Thanks.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Routine to change layer settings on multiple viewports in multiple tabs
« Reply #7 on: January 23, 2019, 12:28:06 PM »
Not pretty but seems to work :).
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ ad co e el o s vc)
  2.   ;; RJP » 2019-01-23
  3.   ;; Matches viewport properties to all layouts if target has a similar center location
  4.   (setvar 'tilemode 0)
  5.   (cond ((and (setq e (car (entsel "\nPick source viewport with correct layers: ")))
  6.               ;; Is it a viewport?
  7.               (= "VIEWPORT" (cdr (assoc 0 (setq el (entget e '("ACAD"))))))
  8.               ;; Check if there are layer overrides in the selected viewport
  9.               (vl-remove-if '(lambda (x) (/= (car x) 331)) el)
  10.               ;; Get the center of the vieport selected
  11.               (setq vc (cdr (assoc 10 el)))
  12.               ;; Select all paperspace viewports in drawing and remove the source
  13.               (ssdel e (setq s (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1)))))
  14.               (setq s (mapcar 'cadr (ssnamex s)))
  15.          )
  16.          (setvar 'cmdecho 0)
  17.          (setq o (vlax-ename->vla-object e))
  18.          (foreach x s
  19.            ;; If the center point is within a fuzz value of 1
  20.            (cond ((equal vc (cdr (assoc 10 (setq el (entget x)))) 1)
  21.                   ;; Copy the source viewport
  22.                   (setq co (car (vlax-invoke
  23.                                   ad
  24.                                   'copyobjects
  25.                                   (list o)
  26.                                   (vlax-ename->vla-object (cdr (assoc 330 (entget x))))
  27.                                   t
  28.                                 )
  29.                            )
  30.                   )
  31.                   ;; Matchpprop won't match from tab to tab but will from drawing to drawing .. go figure.
  32.                   (setvar 'ctab (cdr (assoc 410 el)))
  33.                   ;; Make sure we're in paperspace
  34.                   (command "_.pspace")
  35.                   ;; Ugly but seems to work
  36.                   (command "_.matchprop" (vlax-vla-object->ename co) x "")
  37.                   ;; Delete the copied viewport
  38.                   (vla-delete co)
  39.                   ;; Print the tab name
  40.                   (print (cdr (assoc 410 el)))
  41.                  )
  42.            )
  43.          )
  44.          (setvar 'cmdecho 1)
  45.         )
  46.   )
  47.   (princ)
  48. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

damn

  • Mosquito
  • Posts: 15
Re: Routine to change layer settings on multiple viewports in multiple tabs
« Reply #8 on: January 28, 2019, 08:02:55 PM »
Ronjonp,

Thank you very much.  Works! Useful timesaver & PDF size reduction.