POST
|
Hello good people. Just updating this thread with VBA code / tool that I have used instead of a python script. Thanks for your help everyone...I'm going out to buy some python books at lunch time in readiness for our upgrade to ArcGIS 10!
Private Sub ICEWR_Click()
On Error GoTo ERRORR
Dim pGxDialog As IGxDialog
Set pGxDialog = New GxDialog
pGxDialog.ButtonCaption = "Add"
pGxDialog.StartingLocation = "D:\Data"
pGxDialog.Title = "Add the shapefile you wish to integrate and collect events"
pGxDialog.AllowMultiSelect = True
Dim pLFilter As IGxFile
Set pLFilter = New GxFile
Dim pGxFilter As IGxObjectFilter
Set pGxFilter = New GxFilterShapefiles
Set pGxDialog.ObjectFilter = pGxFilter
Dim pLayerFiles As IEnumGxObject
pGxDialog.DoModalOpen 0, pLayerFiles
'Dim pLayerFile As IGxObject
Dim pLayerFile As IGxDataset
Set pLayerFile = pLayerFiles.Next
'Dim pGxLayer As IGxLayer
Dim pGxLayer As IFeatureLayer
Dim pGxFeatureClass As IFeatureClass
Set pGxFeatureClass = pLayerFile.Dataset
Set pGxLayer = New FeatureLayer
Set pGxLayer.FeatureClass = pGxFeatureClass
pGxLayer.Name = pGxFeatureClass.AliasName
theshapefile = pGxLayer.Name
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
pMxDoc.AddLayer pGxLayer
pMxDoc.ActiveView.Refresh
pMxDoc.UpdateContents
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
For i = 0 To pMap.LayerCount - 1
If pMap.Layer(i).Name = theshapefile Then
getindex = i
End If
Next i
Dim pl2 As IDataLayer2
Set pl2 = pMxDoc.FocusMap.Layer(getindex)
Dim pdsNAME As IDatasetName
Set pdsNAME = pl2.DataSourceName
theworkarea = pdsNAME.WorkspaceName.PathName & "\"
SF_Copy = theworkarea & theshapefile & "_copy.shp"
SF_Copier = SF_Copy & " #"
SF_COUNT = theworkarea & theshapefile & "_collectevents.shp"
SF_INTEGRATED = theworkarea & theshapefile & "_integrated.shp"
SF_Rendered = theworkarea & theshapefile & "_rendered"
toly = InputBox("Enter a tolerance value for integration please", "Tolerance")
' Create the Geoprocessor object
Set gp = CreateObject("esriGeoprocessing.GPDispatch.1")
' Load required toolboxes...
gp.AddToolbox "D:/ArcGIS/ArcToolbox/Toolboxes/Spatial Statistics Tools.tbx"
gp.AddToolbox "D:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx"
' Process: Copy Features...
gp.CopyFeatures_management theshapefile, SF_Copy, "", "0", "0", "0"
gp.Integrate_management SF_Copier, toly
gp.CollectEvents_stats SF_Copy, SF_COUNT
gp.CountRenderer_stats SF_COUNT, "ICOUNT", SF_Rendered, "5", "bright_pink", ""
Exit Sub
ERRORR:
MsgBox "You may have already run this and forgotten to delete files created last time", vbCritical, "Error" 'will add a file check and delete to overcome this problem when i get time
End Sub
... View more
12-05-2011
01:19 PM
|
0
|
0
|
500
|
POST
|
I'm going to develop this as a tool in trusty old Arcobjects VBA...it's crazy how hard it is to do something so simple... Thanks for your help folks
... View more
12-04-2011
08:00 PM
|
0
|
0
|
500
|
POST
|
How about this? shapefile = "c://temp//shapefile.shp" That's a joke, kind of. What exactly are you trying to do ? What do you mean by open? Why can't the user add a shapefile to ArcMap and then open its attribute table or what ever it wants to do there? What's the desired process or end result? What does the user need to do with the shapefile once its been opened? Jahood, do you have any input? You posed several questions and I think I answered them for you.
... View more
12-04-2011
11:13 AM
|
0
|
0
|
500
|
POST
|
Try posting your entire code, use code blocks, like this and hopefully we can get to the bottom of your problem. OK. All I want to do is add SF_RENDERED to the arcmap TOC. ArcMap session is where the script is run from (from personal arcgis tollbox).
# Import system modules
import sys, string, os, arcgisscripting
# get the shapefile
from Tkinter import *
import tkFileDialog
# Create the Geoprocessor object
gp = arcgisscripting.create()
master = Tk()
master.withdraw() #hiding tkinter window
file_path = tkFileDialog.askopenfilename(initialdir="D:\\", title="Open file", filetypes=[("Shapefile",".shp"),("All files",".*")])
if file_path.find('.shp') == -1:
print "Not a shapefile, quiting"
master.quit()
if file_path != "":
print "you chose file with path:", file_path
SF = file_path
else:
print "you didn't open anything!"
sys.exit()
def rchop(thestring, ending):
if thestring.endswith(ending):
return thestring[:-len(ending)]
return thestring
#get the tolerance
toly = 0
from tkMessageBox import askokcancel
class Quitter(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.pack()
widget = Button(self, text='Done', command=self.quit)
widget.pack(expand=YES, fill=BOTH, side=BOTTOM)
def quit(self):
gp.addmessage('You chose ' + ent.get() + ' for the tolerance...well played!')
toly = ent.get()
gp.addmessage(toly)
gp.addmessage(toly)
#local variables
SF_Copy = rchop(file_path, '.shp') + '_copy.shp'
SF_Copier = SF_Copy + " #"
SF_COUNT = rchop(file_path, '.shp') + '_collectevents.shp'
SF_Integrated = rchop(file_path, '.shp') + '_integrated.shp'
SF_Rendered = rchop(file_path, '.shp') + '_rendered'
# Load required toolboxes...
gp.AddToolbox("D:/ArcGIS/ArcToolbox/Toolboxes/Spatial Statistics Tools.tbx")
gp.AddToolbox("D:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
## Process: Copy Features...
gp.CopyFeatures_management(SF, SF_Copy, "", "0", "0", "0")
gp.addmessage('Backup copy has been made')
## Process: Integrate...
gp.Integrate_management(SF_Copier, toly)
gp.addmessage('Integration completed')
## Process: Collect Events...
gp.CollectEvents_stats(SF_Copy, SF_COUNT)
gp.addmessage('Events have been collected')
SF_COUNT = SF_COUNT.replace("/","\\")
SF_Rendered = SF_Rendered.replace("/","\\")
gp.addmessage('Creating ' + SF_COUNT)
gp.addmessage('Creating ' + SF_Rendered)
# Process: Count Rendering...
gp.CountRenderer_stats(SF_COUNT, "ICOUNT", SF_Rendered, "5", "bright_pink" ,"")
Frame.quit(self)
gp.addmessage('done and dusted')
#this bit was me having a crack at adding it to the TOC
gp.MakeFeatureLayer_management(SF_Rendered, "Untitled")
gp.RefreshActiveView()
root = Tk()
root.title("Enter the tolerance value for integrate tool")
L1 = Label(root, text="Enter the tolerance value for integrate tool (m): ")
L1.pack( side = LEFT)
ent = Entry(root)
ent.insert(0, '20')
#ent.pack(side=TOP, fill=X)
ent.pack(side=LEFT)
ent.focus()
#ent.bind('<Return>', (lambda event: quitter()))
ent.bind(toly, (lambda event: quitter()))
#btn = Button(root, text='Fetch', command=fetch)
#btn.pack(side=LEFT)
Quitter(root).pack(side=RIGHT)
root.mainloop()
... View more
12-01-2011
04:53 PM
|
0
|
0
|
500
|
POST
|
Are you running this as a script tool or as a separate instance? As a script tool
... View more
12-01-2011
10:42 AM
|
0
|
0
|
500
|
POST
|
No luck.. Here's some Pseudocode: theSession = get the current ArcMap session theSession.addlayer(layer filepath) 'add to TOC Please note, I mentioned shapefile before, but with some additions to my script it is now a .lyr file I need to add Does anyone have a code sample or could someone please expose the dark secret of how to add a layer to the TOC of the current session. Remember no arcpy (Using ArcGIS 9.3.1)!
... View more
11-30-2011
04:37 PM
|
0
|
0
|
500
|
POST
|
Doesn't matter, it is a basic tool available in any recent python package. You just use your arcgisscripting instance instead of arcpy. http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1867&pid=1865&topicname=Make_Feature_Layer_(Data_Management Cheers Matt, I'll try it out
... View more
11-30-2011
04:01 PM
|
0
|
0
|
500
|
POST
|
Thats right, however I can't use arcpy (don't have arcpy module with arcgis 9.3)
... View more
11-30-2011
12:11 PM
|
0
|
0
|
673
|
POST
|
Greetings Folks, Sorry for being too vague guys! The shapefile is created during the script (which I created using model builder then adding a few tweaks). It works fine, I have no problems with this basic scripting. All I want to do is open a shapefile that gets created during the script. At the moment the shapefile is created and after the script has run the user has to press the yellow add data button. I think this is inefficient and would like the shapefile to automatically open. Does anyone know how to open a shapefile in ArcMap using python???
... View more
11-29-2011
04:46 PM
|
0
|
0
|
673
|
POST
|
Hi Dan, I checked out the searchcursor... not sure how you use this to open a shapefile up in ArcMap. I have used cursors before in VBA code to go through each record. I call the python script from a toolbox within an open session of ArcMap. I want it to open a shapefile (chosen by the user with a dialog box). I can get the filepath to the script with the dialog box but I have no idea how to add that shapefile to the arcmap session.. It is easy with arcpy, but I don't have that luxury. Any ideas? Thanks, Josh
... View more
11-24-2011
12:03 PM
|
0
|
0
|
673
|
POST
|
Greetings, I am an amatuer when it comes to python so could someone please help with my simple questions: 1) Is the arcpy module available in ArcGIS 9.3 (I think it is 10 / python 2.6) 2) What is the python code to open a shapefile in ArcGIS 9.3 (not using arcpy module)? Thanks, Josh
... View more
11-23-2011
04:31 PM
|
0
|
19
|
1317
|
POST
|
Greetings, I need to run a batchfile that kills 1 of our SDE servers from a python script (or even better translated into python and run as part of the script). I have tried this in my script to run the batchfile:
import os
os.system("S:\1GIS\Batchfiles\Kill_Engineers.bat")
This doesn't appear to do anything. The batchfile requires a password to be entered. The batchfile has the followingh line of code:
sdemon -o kill -t all -s roc-a-a07 -i 5151
If I could do this from inside the python script it would be awesome. Any tips? Thanks, Geezer
... View more
02-01-2011
04:27 PM
|
0
|
1
|
6660
|
POST
|
Does this happen to everyone or anyone....I have comboboxes on the bottom of my form....when I click one it opens the combobox but it also opens the keyboard...Can I stop this...... Funny, I have the same problem, and only with a combobox near the bottom.
... View more
05-09-2010
08:57 PM
|
0
|
0
|
397
|
POST
|
Is the SIP checkbox ticked on or off in your combo box's properties? I have the same problem with one of my Apps. SIP is not ticked, if a check it will this solve the problem?
... View more
05-09-2010
08:53 PM
|
0
|
0
|
397
|
POST
|
I am trying to use the "GPSSTREAM" function to collect GPS points every 5 minutes till the user stops the streaming. I want the resulting vertices to become a polygon in a polygon shapefile. From a form the user clicks start, this then adds the vertices to the polygon shapefile every 5 minutes. When the user clicks stop the polygon is created from the vertices. I need help! Can't get anything into the shapefile with GPSSTREAM. HELP!!! ARRGG 😮 QUITE SIMPLE REALLY ISN"T IT....DONE!!
... View more
05-02-2010
09:41 PM
|
0
|
0
|
104
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|