Export Image > Tools > Customize >Tools ...Error?

// I created this below
// Saved it as ExportImage.js from notepad
// Then saved it to folder: C:\Program Files\AmiBroker\Scripts\ExportImage.js
// Tried to create it as a Tool > Customize > Tool > New > ExportImage
// Command: wscript.exe
// Arguments: C:\Program Files\AmiBroker\Scripts\ExportImage.js
// Initial Directory: C:\DataExport
// Prompt for Arguments = Blank

// Then Tried To Execute:
// With the Selected Ticker as the Active Window...
// From Upper Ribbon > Tools > I Selected > ExportImage from bottom of list available
// *** Received Error Dialog Box: "There is no file extension in C:\Program".
// The Image format is set to .png in code below and why the folder change from code?
// Why does the error reflect C:\Program and NOT C:\DataExport\ per code below?
// Where is my error?

// Saved as ExportImage.js from notepad
outputdrivepath = "C:\DataExport\";

exportpath = outputdrivepath;

var oAB = WScript.CreateObject("Broker.Application");

Ticker = oAB.ActiveDocument.Name;

AB = new ActiveXObject("Broker.Application");

AW = AB.ActiveWindow;

filename = exportpath + Ticker + ".png";

WScript.Echo("ExportImage: " + filename);

AW.ExportImage( filename, 800, 600 );

WScript.Echo("ExportImage: Done !");

// please let me know where I am in error. thanks in advance.

When posting the formula, please make sure that you use Code Tags (using </> code button) as explained here: How to use this site.

Using code button

Code tags are required so formulas can be properly displayed and copied without errors.

Unfortunately your question isn't clear enough and does not provide all necessary details to give you an answer. Please follow this advice: How to ask a good question

@Mrv, as a first step, I suggest to fix the Jscript file as follow (change the export path and image size as needed):

exportPath = "C:\\Data\\ExportedImages\\";

AB = new ActiveXObject( "Broker.Application" ); 
ticker =  AB.ActiveDocument.Name;
filename = exportPath + ticker + ".png";
AW = AB.ActiveWindow;
// WScript.Echo("Exporting image: " + filename);
AW.ExportImage( filename, 1024, 768 );
WScript.Echo("Exporting image: " + filename + " - Done!");

Then check if you have enclosed the "arguments" in double-quotes like in the example below.

image

In any case, before adding the script to the "Tools", you should check that it will work adequately, invoking it from a command prompt, externally of AmiBroker. If there are errors or JScript is not enabled, or some other kinds of issues (permissions, etc.), you need to solve them before integrating the script in the Tools menu

Tools path fixed... it did NOT have the double quotes; Thanks, working on the rest.tools_path_fixed

Moderator comment: PUT ONLY THE CODE into code tags, not entire post !

Ok, I am getting an error on line 3 >> Error 800A01A8 > See Image
Something is misspelled, I think for the "ticker" object AB.ActiveDocument.Name;
Suggestions?

 exportPath = "C:\\DataExport\\";
AB = new ActiveXObject( "Broker.Application" ); 
ticker =  AB.ActiveDocument.Name;
filename = exportPath + ticker + ".png";
AW = AB.ActiveWindow;
// WScript.Echo("Exporting image: " + filename);
AW.ExportImage( filename, 1024, 768 );
WScript.Echo("Exporting image: " + filename + " - Done!");

ExportImage.js Object Error

The supplied script work perfectly in my configuration.
Anyway, when you launch the script, do you have at least 1 chart open in your Amibroker layout?
I'm asking because the script is minimal and does not check if you have - or not - a "document" open.

On the other hand, If you have visible charts, did you test the script outside of Amibroker?
With the application closed (no instances of AB running), when you invoke the script from a command line, do you see the "splash" screen of Amibroker, confirming that OLE is working on your system?
If not, please, read this thread for a possible solution

You are not checking if ActiveDocument actually exists. You may be using wrong scripting host instance and it may be connecting to wrong instance:

