When I unzip the "Toolbox2" file, I get a "Toolbox2.tbx" and that's it. Putting it into Arc, there's no script file in the toolbox. Posting the Python code up here will work- I can add it to a toolbox as a script like I did the previous one. Sorry to be a pain!
*edit* Yes, I'd like to just input one ID at a time for now. I may want to be able to enter multiple ID's in the future but never all of them at the same time. Thanks!
I apologize about the first script tool I loaded, I forgot to save the script I was working on as a .py, I left it as a .txt, so it couldn't be editted from the catalog.
From your last response you seem to want to iterate over all the ID fields in a layer, and then export PDFs of each of those IDs at 3 pre-defined zooms.
I fixed my script tool, and made it take 7 parameters, that way you don't need to modify the script at all(unless you want to change how they name when they export, I've made the script export with the mxd name, then ID Number, then the Scale Number, so they are all differnt names on export. Currently the tool, will let you export them by ID one at a time, but if you need to iterate all ID's in a Layer and export them all at the same scale, then the script could be changed to do them all at once, and should be faster that way.
I've tested this script tool this time(was in a bit of a rush last time), so it should be out of the box useable, just unzip, navigate to the toolbox in ArcCatalog, open the tool, fill in the parameters and let it run. To fill in the Output Location, you can either navigate to it from the tool, or click and drag it to the input, same for the MXD parameter. For the Layer Name, make sure you copy the name exactly as it shows up in the table of contents in your map document.
Hope this does what you need, if you want it editted to do all ID's in a Layer, it should be a fairly easy adjustment.
Edit: To run the tool as is, it took my 5 year old computer about 42 seconds, hopefully yours goes a bit quicker.
Ian, I appreciate what you've done for me so far but I'm still very lost.
I've tried reading the Arc help pages, plugging in parameters, running the script in Python and in Arc (and sometimes crashing it!) but I'm just not quite getting it.
Basically all I believe that is working properly is the mxd file path. I've been able to set the parameters to return a list of layers so I can select the one where my points/table is located that I want to search but I don't know how to set up the script or the parameters to be able to search it.
Attached is a lame test file I made with random Lat/Long coordinates and other columns. I'd be trying to search for numbers in the "ID" column to zoom to and print out.
Do I need to change the .py file for every ID that I want to search for? That's what the SQL field is for in the parameters GUI, right? Ugh. So frustrating - it just hasn't clicked yet. Any more help please?
#Importing Modules import arcpy #Declaring Variables ID = arcpy.GetParameterAsText(0) OutputLocation = arcpy.GetParameterAsText(1) #Assembling Map - Selecting MXD, Dataframe, and Selecting Layer by Attribute #Creating a Map Document Object within python, referencing the .mxd you want to work with. mxd = arcpy.mapping.MapDocument(r"put filepath to your map here") #Once you have a map document object in python, you can access its various elements, now we need to access the dataframe the layer you are using is in. #The line of code below makes a list of all the dataframes in the map document object we made. The [0] returns the first dataframe in our map document, #if you need to access additional dataframes, you would use a different index, we now have made a dataframe object in python and can access the layers in it df = arcpy.mapping.ListDataFrames(mxd,"*")[0] #Now to Create a Layer Object, the line of code below returns a list of all the layers in the dataframe, with this name. The [0] returns the first layer with that name instead of the whole list Layer = arcpy.mapping.ListLayers(mxd, "Your Layer Name here", df)[0] #Selecting by Attribute, Zooming to Feature, and Setting Scale #This line performs a select by attribute on our Layer object, using a new selection, with an SQL query of ID = the ID variable we created using getparameterAsText(0) arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION" , "ID = " + ID) scales = [scale 1 here , scale 2 here, scale 3 here] for scale in scales: #Selecting by Attribute, Zooming to Feature, and Setting Scale #This line performs a select by attribute on our Layer object, using a new selection, with an SQL query of ID = the ID variable we created using getparameterAsText(0) arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION" , "ID = " + ID) #This zooms the dataframe to the selected feature df.zoomToSelectedFeatures() df.scale = scale #Clearing selected features so they do not show up selected on map arcpy.SelectLayerByAttribute_management(Layer, "CLEAR_SELECTION") #Exporting map dataframe view to pdf, I have it set up to save arcpy.mapping.ExportToPDF(mxd, OutputLocation + ID + scale + ".pdf", "Page_Layout", 640, 480) #Cleaning out memory by deleting the python objects del mxd; del df, del Layer
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.