Login Page - Create Account

Support Board


Date/Time: Tue, 15 Apr 2025 13:28:28 +0000



Post From: sc.GetStudyIDByIndex / sc.GetStudyIDByName always return 0

[2025-04-11 12:21:07]
User431178 - Posts: 646
S_ID is not anything to do with sc.StudyGraphInstanceId

In the chart studies window, studies to graph box, you have:
- Index as the left most number
- ID (aka StudyGraphInstanceId) as the next (ID:#)
- Lastly, after the study name you have the S_ID number (that which you use in sc.AddStudy)


Anyway, as I said, the other study data is not available at the same time as you initially add the study in your function, therefore the testing you are doing is fundamentally flawed.

The code below works ok for me, each time it is run a new study is added, then on the next run that study is found using sc.GetStudyIDByIndex.



SCSFExport scsf_GetStudyInformation(SCStudyInterfaceRef sc)
{
  if (sc.SetDefaults)
  {
    sc.GraphName = "Study Information";
    sc.GraphRegion = 0;
    sc.AutoLoop = 0;
    sc.ValueFormat = VALUEFORMAT_INHERITED;
    sc.ScaleRangeType = SCALE_SAMEASREGION;
    sc.GlobalDisplayStudySubgraphsNameAndValue = 0;
    sc.DisplayStudyInputValues = 0;
    sc.HideDLLAndFunctionNames = 1;

    sc.Input[0].Name = "Chart Number";
    sc.Input[0].SetChartNumber(0);

    sc.Input[1].Name = "Study to Add Internal ID";
    sc.Input[1].SetInt(19); // ATR

    return;
  }

  if (sc.UpdateStartIndex != 0)
    return;

  const auto chartNumber = sc.Input[0].GetChartNumber();
  const auto identifier = sc.Input[1].GetInt();

  if (chartNumber == 0
    || identifier <= 0)
    return;

  auto addStudy = n_ACSIL::s_AddStudy{};

  addStudy.ChartNumber = chartNumber;
  addStudy.StudyID = identifier;

  const auto result = sc.AddStudyToChart(addStudy);

  if (result != 0)
    sc.AddMessageToLog(SCString().Format("Result = %d | Study with internal ID %d added to chart number %d"
                      , result
                      , identifier
                      , chartNumber), 0);

  auto studyIndex{ 1 };

  while (true)
  {
    const auto id = sc.GetStudyIDByIndex(chartNumber, studyIndex++);

    if (id <= 0)
      break;

    const auto studyName = sc.GetStudyNameFromChart(chartNumber, id);

    sc.AddMessageToLog(SCString().Format("Study ID: %d, Name: %s"
                      , id
                      , studyName.GetChars()), 0);
  }
}