Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 11:41:41 +0000



Post From: I need automatically take screen shots of entire SC window

[2024-03-12 12:25:54]
User676363 - Posts: 72
I have a batch screenshot generator.
Save it to your ACS_Source folder in Sierrachart as screenshot.cpp
Compile it using Analysis > Build Custom Studies DLL
Add it to a chart as a custom study and it will run one round of capturing all charts in the chartbook.
Then, save that as Batch Screenshot Run+
Next time you need it, you can add it again and it will run another set of screenshots.

Ideas for improvement:
- Build a UI (I don't know how to do this yet)
- Perhaps offer some options in settings in terms of how to format the filenames
- Automatically remove the study after it has run. Sort of creates a problem for saving it as a study since it runs automatically.
No harm in really loading it multiple times and then deleting it, but maybe somebody can improve on it.


It will produce a file for each chart number in the chart book like this: 2024-03-12_08_05_37_000_xx
That gives you a yyyy-mm-dd_hh_mm_ss_mms_chartnumber which should sort nicely.



// The top of every source code file must include this line
#include "sierrachart.h"

// For reference, refer to this page:
// Advanced Custom Study Interface and Language (ACSIL)

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("Screenshot Script")

// Function to take screenshots of all chart windows in the current chartbook
SCSFExport scsf_TakeScreenshots(SCStudyInterfaceRef sc)
{

sc.GraphRegion = 1; // Use chart region #1 so as to not add another region to the existing chart just for this

// Declare and configure the Active input variable
SCInputRef Active = sc.Input[0];
Active.Name = "Active"; // Set the name of the input variable
Active.SetYesNo(1); // Set the default value - will run once
Active.SetIntLimits(0, 1); // Set the range of allowed values

// Check if the user has activated screenshot generation
if (Active.GetYesNo())
{
// Reset the active input to 0 to prevent repeated screenshot generation
Active.SetYesNo(0);
sc.AddMessageToLog("Screenshot batch start requested.", 0);

// Get the highest chart number used in the chartbook
int highestChartNumber = sc.GetHighestChartNumberUsedInChartBook();
SCString MessageText("sc.GetHighestChartNumberUsedInChartBook = ");
MessageText.AppendFormat("%d", highestChartNumber);
sc.AddMessageToLog(MessageText, 0);

// Get current date and time
SCDateTime currentDateTime = sc.CurrentSystemDateTime;

// Format date and time strings
SCString date;
date.Format("%04d-%02d-%02d", currentDateTime.GetYear(), currentDateTime.GetMonth(), currentDateTime.GetDay());

SCString time;
time.Format("%02d_%02d_%02d_%03d", currentDateTime.GetHour(), currentDateTime.GetMinute(), currentDateTime.GetSecond(), currentDateTime.GetMillisecond());

sc.AddMessageToLog("Entering loop to generate screenshots now.", 0);

// Iterate through each chart window
for (int chartNumber = 1; chartNumber <= highestChartNumber; ++chartNumber)
{
// Set the filename for the screenshot
SCString fileName;
fileName.Format("%s_%s_%d.png", date.GetChars(), time.GetChars(), chartNumber);

SCString MessageText("Writing screenshot:");
MessageText.AppendFormat("%s", fileName.GetChars());
sc.AddMessageToLog(MessageText, 0);

// Take the screenshot and save it to file
sc.SaveChartImageToFileExtended(chartNumber, fileName, 0, 0, 0);
}

// Provide feedback to the user
sc.AddMessageToLog("Screenshots generation completed.", 0);
}
}