Home Forums General XMetaL Discussion Dynamically hide images in large documents by default? Reply To: Dynamically hide images in large documents by default?

Derek Read

Reply to: Dynamically hide images in large documents by default?

If you put the following into an event macro named On_Document_Open_Complete inside the document-level MCR file for your customization, or in an event macro named On_Application_Document_Open_Complete for an application-level MCR file (one in Startup) you will be part way there.

[code] var nodes = ActiveDocument.getNodesByXPath(“//image”);
var tooManyImagesForMe = 200;
if(nodes.length > tooManyImagesForMe) {
var response = Application.MessageBox(“This document has a lot of images.nWould you like to disable image rendering?nn(this is a global setting that affects all documents)”,36);
if(response == 6) { //6 = yes
//turn “show inline images” off
Application.IniVariable(“show_inline_images”) = “false”;

Answers to some (anticipated) questions:

1. This is using the global setting (as set in Tools > Options on the View menu) and so it affects all documents, currently open or to be opened. User can turn it back on in Tools > Options.

2. You might want to re-enable the setting when the document is closed. If not, the user needs to go into Tools > Options and enable it themselves. The logic for that might be to simply call Application.IniVariable("show_inline_images") = "true"; However, if you have two such documents open then, without additional logic, closing one would re-enable the setting and the other doc would then have its images rendered. So, you'd probably want to store another global variable somewhere that keeps track of how many such documents are open. Then when the last one is closed you would enable the setting (probably in the On_Document_Close event). Or you might provide a separate macro for the user to run to toggle the feature back on. You might also want to turn the setting back on when XMetaL Author shuts down.

3. An alternative method for doing this, specifically for SVG or other image types that are not drawn natively, might be to add logic into the On_Should_Create event that tells XMetaL Author whether to run the code in On_Initialize for the ActiveX control that renders your SVG (which is probably Internet Explorer). This would then only affect SVG images. You would probably have a similar macro to what I've listed above, but instead of toggling inline images off it would just check how many of a given element there are (same logic as above) then set some variable you choose that means “don't draw SVG images for this document” (you may need to use the CustomDocumentProperties API to pass values between macros). Then your On_Should_Create macro could check to see if that value is set to “don't draw SVG images for this document” and if it is then On_Should_Create would be set to “false” (which means that On_Initialize won't run). The On_Should_Create will run very briefly for every image in the document, so it might be very slightly slower than turning show_inline_images off, but when compared to instantiating 1000 embedded copies if Internet Explorer it should