4 Replies Latest reply on Apr 1, 2016 9:02 AM by Simon Fritz

    Get Sensor-Data and Controll Motors

    Simon Fritz



      iam looking for way to get all SENSORS in a Solidworks document to get the values. The aim is to controll Motion-motors from a small robot and synchronice it with the virtual twin. So the second question is how to get all motors?


      Iam already able to read all "FeatTypeName" but i cant get all children of the "SensorFolder". There for i used this example:

      2012 SOLIDWORKS API Help - Get Features of Multibody Sheet Metal Part Example (C#)


      I tried to  use an FeatureFolder instead of the Bodyfolder but it didnt worked. Does anyone knows how to get the Sensors and their values?




        • Re: Get Sensor-Data and Controll Motors
          Artem Taturevych

          Hi Simon,


          Please take a look at this example: #CODE|Get All Sensors



            • Re: Get Sensor-Data and Controll Motors
              Simon Fritz

              Thx!!!! That solved my problem!


              Here the C# version:

              // This Code extracts all open documents and outputs the following information about them:

              // - Pathname

              // - Count of features including subfeatures

              // - Count of toplevel features

              // - All Sensors (Name, type, value1, value2)



              ModelDoc2 swModel;

                          Feature swFeat = default(Feature);



                          string text = null;



                          int countdocuments = iSwApp.GetDocumentCount();



                          object[] models = (object[])iSwApp.GetDocuments();

                          object[] features = null;

                          object[] featurestest = null;


                          string[] pathNames = new string[countdocuments];





                          for(int i=0; i < countdocuments; i++)


                              int k = 0;

                              swModel = models[i] as ModelDoc2;



                              pathNames[i] = swModel.GetPathName();



                              swFeat = swModel.FirstFeature();




                              featurestest = (object[])swModel.FeatureManager.GetFeatures(true);



                              text = "Path and name of open document: " + pathNames[i] + "\r\n"

                                  + "hat " + swModel.GetFeatureCount() + " Features" + "\r\n"

                                  + features.GetLength(0) + "\r\n"

                                  + featurestest.GetLength(0) + "\r\n";



                              while(swFeat != null)


                                  if (swFeat.GetTypeName2() == "SensorFolder")


                                      Feature swSensorFeat = default(Feature);

                                      swSensorFeat = swFeat.GetFirstSubFeature();



                                      while(swSensorFeat != null)


                                          Sensor swSensor1 = default(Sensor);

                                          swSensor1 = swSensorFeat.GetSpecificFeature2();

                                          text = text + swSensorFeat.Name + " (Type: " + swSensor1.SensorType + " mit Wert: " + swSensor1.SensorAlertValue1 + " oder " + swSensor1.SensorAlertValue2 + ")" + "\r\n";

                                          swSensorFeat = swSensorFeat.GetNextSubFeature();



                                  swFeat = swFeat.GetNextFeature();




                • Re: Get Sensor-Data and Controll Motors
                  Ghanshyam Iratkar



                  I am looking for a way to export Proximity Sensor data/values into csv/text file or in any other file format.
                  The aim of this is to use these values in MATLAB as input values.


                  Could you please tell me how to use this code?

                  and what will be the outcome of this code?
                  I don't have that much knowledge of coding.


                  -Ghanshyam Iratkar

                    • Re: Get Sensor-Data and Controll Motors
                      Simon Fritz

                      This Line adds a string with the Information about all Sensor Features:


                      text = text + swSensorFeat.Name + " (type: " + swSensor1.SensorType + " with value1: " + swSensor1.SensorAlertValue1 + " and value2 " + swSensor1.SensorAlertValue2 + ")" + "\r\n";



                      Its part of a C# Marko, so you need the API and Visual Studio. Have you any experience in programming a C# makro? Otherwise you should try to translate the Code in VBA.