×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SolidWorks API Dimension Sensor Value

SolidWorks API Dimension Sensor Value

SolidWorks API Dimension Sensor Value

(OP)
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):

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
                
                swDimSensor = swSubFeat.GetSensorFeatureData
                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!

RE: SolidWorks API Dimension Sensor Value

Why not just add a driven dimension in the sketch and then get it (and its value) using ModelDoc2::Parameter?

RE: SolidWorks API Dimension Sensor Value

Dim swApp As SldWorks.SldWorks
Dim swDim As SldWorks.Dimension
Sub main()

Set swApp = Application.SldWorks
Set swDim = swApp.ActiveDoc.Parameter("SomeDrivenDimension@AComplexSketch")
MsgBox "Value is: " & swDim.GetUserValueIn(swApp.ActiveDoc)
End Sub

RE: SolidWorks API Dimension Sensor Value

(OP)
Wow! Thanks! Somewhere along the way I forgot about that possibility!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

White Paper - PLM and ERP: Their Respective Roles in Modern Manufacturing
Leading manufacturers are aligning their people, processes, and tools from initial product ideation through to field service. They do so by providing access to product and enterprise data in the context of each person’s domain expertise. However, it can be complicated and costly to unite engineering with the factory and supply chain. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close