Option Explicit Private dblOldAngle If IsEmpty(dblOldAngle) Then dblOldAngle = 30 End If Rhino.AddStartupScript Rhino.LastLoadedScriptFile Rhino.AddAlias "SpotLightAngle", "_NoEcho _-Runscript (SpotlightAngle)" 'Call SpotlightAngle() Sub SpotlightAngle() Dim arrLights, strLight, arrSpots(), strSpot, dblAngle, dblAngle2 Dim i, p arrLights = Rhino.GetObjects("Select spotlights to adjust", 256, True, True) If Not isArray(arrLights) Then Exit Sub If IsArray(arrLights) Then For Each strLight In arrLights If Rhino.IsSpotLight(strLight) Then ReDim Preserve arrSpots(i) arrSpots(i) = strLight i = i + 1 End If Next End If Dim tempAngle: tempAngle = GetLightAngle(ArrLights(0)) Dim sAngle: sAngle = " Current angle is " & tempAngle & " degrees." If Ubound(arrLights) > 0 Then For i = 1 To UBound(arrLights) If getLightAngle(arrLights(i)) <> tempAngle Then sAngle = " Current angle varies." Exit For End If Next End If If isUpperBound(arrSpots) Then dblAngle = Rhino.GetReal("Spotlight cone angle in degrees." & sAngle, dblOldAngle, .1, 180) If IsNumeric(dblAngle) Then dblOldAngle = dblAngle dblAngle2 = Rhino.ToRadians(.5*dblAngle) End If For p = 0 To UBound(arrSpots) AdjustSpotAngle arrSpots(p), dblAngle2 Next End If End Sub '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ '///////////////////////////////// Sub AdjustSpotAngle(strSpot, dblAngle) Dim Distance, arrSource, arrTarg, vec, radius arrSource = Rhino.LightLocation(strSpot) arrTarg = Rhino.LightDirection(strSpot) vec = Rhino.VectorCreate(arrSource, arrTarg) Distance = Rhino.Distance(arrSource, arrTarg) Radius = Abs((Tan(dblAngle)) * Distance) Rhino.SpotlightRadius strSpot, Radius End Sub Function GetLightAngle(sLight) Dim aLoc: aLoc = Rhino.LightLocation(sLight) Dim aTarg: aTarg = Rhino.LightDirection(sLight) Dim Dist: Dist = Rhino.Distance(aLoc, aTarg) Dim dblrad: dblRad = Round(Rhino.SpotLightRadius(sLight), 2) Dim Side: Side = sqr((dist ^ 2 ) + (dblRad ^ 2)) Dim dblAng: dblAng = 2 * ( Round(Rhino.ToDegrees(atn(dblRad / Dist)), 2) & " ") GetLightAngle = dblAng End Function '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ '///////////////////////////////// ' Function IsUpperBound(ByRef arr) IsUpperBound = False If IsArray(arr) Then On Error Resume Next UBound arr If Err.Number = 0 Then IsUpperBound = True End If End Function '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ '/////////////////////////////////