API Accessing Spectrum Points Keeps Showing 0

API Accessing Spectrum Points Keeps Showing 0

WALIDGIO
Advocate Advocate
503 Views
6 Replies
Message 1 of 7

API Accessing Spectrum Points Keeps Showing 0

WALIDGIO
Advocate
Advocate

 

I created a spectral case with points using the Robot API, and the Case.Records.Count shows the correct number of points. However, when I try to retrieve the points using Spectrum.Points.Count, it always returns 0. How can I correctly access the points of an existing spectrum via the API?

WALIDGIO_0-1738182728134.png

 

 

Code:

 

 

Declare and initialize the Robot application variable
    Dim robApp As IRobotApplication
    Set robApp = New RobotApplication

    ' Declare variables for Robot case and parameters
    Dim RobotServerCas As RobotCaseServer
    Dim SeismicCase As RobotSimpleCase
    Dim SeismicParams As RobotSpectralAnalysisParams
    Dim Spectrum As RobotSpectralAnalysisSpectrum
    
    ' Set up the Robot Structure Cases
    Set RobotServerCas = robApp.Project.Structure.cases
    
    ' Find the first seismic case
    Dim i As Integer
    For i = 1 To RobotServerCas.GetAll().Count
        Dim robotCase As IRobotCase
        Set robotCase = RobotServerCas.Get(i)
        
        If robotCase.Nature = I_CN_SEISMIC Then
            Set SeismicCase = robotCase
            Exit For
        End If
    Next i

    ' Validate if a seismic case was found
    If SeismicCase Is Nothing Then
        MsgBox "Error: Could not find a seismic case.", vbCritical, "Error"
        Exit Sub
    End If
    
    ' Get the analysis parameters and spectrum
    Set SeismicParams = SeismicCase.GetAnalysisParams()
    Set Spectrum = SeismicParams.Spectrum
    
    ' Check the point count
    Dim PointCount As Long
    PointCount = Spectrum.Points.Count

 

 

Any help would be appreciated!

0 Likes
Accepted solutions (3)
504 Views
6 Replies
  • API
Replies (6)
Message 2 of 7

Stephane.kapetanovic
Mentor
Mentor

Hi @WALIDGIO 

It seems that you are responding to your topic posted here: [  https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-spectral-eccentricity-access/td-p... ].

Why redefine the points in each case if you already know how to generate them from an Excel table?

Why not create an *.spe file and save it under cfgusr (SaveToFile) ? That way, you could reload the points using the LoadFromFile command without having to iterate again.

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
Message 3 of 7

WALIDGIO
Advocate
Advocate

Hello Stephane,
In fact I already know to create new Spectrum, but what I'm trying to do know is just to update only the X Y Direction, and keep the original spectrum as it is.
so my logic is to retrieve all the original spectrum parameter and assign them again to the updated one except the direction (the one i want to update), that's why my old post is not the response I'm looking for. 

like you see above I tried to iterate through the point but it seems the API have limitation in this part, and I did also tried to use the (SaveToFile),(LoadFromFile) methods but if fails also the file creating is not having the point unfortunately, that's why for me both method failed.


As you can see in these screenshots

 

WALIDGIO_0-1738229207615.png

WALIDGIO_1-1738229322815.png


I tried also the .spe , but the same result

WALIDGIO_2-1738230145317.png

 



here the code

 

  ' Get the analysis parameters and spectrum
    Set SeismicParams = SeismicCase.GetAnalysisParams()
    Set Spectrum = SeismicParams.Spectrum
    
    ' Define the file path for saving and loading spectrum points
    Dim filePath As String
    filePath = "C:\RPA24Spectrum.txt"
    
    ' Save the spectrum points to a file
    Spectrum.SaveToFile filePath
    
    ' Create a new spectrum object to load the points from the file
    Dim NewSpectrum As RobotSpectralAnalysisSpectrum
    Set NewSpectrum = New RobotSpectralAnalysisSpectrum
    
    ' Load the spectrum points from the file into the new spectrum object
    NewSpectrum.LoadFromFile filePath, "SipectrumRPA24-X"
    
    ' Optionally, delete the file after loading the points
    Kill filePath
    
    ' Now you can access the points from the NewSpectrum object
    Dim PointCount As Long
    PointCount = NewSpectrum.Points.Count

 

 

 

0 Likes
Message 4 of 7

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

hi @WALIDGIO 

'[...]
  Dim Path As String, File As String, Ext As String, FullName As String
  Path = "C:\Users\____\AppData\Roaming\Autodesk\Autodesk Robot Structural Analysis Professional 20XX\CfgUsr\"
  File = "SpectrumRPA"
  Ext = ".spe"
  FullName = Path & File & Extension
'[...]
  Dim Pts As Variant
  Pts = Array(Array(0#, 0.01), _
              Array(0.1, 0.02), _
              Array(0.2, 0.04), _
              Array(0.3, 0.06), _
              Array(0.4, 0.08), _
              Array(0.5, 0.1), _
              Array(0.6, 0.18), _
              Array(0.7, 0.06), _
              Array(0.8, 0.04), _
              Array(0.9, 0.02), _
              Array(1#, 0.01))
'[...]
      With .Spectrum
        .Name = "SpectrumRPA24-X"
        .Damping = 0.1
        .AbscissaXAxis = I_SAAXAT_PERIOD
        .OrdinateYAxis = I_SAOYAT_ACCELERATION
        .OrdinateYAxisLogarithmicScale = False
        With .Points: .Clear
          For Each Pt In Pts: .Add Pt(0), Pt(1): Next
          .SaveToFile FullName
        End With
      End With
'[...]
  Dim SpectralCaseY As RobotSimpleCase
  Set SpectralCaseY = Cases.CreateSimple(Cases.FreeNumber, "Spectrale Dir. masses Y", I_CN_SEISMIC, I_CAT_DYNAMIC_SPECTRAL)
  With SpectralCaseY
    With .GetAnalysisParams
      With .Spectrum
        .Name = "SpectrumRPA24-Y"
        .Points.LoadFromFile FullName
      End With
      With .ExcitationDir: .X = 0: .Y = 9.81 * yFactor: .Z = 0: End With
    End With
  End With
  SpectralCaseY.SetAnalysisParams SpectralParams
'[...]

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 5 of 7

WALIDGIO
Advocate
Advocate

yeah, but I'm stuck in the part to retrieve the point from an existing spectrum in the project.

0 Likes
Message 6 of 7

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

Instead of creating a case, read the one you want to check, save the points and add or transform the file. 

Stephanekapetanovic_0-1738251390056.png

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 7 of 7

Stephane.kapetanovic
Mentor
Mentor
Accepted solution

hi @WALIDGIO 

In the case of spectrum points, since the Get function seem protected, you can try reading the points until the condition is met

'[...]
      With .Spectrum
        With .Points
          Dim LastPoint As Boolean, x_ As Double, y_ As Double, PtsCount As Long, i As Long: i = 0
          Do
            i = i + 1: .Get i, x_, y_: LastPoint = x_ = -1 And y_ = -1
            If Not LastPoint Then Debug.Print i, x_, y_
          Loop Until LastPoint
          PtsCount = i - 1
        End With
      End With
'[...]

Best Regards

 

 

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes