1 Reply Latest reply on Dec 21, 2015 11:08 AM by Michael Nebel

    Select sensor

    Michael Nebel

      Hello!

       

      Why is it not able to select a sensor via VBA-macro?

       

      I am using the following code, but unfortunately nothing will be selected:

       

      boolstatus = swModel.Extension.SelectByID2("Stress1", "SENSOR", 0, 0, 0, True, 0, Nothing, swSelectOptionDefault)

       

      When I am recording a macro in SW, the output is the following:

       

      boolstatus = swModel.Extension.SelectByID2("Unknown", "BROWSERITEM", 0, 0, 0, False, 0, Nothing, 0)

       

      Thanks in advance

       

      Best regards

      Michael

        • Re: Select sensor
          Michael Nebel

          I have found a possibility to select the sensor, but there is no way to get the sensor data.

           

          It seems that the function GetSelectedObject6 is not working with the function Select2.

           

          Dim SwApp           As SldWorks.SldWorks

          Dim Model           As SldWorks.ModelDoc2

          Dim Matlab          As Object

          Dim Result          As Integer

          Dim bool            As Boolean

          Dim swSubFeat       As SldWorks.Feature

          Dim feat            As SldWorks.Feature

          Dim swSelMgr        As SldWorks.SelectionMgr

          Dim swSensor        As SldWorks.Sensor

          Dim boolstatus      As Boolean

          Dim swFeat          As SldWorks.Feature

          Dim value           As Double

          Dim Unit            As String

           

          Option Explicit

           

          Sub ReadSen()

           

          Set SwApp = CreateObject("SldWorks.Application")

          Set Model = SwApp.ActiveDoc

          Set Matlab = CreateObject("Matlab.Application")

          Set swSelMgr = Model.SelectionManager

          Set feat = Model.FirstFeature

           

          Do While Not feat Is Nothing

              If feat.Name = "Sensoren" Then

              bool = feat.Select2(False, -1)

              Set swSubFeat = feat.GetFirstSubFeature

              Do While Not swSubFeat Is Nothing

                  bool = swSubFeat.Select2(True, -1)

                  Set swSubFeat = swSubFeat.GetNextSubFeature

              Loop

              End If

          Set feat = feat.GetNextFeature

          Loop

           

          boolstatus = Model.Extension.SelectByID2("test", "Sensoren", 0, 0, 0, True, 0, Nothing, swSelectOptionDefault)

           

          If boolstatus = True Then

              Set swSelMgr = Model.SelectionManager

              Set swFeat = swSelMgr.GetSelectedObject6(0, -1)

              Set swSensor = swFeat.GetSpecificFeature2()

              swSensor.UpdateSensor

              bool = swSensor.GetSensorValue(value, Unit)

              Result = Matlab.PutWorkspaceData("SensorData", "base", value)

          End If

           

          End Sub