Real Time Rendering

Switching on and off All the Environments' Shadows of a Product


This macro shows you how to switch off the shadows of a the current document, and how to switch them on again.

 

switch_ShadowsEnv is launched in CATIA. An existing document called "TestLight.CATProduct" must be found in the CATDocView. It needs "Back.CATPart" and "Hole.CATPart".

switch_ShadowsEnv.CATScript is located in the CAAScdRscUseCases module. Execute macro (windows only).

 

switch_ShadowsEnv includes three steps:

  1. Prolog
  2. Switching off Shadows
  3. Switching on Shadows

Prolog

	' Get the documents collection
	Dim oCollection As Documents
	Set oCollection = CATIA.Documents

	' test if no document is open
	If 0=oCollection.Count Then 
		msgbox "A product document must be active to execute this macro.", vbOKOnly, "Switch On Lights"
		Exit Sub
	End If

	 ' Get material library
	Dim oProductDocument As Document
	Set oProductDocument = CATIA.ActiveDocument

	' test if the active document is a material library (CATMaterial)
	If 0=InStr(oProductDocument.Name, ".CATProduct") Then
		msgbox "A product document must be active to execute this macro.", vbOKOnly, "Switch Off Shadows"
		Exit Sub
	End If

	' Accessing the Root Product
	Dim oRootProduct As Document
	Set oRootProduct = oProductDocument.Product

	' Accessing the collection of rendering lights
	Dim oLights As RenderingLights
	Set oLights = oRootProduct.GetItem("CATRscRenderingLightVBExt")

	' Declarations
	Dim I As Int
	Dim oLight As RenderingLight
	Dim oTab(3) As CATSafeArrayVariant

	' Create the parameter
	Dim oParams As Parameters
	Dim oReadParam As Parameter
	Dim oParam As Parameter
	Dim sParamValue As String
	Set oParams = oProductDocument.Product.Parameters

	On Error Resume Next
	Set oParam = oParams.Item("LightsShadowsStatus")
	...

At first, this macro tests if a document is active in CATIA and if this document is a CATProduct. Then it access to the valid root document and to the collection of rendering environments. After that the macro tests if the knowledge parameter exists. This parameter is used in order to remember which shadow was active.

[Top]

Switching off Shadows

	...
	If Err <> 0 Then ''''''''' switch OFF '''''''''
		' Environments loop
		For I=1 To oRenderingEnvironments.Count
			Set oRenderingEnvironment = oRenderingEnvironments.Item(I)

			' Select the active env
			If 1=oRenderingEnvironment.ActiveStatus Then
				iTypeEnv = oRenderingEnvironment.GetType
				sParamValue = oRenderingEnvironment.Name & "="

				' Walls loop
				For J=1 To 6
					' Adapt to the env type
					If (J<=2 And iTypeEnv<>2) Or (J<=4 And J>=3 And iTypeEnv=1) Or (J>=5)  Then
						Set oRenderingEnvironmentWall = oRenderingEnvironment.GetWall(J)
						If 1=oRenderingEnvironmentWall.ShadowsStatus Then
							sParamValue = sParamValue & J
							oRenderingEnvironmentWall.ShadowsStatus = 0
						End If
					End If
				Next
				Exit For
			End If
		Next

		' Create the parameter
		oParams.CreateString "EnvironmentsShadowsStatus", sParamValue
		oParams.Item("EnvironmentsShadowsStatus").Hidden = True
		...

The macro deactivates environments' shadows. And it creates the string to be saved by the parameter.

[Top]

Switching on Shadows

	...
	Else ''''''''' switch ON '''''''''

		' Parse the parameter value
		Dim aTab As Array
		sParamValue = oParam.ValueAsString ' read the parameter value
		aTab = Split(sParamValue, "=")

		Set oRenderingEnvironment = oRenderingEnvironments.Item(aTab(0))
		If Err <> 0 Then ' env not exist
			msgbox "Impossible to find the environment '" & aTab(0) & "'", vbOKOnly, "Switch On Environmemts' Shadows"
		Else
			For I=0 To Len(aTab(1))
				Set oRenderingEnvironmentWall = oRenderingEnvironment.GetWall(Mid(aTab(1), I, 1))
				oRenderingEnvironmentWall.ShadowsStatus = 1
			Next
		End If

		' Remove parameter
		oParams.Remove "EnvironmentsShadowsStatus"

	End If
	...

The macro reactivates environments' shadows. And it destroys the parameter.

[Top]


In Short

This use case presents a macro which can be useful for the demos with CATIA. It gives the possibility to deactivate the environments' shadows, and the ability to reactivate only thoses which where ON.

[Top]


Copyright © 1994-2003, Dassault Systèmes. All rights reserved.