ViewportDefault Example

Using Programming Languages other than VBA

Sub Example_ViewportDefault()
	' This example creates a new layer called "New_Layer".  It then uses
	' the ViewportDefault property of each Layer to display whether or not that layer
	' is frozen in new viewports.  The user has the ability to toggle whether or not
	' each layer will be frozen in new viewports, and the final ViewportDefault status
	' for all layers is displayed.

	Dim layerObj As AcadLayer, tempLayer As AcadLayer
	Dim msg As String

	' Add the layer to the layers collection
	Set layerObj = ThisDrawing.Layers.Add("New_Layer")

	' Make the new layer the active layer for the drawing
	ThisDrawing.ActiveLayer = layerObj

	' Cycle through the layers and allow user to make them frozen in new viewports or not

	For Each tempLayer In ThisDrawing.Layers
		If tempLayer.ViewportDefault Then	 ' Determine if this layer is fozen in new viewports
			If MsgBox("The layer '" & tempLayer.name & "' will be frozen in new viewports.  Would you like to make this layer unfrozen in new viewports?", vbYesNo & vbQuestion) = vbYes Then
				tempLayer.ViewportDefault = False	 ' Change frozen state
			End If
		Else
			If MsgBox("The layer '" & tempLayer.name & "' will not be frozen in new viewports.  Would you like to make this layer frozen in new viewports?", vbYesNo & vbQuestion) = vbYes Then
				tempLayer.ViewportDefault = True	' Change frozen state
			End If
		End If
	Next

	' Display the new viewport freeze status of the layers in this drawing

	For Each tempLayer In ThisDrawing.Layers
		' Determine if this layer is frozen in new viewports
		If tempLayer.ViewportDefault Then
			msg = msg & "The layer '" & tempLayer.name & "' will be frozen in new viewports." & vbCrLf
		Else
			msg = msg & "The layer '" & tempLayer.name & "' will not be frozen in new viewports." & vbCrLf
		End If
	Next

	MsgBox msg
End Sub

 

   Comments?