|
POST
|
I have a question about Pyscripter in which I am trying to understand. Suppose if I set up a script within Pycripter and hit the run button to check for any errors. You know if you copy the script from somewhere and paste it in Pyscripter and run it and sometimes Pyscripter does not understand but if you save it and load it in Python Window it would run fine. Why are they both different ? Here is the example: Traceback (most recent call last): File "C:\workspace\GeoTIFF.py", line 12, in <module> mxd = arcpy.mapping.MapDocument("CURRENT") NameError: name 'arcpy' is not defined I understand that the error is because Pyscripter does not understand CURRENT because it is the way that Python window understands it. Message was edited by: Robert Pollock
add the e after past = paste
... View more
02-08-2015
09:28 AM
|
0
|
1
|
4979
|
|
POST
|
Okay I finally figured it out ! Apparently the book on Chapter 7 has some errors in it as I was trying to work on them in Pyscripter and Python Window and got it worked ! This HAS nothing to do with the del cur I had to re-read the instructions and found that the chapter mention to delete two hardcoded THAT should be include in the python script ! phew ! This is the correct coding. #Script to Import data to a feature class within a geodatabase import arcpy, os arcpy.env.workspace = "C:/ArcpyBook/data/Wildfires/WildlandFires.mdb" f = open("C:/ArcpyBook/data/Wildfires/NorthAmericaWildfires_2007275.txt", "r") cur = arcpy.InsertCursor("FireIncidents") try: # the output feature class name outputFC = arcpy.GetParameterAsText(0) # the template feature class that defines the attribute schema fClassTemplate = arcpy.GetParameterAsText(1) #Open the file to read f = open(arcpy.GetParameterAsText(2), 'r') arcpy.CreateFeatureclass_management(os.path.split(outputFC)[0],os.path.split(outputFC)[1],"POINT", fClassTemplate) lstFires = f.readlines() cur = arcpy.InsertCursor(outputFC) cntr = 1 for fire in lstFires: if 'Latitude' in fire: continue vals = fire.split(",") latitude = float(vals[0]) longitude = float(vals[1]) confid = int(vals[2]) pnt = arcpy.Point(longitude, latitude) feat = cur.newRow() feat.shape = pnt feat.setValue("CONFIDENCEVALUE", confid) cur.insertRow(feat) arcpy.AddMessage("Record number " + str(cntr) + "written to feature class") cntr = cntr + 1 except: print arcpy.GetMessages() finally: del cur f.close()
... View more
02-07-2015
08:04 AM
|
0
|
0
|
2943
|
|
POST
|
Where do I find this information in an IDE ? Would Pyscripter show the avaiable variable to replace the cur ?
... View more
02-06-2015
08:19 PM
|
0
|
1
|
2943
|
|
POST
|
Thank you. That is what I thought so. Does that mean ESRI took out the cur sytanx ? Ok, I will look into that as what you suggest. I have googled it as well but did not find it. I tried cursor and it came back an error...
... View more
02-06-2015
02:35 PM
|
0
|
1
|
2943
|
|
POST
|
This is what I wrote from the book Programming ArcGIS 10.1 with Python Cookbook wrote by Eric Pimper and it is on Chapter 7th. #Script to Import data to a feature class within a geodatabase import arcpy, os arcpy.env.workspace = "C:/ArcpyBook/data/Wildfires/WildlandFires.mdb" f = open("C:/ArcpyBook/data/Wildfires/NorthAmericaWildfires_2007275.txt", "r") try: # the output feature class name outputFC = arcpy.GetParameterAsText(0) # the template feature class that defines the attribute schema fClassTemplate = arcpy.GetParameterAsText(1) #Open the file to read f = open(arcpy.GetParameterAsText(2), 'r') arcpy.CreateFeatureclass_management(os.path.split(outputFC)[0], os.path(outputFC)[1]), "point", (fClassTemplate) lstFires = f.readlines() cur = arcpy.InsertCursor(outputFC) cntr = 1 for fire in lstFires: if 'Latitude' in fire: continue vals = fire.split(",") latitude = float(vals[0]) longitude = float(vals[1]) confid = int(vals[2]) pnt = arcpy.Point(longitude, latitude) feat = cur.newRow() feat.shape = pnt feat.setValue("CONFIDENCEVALUE", confid) cur.insertRow(feat) arcpy.AddMessage("Record number" + str(cntr) + "written to feature class") cntr = cntr + 1 except: print arcpy.GetMessages() finally: del cur f.close() The error showed here Traceback (most recent call last): File "C:\ArcpyBook\Ch7\InsertWildfires.py", line 34, in <module> del cur NameError: name 'cur' is not defined
... View more
02-06-2015
02:24 PM
|
0
|
7
|
7011
|
|
POST
|
Is that for shapefiles only ? What about geodatabases ?
... View more
02-05-2015
01:59 PM
|
0
|
1
|
2744
|
|
POST
|
Is there a way for me to run a tool or script to call how many vertices of a file geodatabase polygon ?
... View more
02-05-2015
12:31 PM
|
0
|
5
|
6752
|
|
POST
|
Hi all , I am trying to write a code how to retrieve imagery from the server as a add data however I am not sure using the "layer" is the right word to call it. Writing in Pyscripter showed me the syntax check is ok however; it brings up another error saying Runtime Error: Object.Create Object cannot open map document (_base.py) What I am trying to do here is to have MapDocument open and run the script to call and add the imagery to ArcMap without having to manually add them . import arcpy, os import arcpy.mapping as mapping mxd = mapping.MapDocument("CURRENT") df = mapping.ListDataFrames(mxd) layer = mapping.Layer(r"S\Las Cruces SSO\NAIP_2009") mapping.AddLayer(df,layer,"AUTO_ARRANGE") del mxd
... View more
01-29-2015
10:53 AM
|
0
|
0
|
4020
|
|
POST
|
Xander Bakker - Yes, I've explored the Pyscripter and read the information right before you answered my question. Now, I can see why the difference between the two. Now I can see why how cool Pyscripter is !!!!
... View more
01-25-2015
02:27 PM
|
0
|
1
|
980
|
|
POST
|
One more other question. Which one should i write the code in the Pyscripter ? The python interpreter below or the top with the module ?Xander Bakker
... View more
01-25-2015
01:57 PM
|
0
|
3
|
980
|
|
POST
|
Xander Bakker ok, so for example, if you want to write one code and all of sudden it gave you the error in python window and then you turn to pyscripter and use the same one code and test it. Is that what you are suggesting ?
... View more
01-25-2015
01:45 PM
|
0
|
4
|
980
|
|
POST
|
I am trying to understand between the two Pyscripter and Python Window and how it works together. So for the Pyscripter you just write to test it and if it works you copy and paste them to the Python Window but change to the functions or classes to Python window where they understand it and run from Python windows? Or do I just write the code within the Pyscripter and run the code from there and will that change in ArcMap ? Thanks
... View more
01-25-2015
10:19 AM
|
0
|
6
|
1871
|
|
POST
|
So the Pyscripter doesnt understand so I have to manually change the mxd to something else like ?
... View more
01-25-2015
09:41 AM
|
0
|
1
|
1871
|
|
POST
|
See the error >>> mxd.replaceWorkspaces(path + r"\City_of_Westerville.mdb", "ACCESS_WORKSPACE", path + r"\Westerville.gdb", "FILEGDB_WORKSPACE") Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'mxd' is not defined
... View more
01-25-2015
09:40 AM
|
0
|
2
|
1871
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | Monday | |
| 1 | 04-08-2026 10:11 AM | |
| 1 | 09-01-2022 03:43 PM | |
| 1 | 09-28-2020 09:34 AM | |
| 2 | 09-24-2025 09:48 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|