I am attempting to use the api to run and retrieve data from motion studies with very little success. I have tried retrieving data both through sensors and through plots set up in the study. The sensor seems to be non functioning and always return 0 through the API even though it updates fine in Solidworks. When attempting to retrieve data from the plots i have very mixed success with retrieving x-valuess and RuntimeBinderExceptions when running trying to retrieve y-values
To demonstrate what i tried and what is happening i created a small example. Since Macro support for C# is apparently in pretty bad shape in 2017 i have created a small Add-in that basically just contains two buttons that can run a piece of C# code
In the attached zip file is a visual studio project and a Solidworks assembly to test with. In order to recreate the issues:
1. Open the solution in Visual studio 2015.
2. in the project references, make sure that all references to solidworks.interop dll resolves correctly to 2017 dll files.
3. Right click the MinimalExampleAddIn and go to properties.
4. In the debug tab, make sure "Start external program" is selected and points to the sldworks.exe for Solidworks 2017
5. Find the method "Macro1()" in SwAddin.cs and set a break point at the beginning.
6. Build and run the solution in debug mode
7. Open Valve_cam.sldasm located in the "support file" directory
8. Make sure to enable both SOLIDWORKS Motion and SOLIDWORKS Simulation as well as the "Minimal Example" Addin
9. In the "Minimal Example Command Manager click the "Run Macro 1" button.
You should now hit the break point set in the Macro1 method. Here is my attempts at retrieving data from a motion analysis. Both through the sensor and the Plots. Neither
Method has been succesful.
The sensor simply returns 0 even though its return value indicated that the retrieval was succesful.
I am a bit unsure whether my approach for getting data out of the plots is correct. The documentation is a bit confusing, and the only example available seem to create the axes right before they are used. There seems to be no example on how to get data from an existing plot. On these lines:
double[] ys = output.GetYAxis(yaxis);
xs becomes null and output.GetYAxis(yaxis); throws a RuntimeBinderException with the message: "Additional information: Cannot implicitly convert type 'System.DBNull' to 'double[]'"
For the second macro i tried using DispatchWrapper since one of the examples in the documentation uses this. However, this did not help.
Any information on how to retrieve data from a motion study will be greatly appreciated!