 |
switch_ShadowsEnv includes three steps:
- Prolog
- Switching off Shadows
- 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]
|