0

I have a python script that will position the scale bar, north arrow, title, and legend on a map layout in ArcGIS Pro. This script also references a bookmark and then exports the layout to a PDF. I need to turn this script into a script tool so that it can be used in ModelBuilder, but I have no idea where to start.

Here is the python script I need to convert to a script tool in ArcGIS Pro.

# input name of layout
 p = arcpy.mp.ArcGISProject("CURRENT")
 lyt = p.listLayouts("Test")[0]
# Reposition the scale bar
 scaleBar = lyt.listElements("MAPSURROUND_ELEMENT", "Scale Bar")[0]
 mf = scaleBar.mapFrame
 scaleBar.elementPositionX = mf.elementPositionX + 0.0
 scaleBar.elementPositionY = mf.elementPositionY - 0.5
# Reposition the north arrow
 northArrow = lyt.listElements("MAPSURROUND_ELEMENT", "North Arrow")[0]
 mf = northArrow.mapFrame
 northArrow.elementPositionX = mf.elementPositionX + 8.8
 northArrow.elementPositionY = mf.elementPositionY + 0.7
# Align the title with the center of the map frame
 title = lyt.listElements("TEXT_ELEMENT","Name of Map Text")[0]
 mf = lyt.listElements('MAPFRAME_ELEMENT',"Map Frame")[0]
 title.elementPositionX = mf.elementPositionX + (mf.elementWidth / 3.7)
 title.elementPositionY = mf.elementPositionY + (mf.elementHeight / 0.98)
# Reposition the Legend and fix legend title
 legend = lyt.listElements("LEGEND_ELEMENT", "Legend")[0]
 legend.title = "Legend"
 legend.elementPositionX = mf.elementPositionX + 7.7
 legend.elementPositionY = mf.elementPositionY + 7.15
# setting layout to bookmark
 aprx = arcpy.mp.ArcGISProject("Current")
# add name of layout
 lyt = aprx.listLayouts("Test")[0]
 mf = lyt.listElements("MAPFRAME_ELEMENT")[0]
# add name of bookmark and export as PDF
 bkmks = mf.map.listBookmarks("Castro_Py")
 for bkmk in bkmks:
 mf.zoomToBookmark(bkmk)
 lyt.exportToPDF(r"C:\arcGIS_Shared\Exports" + "\\" + bkmk.name + ".pdf")
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 20, 2017 at 15:57

1 Answer 1

1

Create a script tool is the documentation for creating script tools. You need to create a new toolbox, then add your script and configure the parameters as desired.

Note that if you want to reuse this script for other projects, then you need to make the variables dynamic. use these inputs in the tool parameters pane when creating the tool.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Nov 20, 2017 at 16:52
2
  • Thanks for the resources. Just to clarify. If I don't want to reuse the script for future projects, I could just leave it as it is now??? Or do I still need the GetParameterAsText? Commented Nov 20, 2017 at 17:26
  • if its for one time use and the file paths are not changing then you dont need to prompt the user for an input Commented Nov 20, 2017 at 17:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.