rob1231
Mechanical
- Apr 20, 2020
- 4
Good Evening,
I'm trying to write a SW script in VBA to automatically output the length of a line (defined in a sketch).
To make things easier, I created a dimension sensor for the length of the line (since it is a complex shape).
I keep getting the error: "Object doesn't support this property or method" on the same line of the code even though I'm following the SW help very closely (I get the error when running the sample script too).
Here's the script (with the line giving the error highlighted):
Thanks in advance for your help!
I'm trying to write a SW script in VBA to automatically output the length of a line (defined in a sketch).
To make things easier, I created a dimension sensor for the length of the line (since it is a complex shape).
I keep getting the error: "Object doesn't support this property or method" on the same line of the code even though I'm following the SW help very closely (I get the error when running the sample script too).
Here's the script (with the line giving the error highlighted):
Code:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.PartDoc
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swSubFeat As SldWorks.Feature
Dim swSensor As SldWorks.Sensor
Dim swDimSensor As SldWorks.DimensionSensorData
Dim sensorValue As Double
Dim text As String
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
Do While Not swFeat Is Nothing
If (swFeat.Name = "Sensors") Then
Set swSubFeat = swFeat.GetFirstSubFeature
Do While Not swSubFeat Is Nothing
Set swSensor = swSubFeat.GetSpecificFeature2
[highlight #FCE94F]swDimSensor = swSubFeat.GetSensorFeatureData[/highlight]
sensorValue = swDimSensor.sensorValue
text = (text & (swSensor.Name & ": " & sensorValue))
Set swSubFeat = swSubFeat.GetNextSubFeature
Loop
End If
Set swFeat = swFeat.GetNextFeature
Loop
MsgBox (text)
End Sub
Thanks in advance for your help!