1 Like

TJ,
Amibroker is great! I am stumped. Every AFL formula just Works. It's obviously me.!

I have been able to code formulas in AmiBroker successfully since way... back when.
I originally had it back when on 32Bit, then upgraded to 64Bit Pro Version, So I think its my configuration because I try to run the .js file from command line and it just opens the file rather than execute. They always come up with varying object errors or COM errors.
How can I verify the change file association to 64Bit for OLE.
AmiBroker is installed on Windows 10 in C:\Program Files\AmiBroker\Broker.exe
The script is saved to C:\Program Files\AmiBroker\Scripts
Apparently my OLE automation is wacked from my perspective...
I tried -verbatim - "http://www.amibroker.com/kb/2014/10/21/how-to-export-chart-image-to-a-file/" and it just opens the file.

Bottom Line:
***There has to be a better way...
Isn't there a "simple" way in "C" to simply stay within AFL, run Exploration, receive that exploration data AND save the Sheet 9 tab as a png 1024 by 768 to disk? Is there way to do fput or printf and write the .png to disk?
Thanks

Here is another failed attempt AFL.

//CaptureImage.afl

GraphXSpace = 15;
periods = 11;
nClose = (Close - LLV(L,periods)) / ( HHV(H,periods) - LLV(L,periods));
G0 = nClose;
WMAnClose = WMA(nClose,11);
color = IIf( G0 > 0.50, 5, 4 );
Plot(nClose,"nClose",color,styleStaircase);
Plot(MA(nClose,3),"MA3nClose",4,styleStaircase);
Plot(0.83,"",7,1);
Plot(0.50,"",2,1);
Plot(0.17,"",7,1);
PlotOHLC( G0,G0,0.50,G0, "", IIf( G0 > 0.50, 5, 4 ),  styleCloud | styleOwnScale | styleNoLabel | styleClipMinMax, 0.50, 0.50); 

//sample exploration code 

Filter = Cross(nClose, 0.50); //For Educational Purposes Only 

//remove /* //Commented out due to error

exportpath = "C:\\DataExport\\";
fmkdir( exportPath ); // Create the path if it does not exists
filename = exportpath;
/*
{
AB = new ActiveXObject("Broker.Application");
stks = AB.Stocks;
Qty = AB.Stocks.Count;
for ( i = 0; i < Qty; i++ )
Stk = AB.Stocks( i );
myDate = DateTimeFormat("%m-%d-%Y");
AB.ActiveDocument.Name = Stk.Ticker;
AW = AB.ActiveWindow.SelectedTab = 8;
AW.Activate();
AW.ExportImage( filename + Name() + "_" + myDate + "_" +".png");
}
*/

MrV

Clicking on a filename invokes the application associated with its file extension. Probably in your system, you have associated the .js extension to a code / text editor (this is quite common, and I have it also in my system).

Try to run the script from the command line:

  1. Open a command window and change the directory to the path of the script.
  2. At the command-line prompt type: wscript nameofyourscript.js

image

Optionally, modify the script to check for empty layouts:

exportPath = "C:\\Data\\ExportedImages\\";

AB = new ActiveXObject( "Broker.Application" ); 
ABDocs = AB.Documents;
if (ABDocs.Count > 0) {
    ticker =  AB.ActiveDocument.Name;
    filename = exportPath + ticker + ".png";
    AW = AB.ActiveWindow;
    // WScript.Echo("Exporting image: " + filename);
    AW.ExportImage( filename, 1024, 768 );
    WScript.Echo("Exporting image: " + filename + " - Done!");
} else {
    WScript.Echo("ERROR - No open charts in the current layout.");
}    

If you still get errors, try the suggestion I linked in post #7. Then report back.

How does one code the system.drawing image.save method parameters in AFL properly?
see link below
What is the best way to do this in AFL?
Thanks in advance.

