Hide Table of Contents

Redirect Spotlight Example (VBA)

This examples shows how select a spotlight and two sketch points.  The spotlight is then redirected to point along the vector that is defined by the two points.  

NOTE: This example is specific to the model used to develop and test the example. You will need to modify the example to allow for more general conditions.

 

'---------------------------------------------

 

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim Part As SldWorks.ModelDoc2

Dim SelMgr As SldWorks.SelectionMgr

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

 

Sub main()

 

Dim swMath As SldWorks.MathUtility

Dim selLightFeat As SldWorks.Feature

Dim selLight As SldWorks.Light

Dim selRootSkPt As SldWorks.SketchPoint

Dim selDirSkPt As SldWorks.SketchPoint

Dim selSk As SldWorks.Sketch

Dim selSkTrans As SldWorks.MathTransform

Dim ptArr(2) As Double

Dim dirArr(2) As Double

Dim rootPoint As SldWorks.MathPoint

Dim dirPoint As SldWorks.MathPoint

Dim dirVector As SldWorks.MathVector

Dim params As Variant

 

Set swApp = Application.SldWorks

Set swMath = swApp.GetMathUtility

Set Part = swApp.ActiveDoc

Set SelMgr = Part.SelectionManager

 

'Select the light to operate on

boolstatus = Part.Extension.SelectByID2("Spot1", "LIGHTS", 0, 0, 0, False, 0, Nothing, 0)

Set selLightFeat = SelMgr.GetSelectedObject6(1, -1)

Set selLight = selLightFeat.GetSpecificFeature2

 

'Select the root point

boolstatus = Part.Extension.SelectByID2("Point3@3DSketch1", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)

Set selRootSkPt = SelMgr.GetSelectedObject6(1, -1)

Set selSk = selRootSkPt.GetSketch

Set selSkTrans = selSk.ModelToSketchTransform.Inverse 'Need the sketch to model transform

ptArr(0) = selRootSkPt.X

ptArr(1) = selRootSkPt.Y

ptArr(2) = selRootSkPt.Z

Set rootPoint = swMath.CreatePoint((ptArr))

Set rootPoint = rootPoint.MultiplyTransform(selSkTrans) 'Make sure that the point is in model space

 

'Select the direction point

boolstatus = Part.Extension.SelectByID2("Point1@3DSketch1", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)

Set selDirSkPt = SelMgr.GetSelectedObject6(1, -1)

Set selSk = selDirSkPt.GetSketch

Set selSkTrans = selSk.ModelToSketchTransform.Inverse

ptArr(0) = selDirSkPt.X

ptArr(1) = selDirSkPt.Y

ptArr(2) = selDirSkPt.Z

Set dirPoint = swMath.CreatePoint((ptArr))

Set dirPoint = dirPoint.MultiplyTransform(selSkTrans)

 

'Determine the direction of the spotlight

Set dirVector = dirPoint.Subtract(rootPoint)

params = rootPoint.ArrayData

ptArr(0) = params(0)

ptArr(1) = params(1)

ptArr(2) = params(2)

params = dirVector.ArrayData

dirArr(0) = params(0)

dirArr(1) = params(1)

dirArr(2) = params(2)

 

'Get the current parameters for the spotlight

params = Part.LightSourcePropertyValues(selLight.GetID())

 

'Modify the root point and direction vector, then apply the changes

params(5) = ptArr(0)

params(6) = ptArr(1)

params(7) = ptArr(2)

params(8) = dirArr(0)

params(9) = dirArr(1)

params(10) = dirArr(2)

Part.LightSourcePropertyValues(selLight.GetID()) = params

 

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Redirect Spotlight Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:



x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.