Fatigue variable amplitude macro (array problem)

Hi,

Im trying to create a macro to create multiple fatigue studies with multiple forces and time series.

I have been successful in creating the studies and the fatigue events but my problem is getting my amplitude and time series data imported correctly.

I am using this example that i want to modify to create the different events:

2015 SOLIDWORKS API Help - Create Fatigue Study Example (VBA)

I want to import my data either from a .txt file or most preferably an excel file. I have no problem to import from excel its just how to get it into the right array format.

This is where the event is created and i want the data from a file instead of written directly in the code.

    PointsX = Array(0, 1, 2, 3, 4, 5, 6.25714, 7, 8.3846, 9, 10)

    PointsY = Array(0, 11, 21, 33, 44, 21, 66.25714, 77, 88.3846, 99, 109)

    Set FatigueEvent2 = FatigueOptions2.AddFatigueEventForVariableAmplitude("Ready_Static", -0.002, 1, (PointsX), (PointsY), 0, 1#, errCode)

I would want to write something like this but it is not working:

    PointsY = exApp.Worksheets("fatiguedata").Range("B2:B12")

Anyone have any clues how to get this to work?

SolidworksApi macros
Answers 2
ST
ST 2015-07-29 Best Answer

There's probably a clever, one line piece of code that will do that. But one easy way is to add the cell values into the array one at a time:

Dim PointsX(10)

Dim i as Integer

For i = 2 to 12

     PointsX(i - 2) = exApp.Worksheets("fatiguedata").Range("B" & i).Value

Next

SF
SF 2015-07-29

Thanks! Yes i hope there is a more clever way of doing it. I did it in a similar manner as below to get it working.

 

For i = 0 To row

        PointsX(i) = exApp.Worksheets("fatiguedata").Cells(i + 2, 1)

    Next i