In AFL, upon scan or Exploration, Save Sheet(6) image to "C:\DataExport\" as .png 1024 X 768
Image Filename format: Ticker + "" + MM-DD-YY + "" + ".png";

// Scan or Exploration
Buy = Close > 2800.00;
Filter = Close > 2800.00;
AddColumn( Close, "Close", format = 1.4, textColor = colorDefault, bkgndColor = colorDefault ) ;
//Result is about 20+ ticker symbols, so there should be 20+ images in the folder

Thanks
System.Drawing Image.Save Method

AmiBroker is NOT written in DOT NET, so the link you gave is not relevant to AFL.

Chart images can only be saved using AmiBroker's object interface described in manual http://www.amibroker.com/guide/objects.html

It was already discussed on this list many many times, use search: https://forum.amibroker.com/search?q=exportimage

1 Like

Hello @MrV

i think is better to keep one thread to post all your question about the same subject. Sorry but as i can see, you open every day a new thread for the same project.
So now i am going to share in this thread my thoughts.

again Hello @MrV

I am just thinking loud.

What about if…

  1. 1st Run your exploration, and if any BUY signal then store in StaticVarSetText() the Name() of the ticker

  2. 2nd after exploration is finish
    call this StaticVarGetText() in a loop and ExportImage

i hope it helps And I bet this is doable and easy code

1 Like

Awesome suggestions, let me look into that. Thanks!

1 Like

Beppe,
SUCCESS! You (and TJ) are AMAZING! Thank You!
I opened AmiBroker to the desired sheet tab.
I changed the output path to the directory in my PC in the code and save the new file to the Scripts directory. Then, I first tried a CMD prompt with C:\Program Files\AmiBroker\Scripts>wscript ExportImage.js as the image above and got access denied.
Then, I tried C:\Program Files\Amibroker\Scripts>wscript.exe ExportImage.js and IT WORKED!
Thanks again!!! , MrV

Now, I need to find the Exploration code to read the symbols in Watchlist 10 and loop thru the script trigger for ShellExecute wscript.exe ExportImage.js until done, then delete the symbols in Watchlist 10.

PanoS,
Thank you again for the Awesome suggestions!
MrV

How does one properly control the jscript export image elements of Border size, color, and style?
Where is my error in this?

exportPath = "C:\\DataExport\\";

AB = new ActiveXObject( "Broker.Application" ); 
ABDocs = AB.Documents;

if (ABDocs.Count > 0) {
    ticker =  AB.ActiveDocument.Name;
    filename = exportPath + ticker + "_Portrait_" + ".png";
    AW = AB.ActiveWindow;
	//////Add Colored / Styled Border///////////
	 AB.object.style.borderImageWidth="10px" 
	 AB.object.style.borderColor="#00ff00 green"
	 AB.object.style.borderStyle="solid"
	/////////////////////

    //WScript.Echo("Exporting image: " + filename);
    AW.ExportImage( filename, 640, 480 );
    //WScript.Echo("Exporting image: " + filename + " - Done!");

} else {
    WScript.Echo("ERROR - No open charts in the current layout.");
}  

I'm sure someone will have a one line solution :wink:
Thanks is advance

Indeed:

“You better do this processing outside of AmiBroker.” :upside_down_face:

The ONLY methods and properties available in the AmiBroker OLE model are the ones described in the documentation.

If you want to add some fancy graphics attributes to your saved images, I suggest running an external script capable of achieving the desired result after exporting them.

For a plain border, there is a possible alternative: you could use some low level graphic functions to DRAW the desired effect around your charts, before exporting them, but IMO, doing it externally of the AmiBroker application, starting from clean images, is better.

2 Likes

Pillow FTW

1 Like

From where did you got that? Nothing like that is present in the documented OLE interface http://www.amibroker.com/guide/objects.html
Obviously calling non-existing objects/methods/properties will result in an error.

As others noted, if you want some extra borders you have to add it yourself, after chart image is exported.

Ok, thank you. I will look into an external method.