LAYOUT.sml

  Download

More scripts: Layout

Syntax Highlighing:

comments, key words, predefined symbols, class members & methods, functions & classes
            
# LAYOUT.SML;
# sample script for tutorial Writing Scripts in SML.
# demonstrates reading an existing hardcopy layout from a Project File, adding a spatial
# data layer to the spatial group in the layout, and rendering the layout to a PDF file.
# 30 December 2009.
clear();
# select the color.rvc Project File
class STRING filename$;
class STRING prompt$ = "Select the color.rvc Project File from the Color folder in the TNT sample data:";
filename$ = GetInputFileName(_context.ScriptDir, prompt$, "rvc");
print(filename$);
# select a filename for the output PDF file
class STRING outPDFfile$;
outPDFfile$ = GetOutputFileName(_context.ScriptDir + "/DEM_LAYOUT", "Please name the output PDF file:", "pdf");
# open the HazZones vector object in color.rvc using the filepath and object path
class FILEPATH inFilepath(filename$);
class STRING objectPath = "HazZones.Vector";			# object path of the HazZones vector object
class RVC_VECTOR HazZones;
HazZones.OpenByName(inFilepath, objectPath, "Write"); 
# read the hardcopy layout object in color.rvc 
class GRE_LAYOUT layout;
layout.Read(filename$, "DEM_LAYOUT");
# get the handle for the first group in the layout, which is the only spatial group
class GRE_GROUP mapGroup;
mapGroup = layout.FirstGroup;
# add the HazZones vector object to the map group in the layout
class GRE_LAYER_VECTOR vectLayer;
vectLayer = GroupQuickAddVectorVar(mapGroup, HazZones);
# the HazZones vector has been added as the top layer in the group, above the map grid layer;
# lower the vector layer one level so that is is below the map grid
LayerLower(vectLayer); 
######################
# set up PDF file to render the modified layout to
class FILEPATH pdfPath(outPDFfile$);
if(pdfPath.Exists() ) then pdfPath.Delete();		# delete existing PDF file if found; otherwise will add page to existing file
class PDF pdf;
pdf.SetPath(pdfPath);			# set the filepath to the output PDF file
pdf.SetLayout(layout);		# set the layout to render to PDF
pdf.EmbedFonts(0);				# don't embed fonts
pdf.SetResolution(150);		# set a resolution for the PDF file in dots per inch
pdf.Write();								# write the PDF file
# cleanup
HazZones.Close();
layout.Destroy();
print("Done.");