Change viewports Layer

Change viewports Layer

My_Civil_3D
Advocate Advocate
428 Views
4 Replies
Message 1 of 5

Change viewports Layer

My_Civil_3D
Advocate
Advocate

Hi guys i am having a problem with my code. i am trying to change the layer of the viewports in my sheet, it works well but at the end i want to change the layer back to the last layer it was on but it doesnt want to. not sure why

(defun c:C_CVL (/ selViewports OldLayer)
(setq OldLayer(Getvar "Clayer"))
(setq selViewports (ssget "X" '((0 . "VIEWPORT")))) 
(if(tblsearch "LAYER" ".VIEWPORT")
(setvar "Clayer" ".VIEWPORT")
(command "-layer" "m" ".VIEWPORT" "c" 150 "" "P" "N" """"))
(command "CHPROP" sel1 "" "LAYER" ".VIEWPORT" "")
(setvar "Clayer" OldLayer )
(princ)
)

 

Civil 3D Certified Professional
0 Likes
Accepted solutions (1)
429 Views
4 Replies
Replies (4)
Message 2 of 5

komondormrex
Mentor
Mentor
Accepted solution

hey, there is no sel1 selection set

 

(defun c:C_CVL (/ selViewports OldLayer)
	(setq OldLayer (Getvar "Clayer"))
	(setq selViewports (ssget "X" '((0 . "VIEWPORT")))) 
	(if (not (tblsearch "LAYER" ".VIEWPORT"))
		(command "-layer" "m" ".VIEWPORT" "c" 150 "" "P" "N" """")
	)
	(command "CHPROP" selViewports "" "LAYER" ".VIEWPORT" "")
	(setvar "Clayer" OldLayer )
	(princ)
)
0 Likes
Message 3 of 5

My_Civil_3D
Advocate
Advocate

Problem fixed thank you

 

(defun c:C_CVL (/ sel1 OldLayer)
(setq OldLayer(Getvar "Clayer"))
(setq sel1 (ssget "X" '((0 . "VIEWPORT")))) 
(if(tblsearch "LAYER" ".VIEWPORT")
(setvar "Clayer" ".VIEWPORT")
(command "-layer" "m" ".VIEWPORT" "c" 150 "" "P" "N" """"))
(command "CHPROP" sel1 "" "LAYER" ".VIEWPORT" "")
(setvar "Clayer" OldLayer)
(princ)
)

 

Civil 3D Certified Professional
0 Likes
Message 4 of 5

ronjonp
Mentor
Mentor

@My_Civil_3D 

 

Here's another way to do it without messing with the current layer.

 

(defun c:c_cvl (/ l n s)
  (cond	((setq s (ssget "_X" '((0 . "VIEWPORT"))))
	 (setq n ".VIEWPORT")
	 (setq l (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) n))
	 (vla-put-color l 150)
	 (foreach e (mapcar 'cadr (ssnamex s)) (vla-put-layer (vlax-ename->vla-object e) n))
	)
  )
  (princ)
)

 

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

How about simply checking whether the ".VIEWPORT" Layer exists, and if it does, LAYMRG the "VIEWPORT" Layer into it, and if it doesn't, just RENAME "VIEWPORT" to add the period prefix?  No dealing with the current Layer, no object selection involved, etc.

Kent Cooper, AIA
0 Likes