Set viewport layer settings to all viewports in a drawing

Set viewport layer settings to all viewports in a drawing

dani_cs
Advocate Advocate
621 Views
4 Replies
Message 1 of 5

Set viewport layer settings to all viewports in a drawing

dani_cs
Advocate
Advocate

Hello all,

 

I have a drawing with 50 tabs and a viewport in each tab. The layer settings inside the first tab changed (not in model space) so, I have to apply that change in all other 49 tabs. I know about layer states (.las) but you have to apply one by one. I looked for lisp in some forum but no one works fine. It changed all kind of settings (colour, freeze, width, type of line, transparency...)

 

do you know some lisp or workflow that would help me?

 

thanks in advance.

0 Likes
622 Views
4 Replies
Replies (4)
Message 2 of 5

Moshe-A
Mentor
Mentor

@dani_cs  hi,

 

check this PopLayState lisp

 

still the solution here relies on LayerState. on your first layout you need to define the LayerState to be applied.

each layout must have only one viewport.

 

wrap the following program in PopLayState.lsp file and load it.

 

Command: PopLayState <enter> ... magic performs 😀

 

enjoy

Moshe

 

 

(vl-load-com) ; load activex support

(defun c:PopLayState (/ laysta layState^ laystate layout flag)

 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (if (not (setq layState^ (layerstate-getnames t t)))
  (progn
   (vlr-beep-reaction)
   (princ "\nCan not find any layerState(s)")
  ); progn
  (progn 
   (foreach laysta layState^
    (terpri)
    (princ laysta)
   ); foreach

   (while (and
	    (not flag)
	    (/= (setq layState (getstring "\nLayerState to populate: ")) "")
	  )
    (if (not (layerstate-has layState))
     (progn
      (vlr-beep-reaction)
      (princ (strcat "\nLayerState \"" (strcase layState) "\" is does not exist."))
     ); progn
     (progn
      (setvar "tilemode" 0)
      (setq flag
	    (foreach layout (layoutlist)
             (setvar "ctab" layout)
             (command "._pspace") ; make sure in pspace
	     (command ".mspace")  ; enter last working viewport
             (layerstate-restore layState nil 3)
            ); foreach
      ); setq
     ); progn
    ); if

   ); while
 
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
); c:PopLayState

 

0 Likes
Message 3 of 5

dani_cs
Advocate
Advocate

Hello @Moshe-A 

 

thanks for your response. I tried the lisp but it did not work as expected. I am attaching some pictures and a drawing as template. I created "_Ventanas" layer (picture 1) and I modified all kind of settings in viewport from tab 1 (picture 2). Then, I created two more tabs with a new viewport in each one, and "_Ventanas" layer settings were equal to picture one (picture three), as I expected.

 

Then, I created a layerstate inside viewport 1, I run the code and, as you can see from picture 4, it modified the whole settings of the layer (I just need settings of viewport). It means that settings of the whole layer were changed, even in model space (picture 5)

0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

Had a look at one of my dwg's and had multiple layer states, some long names, so thought about it, this allows you to pick with out typing a name. Your welcome to use.

 

 

(setq layState^ (layerstate-getnames t t))
(setq lst ())
(foreach laysta layState^
 (setq lst (cons laysta lst))
)
(if (not AHlstbox)(load "Listbox-AH.lsp"))
(setq layState (nth (ahlstbox "Pick a layer state " lst 30 10) lst))

 

SeaHaven_0-1728690875160.png

 

0 Likes
Message 5 of 5

Moshe-A
Mentor
Mentor

@dani_cs hi,

 

i deeply investigate this and it turns out that there is no easy AutoLISP tools to read layer viewport override settings

so my suggest is to do semi automatic job and what does this mean?

 

inside the lisp file (or other file) to manually define the layers + the vp properties (see pic) that you want to populate and this can be applied to each layout viewport.

 

is this something you think you can deal with?

 

Moshe

 

 

(setq layerVPoverrides
       '(("layer1" '(1070 . 0)     		; vp-freeze
	           '(1062 . 7)   		; vp-color
		   '(1006 . "continous")	; vp-linetype
		   '(1370 . "Default")		; vp-lineweight
		   '(1470 . 50)			; vp-transparency
	 )
         ("layer2" '(1070 . 0)     		; vp-freeze
	           '(1062 . 7)   		; vp-color
	           '(1006 . "continous")	; vp-linetype
	           '(1370 . "Default")		; vp-lineweight
	           '(1470 . 50)			; vp-transparency
	 )
	); list
); setq

 

 

 

 

0 Likes