POST
|
I am trying to convert some python script to display a table (based on a dbf) of features located within a specific data driven page. So far, I have the script successfully able to refresh the map to the specific table, but it does not update the table. I have it set-up as three text boxes that should be updated with three specific fields when the user runs the script from ArcToolbox. Any suggestions on why my table is not updating?
#Reference current MXD
mxd = arcpy.mapping.MapDocument("current")
#Get input parameter
Name = arcpy.GetParameterAsText(0)
#Reference data frames
mapatlasDF = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
locatorDF = arcpy.mapping.ListDataFrames(mxd, "Locator Map")[0]
#Reference appropriate layers
atlasLyr = arcpy.mapping.ListLayers(mxd, "PinalCreekMapAtlas_HalfMile", mapatlasDF)[0]
locatorLyr = arcpy.mapping.ListLayers(mxd, "Locator Map", locatorDF)[0]
atlasoutlineLyr = arcpy.mapping.ListLayers(mxd, "Map Atlas Outline", locatorDF)[0]
#Reference layout elements by calling ListLayoutElements
for elm in arcpy.mapping.ListLayoutElements(mxd):
if elm.name =="Table1Column1": tab1Col1Txt = elm
if elm.name =="Table1Column2": tab1Col2Txt = elm
if elm.name =="Table1Column3": tab1Col3Txt = elm
#Reference the Data Driven Page object
ddp = mxd.dataDrivenPages
#Set the current page to be the one selected in the script tool
arcpy.AddMessage(Name)
pageID = mxd.dataDrivenPages.getPageIDFromName(str(Name))
mxd.dataDrivenPages.currentPageID = pageID
#Set the appropriate definition queries
atlasLyr.definitionQuery = "Name = '" + Name + "'"
locatorLyr.definitionQuery = "Name = '" + Name + "'"
atlasoutlineLyr.definitionQuery = "Name <> '" + Name + "'"
#Update Sheet Index data frame
arcpy.SelectLayerByAttribute_management(locatorLyr, "NEW_SELECTION", "\"Name\" = '" + Name + "'")
locatorDF.panToExtent(locatorLyr.getSelectedExtent())
#Reference Affected Parcels table and select appropriate records
parcelTable = arcpy.mapping.ListTableViews(mxd, "AffectedParcels")[0]
#Build query and create search cursor to loop through rows
parcelFieldValue = "Page " + Name
queryExp = "\"MapPage\" = '" + parcelFieldValue + "'" #e.g., "MapPage" = 'Page 01'
parcelRows = arcpy.SearchCursor(parcelTable.dataSource, queryExp)
#Clear all table text values
tab1Col1Txt.text = " "; tab1Col2Txt.text = " "; tab1Col3Txt.text = " "
#iteate through each row, update appropiate text
count = 0
for row in parcelRows:
if count < 30: #Table1 - static position
tab1Col1Txt.text = tab1Col1Txt.text + row.getValue("OwnerName") +"\n"
tab1Col2Txt.text = tab1Col2Txt.text + row.getValue("APN") + "\n"
tab1Col3Txt.text = tab1Col3Txt.text + row.getValue("LengthTrail") + "\n"
if count ==30:
arcpy.AddMessage("Table Overflow") #The code could be reworked to show the last 90 records
count = count + 1
arcpy.RefreshActiveView()
arcpy.AddMessage("PROCESS COMPLETED")
... View more
04-30-2012
09:26 AM
|
0
|
1
|
582
|
POST
|
I am using ArcPad 10 on a TopCon GRS-1 unit and haven't had any problems until yesterday. When I ArcPad on the unit I recieve the error: a problem has occurred with ArcPad.exe and the error log says: EvntType: WinCE501bExceptio AppNam: ArcPad.exe ModNam: coredll.dll OwnName: ArcPad.exe any suggestions other than uninstall/re-install ArcPad?? Thanks in advance!
... View more
02-14-2012
11:03 AM
|
0
|
1
|
489
|
POST
|
Actually..Just figured it out..if I comment out the Editor.StartOperation it works like a charm!! THANKS for your help!!
... View more
01-09-2012
07:49 AM
|
0
|
0
|
1350
|
POST
|
below c# snippet might be helpful. You may have to convert it to vb.net ISelectionSet2 pSelSet2 = pSelSet as ISelectionSet2 ; pSelSet2.Update(null,false, out pCursor); Thank you!! That worked great. My only problem now, if I make changes to one feature, it saves edits and closes the form. If I try to make changes to another feature QUOTE]System.Runtime.InteropServices.COMException was caught ErrorCode=-2147467259 Message="Error HRESULT E_FAIL has been returned from a call to a COM component." Source="ESRI.ArcGIS.Editor" StackTrace: at ESRI.ArcGIS.Editor.IEditor.StartOperation() at ImprovementProjectsLines.ImprovementLines.cmdUpdate_Click(Object sender, EventArgs e) in X:\PhyllisTemp\ImprovementProjectsLines\ImprovementProjectsLines\ImprovementLines.vb:line 89 InnerException: Full code: Try
Dim pMxDoc As IMxDocument
pMxDoc = My.ArcMap.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureSelection
'Get a reference to the editor.
Dim editor As IEditor
editor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")
'Get Crossings FeatureLayer
Dim pFeatLyr As IFeatureLayer
pFeatLyr = GetLayerByTOC("TransportationImprovementProjects_Lines")
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFeatLyr
'If not editing, start editing dataset's Workspace
If editor.EditState <> esriEditState.esriStateEditing Then
editor.StartEditing(pEditDataset.Workspace)
editor.StartOperation()
End If
'Get SelectionSet
Dim pSelSet As ISelectionSet
pSelSet = GetSelection(pFeatLyr)
'Get FeatureCursor from SelectionSet
Dim pFCursor As IFeatureCursor = Nothing
pSelSet.Search(Nothing, False, pFCursor)
Dim pSelSet2 As ISelectionSet2 = CType(pSelSet, ISelectionSet2)
pSelSet2.Update(Nothing, False, pFCursor)
'Initialize first (only) feature
Dim pFeat As IFeature
pFeat = pFCursor.NextFeature
'Update attributes with user input
'Fill in Attributes of selected feature in User Form
Do Until pFeat Is Nothing
pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text
pFCursor.UpdateFeature(pFeat)
pFeat = pFCursor.NextFeature
Loop
'Stop editing and save edits
editor.StopEditing(True)
'Close form
Me.Close()
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.ToString, "error")
... View more
01-09-2012
07:36 AM
|
0
|
0
|
1350
|
POST
|
Use IFeatureClass.Update to populate IFeatureCursor. Thanks for your reply..I don't use IFeatureClass, so I have pFCursor.UpdateFeature(pFeat). I believe that is the same code???
... View more
01-09-2012
06:44 AM
|
0
|
0
|
1350
|
POST
|
I have a form that allows users to update attribute information for selected features...but I'm recieving the error: "Exception from HRESULT: 0x80041051" when it tries to update the data. I'm using VB.net, Visual Studio Express 2008 and ArcGIS 10. Any suggestions on where I went wrong with updating the data? System.Runtime.InteropServices.COMException was caught ErrorCode=-2147217327 Message="Exception from HRESULT: 0x80041051" Source="ESRI.ArcGIS.Geodatabase" StackTrace: at ESRI.ArcGIS.Geodatabase.IFeatureCursor.UpdateFeature(IFeature Object) at ImprovementProjectsLines.ImprovementLines.cmdUpdate_Click(Object sender, EventArgs e) InnerException: CODE: Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Try
Dim pMxDoc As IMxDocument
pMxDoc = My.ArcMap.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureSelection
'Get a reference to the editor.
Dim editor As IEditor
editor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")
'Get Crossings FeatureLayer
Dim pFeatLyr As IFeatureLayer
pFeatLyr = GetLayerByTOC("TransportationImprovementProjects_Lines")
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFeatLyr
'If not editing, start editing dataset's Workspace
If editor.EditState <> esriEditState.esriStateEditing Then
editor.StartEditing(pEditDataset.Workspace)
End If
'Get SelectionSet
Dim pSelSet As ISelectionSet
pSelSet = GetSelection(pFeatLyr)
'Get FeatureCursor from SelectionSet
Dim pFCursor As IFeatureCursor
pSelSet.Search(Nothing, True, pFCursor)
'Initialize first (only) feature
Dim pFeat As IFeature
pFeat = pFCursor.NextFeature
'Update attributes with user input
'Fill in Attributes of selected feature in User Form
Do Until pFeat Is Nothing
pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text
pFCursor.UpdateFeature(pFeat)
'pFeat = pFCursor.NextFeature
Loop
'Stop editing and save edits
editor.StopEditing(True)
'Close form
Me.Close()
Catch ex As Exception
Windows.Forms.MessageBox.Show(ex.ToString, "error")
End Try
End Sub
Public Function GetSelection(ByVal pFeatLyr As IFeatureLayer) As ISelectionSet
'Gets selection of feature layer and returns selection set
'Initialize the required variables
pMxDoc = My.ArcMap.Application.Document
Dim pFeatSel As IFeatureSelection
pFeatSel = pFeatLyr
GetSelection = pFeatSel.SelectionSet
End Function
Public Function GetLayerByTOC(ByVal lyrName As String) As IFeatureLayer
'This function finds a feature layer based on its TOC Name
'Initalize global variables
pMxDoc = My.ArcMap.Application.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim lyrCntr As Integer
Dim pFeatLyr As IFeatureLayer
For lyrCntr = 0 To pMap.LayerCount - 1
'Ensure that the layer is valid
If pMap.Layer(lyrCntr).Valid = True Then
'Ensure that the layer is a feature layer
If TypeOf pMap.Layer(lyrCntr) Is IFeatureLayer Then
pFeatLyr = pMap.Layer(lyrCntr)
If UCase(pMap.Layer(lyrCntr).Name) = UCase(lyrName) Then
GetLayerByTOC = pFeatLyr
Exit Function
End If
End If
End If
Next lyrCntr
Return Nothing
'Layer not found. Show a message
MsgBox("Layer " & lyrName & " not found !", vbCritical, "Error")
End Function
... View more
01-09-2012
05:19 AM
|
0
|
9
|
5764
|
POST
|
I changed my code some...and all of the errors are out of my program, except I get an error in my immediate window that says:" Am I not referencing the Editor or another toolbar correctly? Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Dim pEnumLayer As IEnumLayer
Dim player As ILayer
Dim editor As IEditor
editor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")
pMxDocument = My.ArcMap.Application.Document
pMap = pMxDocument.FocusMap
pEnumLayer = pMap.Layers
pEnumLayer.Reset()
player = pEnumLayer.Next
Dim pMxDoc As IMxDocument
pMxDoc = My.ArcMap.Document
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureSelection
'Verify there are layers located in Map
Dim Count As Integer
For Count = 0 To pMap.LayerCount - 1
'Get the Transportation Improvement Line Layer from the Map
If pMap.Layer(Count).Name = "TransportationImprovementProjects_Lines" Then
pFLayer = pMap.Layer(Count)
Dim pFCursor As IFeatureCursor = Nothing
pFLayer.SelectionSet.Search(Nothing, False, pFCursor)
Dim pF As IFeature
pF = pFCursor.NextFeature
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFLayer
If editor.EditState <> esriEditState.esriStateNotEditing Then
editor.StartEditing(pEditDataset.Workspace)
End If
'Update attributes with user input
If pFLayer.SelectionSet.Count <> 0 Then
pF.Value(pF.Fields.FindField("YEAR")) = txtPrjYear.Text
pF.Value(pF.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pF.Value(pF.Fields.FindField("LOCATION")) = txtLocation.Text
pF.Value(pF.Fields.FindField("AGENCY")) = txtAgency.Text
pF.Value(pF.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pF.Value(pF.Fields.FindField("COST")) = txtCost.Text
pF.Value(pF.Fields.FindField("DATEEDITED")) = txtDate.Text
pF.Value(pF.Fields.FindField("USEREDITED")) = txtUser.Text
End If
pF.Store()
End If
Next Count
'Stop editing and save edits
editor.StopEditing(True)
'Kill form
Me.Close()
End Sub
... View more
01-07-2012
07:57 AM
|
0
|
0
|
462
|
POST
|
I have an error on my pfCursor..wonder if this is the problem? Error: 'pFCursor' is passed by reference before it has been assigned a value. A null reference exception could result at runtime. Dim pFCursor As IFeatureCursor
pFeatureSelection.SelectionSet.Search(Nothing, False, pFCursor)
Dim pFeature As IFeature
... View more
01-06-2012
12:55 PM
|
0
|
0
|
498
|
POST
|
Neil, Thanks for catching my Editor declarations..I fixed that error. I changed my code to loop through and get the selected feature and update attributes...but the form just closes, it doesn't update the data. Is this because I don't have it in an edit operation like you said? How do I create and edit operation? Thanks again for help! Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Dim pEnumLayer As IEnumLayer
Dim pFeatureSelection As IFeatureSelection
Dim player As ILayer
'Get a reference to the editor.
Dim editor As IEditor
editor = My.ArcMap.Application.FindExtensionByName("esriEditor.Editor")
pMxDocument = My.ArcMap.Application.Document
pMap = pMxDocument.FocusMap
pEnumLayer = pMap.Layers
pEnumLayer.Reset()
player = pEnumLayer.Next
Do While Not player Is Nothing
If TypeOf player Is IFeatureLayer Then
Dim pFLayer As IFeatureLayer
pFLayer = player
pFeatureSelection = pFLayer
If pFeatureSelection.SelectionSet.Count <> 0 Then
Dim pFCursor As IFeatureCursor
pFeatureSelection.SelectionSet.Search(Nothing, False, pFCursor)
Dim pFeature As IFeature
pFeature = pFCursor.NextFeature
If Not pFeature Is Nothing Then
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFLayer
'If not editing, start editing dataset's Workspace
If editor.EditState <> esriEditState.esriStateEditing Then
editor.StartEditing(pEditDataset.Workspace)
End If
'Get SelectionSet
Dim pSelSet As ISelectionSet
pSelSet = GetSelection(pFLayer)
'Get FeatureCursor from SelectionSet
pSelSet.Search(Nothing, True, pFCursor)
'Initialize first (only) feature
pFeature = pFCursor.NextFeature
'Update attributes with user input
pFeature.Value(pFeature.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeature.Value(pFeature.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeature.Value(pFeature.Fields.FindField("LOCATION")) = txtLocation.Text
pFeature.Value(pFeature.Fields.FindField("AGENCY")) = txtAgency.Text
pFeature.Value(pFeature.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeature.Value(pFeature.Fields.FindField("COST")) = txtCost.Text
pFeature.Value(pFeature.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeature.Value(pFeature.Fields.FindField("USEREDITED")) = txtUser.Text
End If
End If
End If
player = pEnumLayer.Next
Loop
'Store changes to feature
'pFeature.
'Stop editing and save edits
editor.StopEditing(True)
'Close form
Me.Close()
End Sub
Public Function GetSelection(ByVal pFeatLyr As IFeatureLayer) As ISelectionSet
'Gets selection of feature layer and returns selection set
'Initialize the required variables
pMxDoc = My.ArcMap.Application.Document
Dim pFeatSel As IFeatureSelection
pFeatSel = pFeatLyr
GetSelection = pFeatSel.SelectionSet
End Function
End Class
... View more
01-06-2012
12:02 PM
|
0
|
0
|
462
|
POST
|
Neil, Thanks again for your help...as you can tell I'm very much a novice with programming. I spent a lot of time yesterday trying to figure out how to get this code to work, but each time it crashes when the button is clicked. I added "editor.startediting(peditdataset.workspace)" within the code and removed the public editor declaration. Am I selecting my feature in correctly or am I still mis-coding my editor? Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
pMxDoc = My.ArcMap.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureSelection
Dim Count As Integer
'Get a reference to the editor
Dim uid As UID
uid = New UIDClass()
uid.Value = "esriEditor.Editor"
Dim editor As IEditor
editor = My.ArcMap.Document.FindExtensionByName("ESRI Object Editor")
'If not editing, start editing dataset's Workspace
If editor.EditState <> esriEditState.esriStateEditing Then Exit Sub
'Get the Transportation Improvement Line Layer from the Map
If pMap.Layer(Count).Name = "TransportationImprovementProjects_Lines" Then
pFLayer = pMap.Layer(Count)
Dim pFCursor As IFeatureCursor = Nothing
pFLayer.SelectionSet.Search(Nothing, False, pFCursor)
Dim pF As IFeature
pF = pFCursor.NextFeature
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFLayer
'Start Editing
editor.StartEditing(pEditDataset.Workspace)
'Initialize first (only) feature
Dim pFeat As IFeature
pFeat = pFLayer.NextFeature
'Update attributes with user input
pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text
'Store changes to feature
pFeat.Store()
'Stop editing and save edits
Editor.StopEditing(True)
'Close form
Me.Close()
End If
End Sub
... View more
01-06-2012
05:03 AM
|
0
|
0
|
462
|
POST
|
Ahh...thanks, Neil.. Ahh...thanks, Neil!! I added "Public Editor as Editor", Instantiated the EditorDim Editor = My.ArcMap.Document.FindExtensionByName("ESRI Object Editor"), and changed all my IEditors to Editor. However, it crashes everytime i push the button....any suggestions?!?
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Dim pMxDoc As IMxDocument
pMxDoc = My.ArcMap.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureSelection
Dim Count As Integer
'Instantiate the editor
Dim Editor = My.ArcMap.Document.FindExtensionByName("ESRI Object Editor")
'Get the Transportation Improvement Line Layer from the Map
If pMap.Layer(Count).Name = "TransportationImprovementProjects_Lines" Then
pFLayer = pMap.Layer(Count)
Dim pFCursor As IFeatureCursor = Nothing
pFLayer.SelectionSet.Search(Nothing, False, pFCursor)
Dim pF As IFeature
pF = pFCursor.NextFeature
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFLayer
'If not editing, start editing dataset's Workspace
If Editor.EditState <> Editor Then
Editor.StartEditing(pEditDataset.Workspace)
End If
'Initialize first (only) feature
Dim pFeat As IFeature
pFeat = pFLayer.NextFeature
'Update attributes with user input
pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text
'Store changes to feature
pFeat.Store()
'Stop editing and save edits
Editor.StopEditing(True)
'Close form
Me.Close()
End If
End Sub
... View more
01-05-2012
06:12 AM
|
0
|
0
|
462
|
POST
|
I am trying to convert my old ArcGIS 9.3 (VBA) code to ArcGIS 10 using Visual Basic 2008 Express Edition. So far I have sucessfully created an pop-up window that displays the attributes of a selected feature in text boxes on the form. However, I want to create a button that allows users to save any changes they make to the attributes in the user form. Below is the code I have thus far for the On_Click event to update the attributes. The error I'm getting is on "IEditor.EditState <> esriStateEditing Then" IT says reference to non-shared member requires an object reference Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
Dim pMxDoc As IMxDocument
pMxDoc = My.ArcMap.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureSelection
Dim Count As Integer
For Count = 0 To pMap.LayerCount - 1
'Get the Transportation Improvement Line Layer from the Map
If pMap.Layer(Count).Name = "TransportationImprovementProjects_Lines" Then
pFLayer = pMap.Layer(Count)
Dim pFCursor As IFeatureCursor = Nothing
pFLayer.SelectionSet.Search(Nothing, False, pFCursor)
Dim pF As IFeature
pF = pFCursor.NextFeature
End If
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFLayer
'If not editing, start editing dataset's Workspace
If IEditor.EditState <> esriStateEditing Then
Editor.StartEditing(pEditDataset.Workspace)
End If
'Initialize first (only) feature
Dim pFeat As IFeature
pFeat = pFLayer.NextFeature
'Update attributes with user input
pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text
'Store changes to feature
pFeat.Store()
'Stop editing and save edits
Editor.StopEditing(True)
'Refresh map
pMxDoc.ActiveView.Refresh()
'Close form
Me.Close()
Next Count
End Sub
... View more
01-05-2012
04:53 AM
|
0
|
8
|
658
|
POST
|
I'm trying to convert my ArcGIS 9.3 code to ArcGIS 10 via Visual Basic 2008 Express; however, I'm having a couple issues. The goal is for a user to select a feature in ArcMap, click on this custom button, and a user form appears displaying attribute information of the selected feature. The code worked great in 9.3, but not in 10. Currently, I can get the user form to open by itself...but if a user selects a feature and clicks the button it crashes ArcMap. :eek: Also, I have three function and variable warnings in Visual Basic...I'm not sure what they mean or how to fix them... I have attached the warning errors I received in Visual Basic and the code for the user form is below. Any help would be greatly appreciated!!
Open User Form
Public Class TransLineEdit
Inherits ESRI.ArcGIS.Desktop.AddIns.Button
Dim pForm As New frmEdit
Protected Overrides Sub OnClick()
Try
pForm.Show()
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString, "OnClick")
End Try
End Sub
End Class
User Form Code:
Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.ArcMap
Imports ESRI.ArcGIS.DataManagementTools
Imports ESRI.ArcGIS.Desktop
Imports ESRI.ArcGIS.Editor
Imports ESRI.ArcGIS.Framework
Public Class frmEdit
'Declare variables that are used all thru the application
Public pMxDoc As IMxDocument
Public pMap As IMap
Public pEditor As IEditor
Public Application As IAppROT
Private Sub UserForm_Initialize()
'Get Improvement Projects FeatureLayer
Dim pFeatLyr As IFeatureLayer
pFeatLyr = GetLayerByTOC("TransportationImprovementProjects_Lines")
'Get selected feature (only one)
Dim pFeat As IFeature
pFeat = GetSelFeat(pFeatLyr)
'Populate form controls with feature's attribute values
txtPrjYear.Text = pFeat.Value(pFeat.Fields.FindField("YEAR"))
txtPrjType.Text = pFeat.Value(pFeat.Fields.FindField("PROJECTYPE"))
txtAgency.Text = pFeat.Value(pFeat.Fields.FindField("AGENCY"))
txtLocation.Text = pFeat.Value(pFeat.Fields.FindField("LOCATION"))
txtDescrip.Text = pFeat.Value(pFeat.Fields.FindField("DESCRIPTION"))
txtCost.Text = pFeat.Value(pFeat.Fields.FindField("COST"))
txtDate.Text = pFeat.Value(pFeat.Fields.FindField("DATEEDITED"))
txtUser.Text = pFeat.Value(pFeat.Fields.FindField("USEREDITED"))
Dim pDoc As IMxDocument
pDoc = My.ArcMap.Document
End Sub
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
End Sub
Private Sub cmdUpdate_Click()
On Error GoTo EH
'Initialize global variables
Call Initialize()
'Get Transportation Improvement Projects FeatureLayer
Dim pFeatLyr As IFeatureLayer
pFeatLyr = GetLayerByTOC("TransportationImprovementProjects_Lines")
'Get Dataset from FeatureLayer
Dim pEditDataset As IDataset
pEditDataset = pFeatLyr
'If not editing, start editing dataset's Workspace
If pEditor.EditState <> esriEditState.esriStateEditing Then
pEditor.StartEditing(pEditDataset.Workspace)
End If
'Get SelectionSet
Dim pSelSet As ISelectionSet
pSelSet = GetSelection(pFeatLyr)
'Get FeatureCursor from SelectionSet
Dim pFCursor As IFeatureCursor
pSelSet.Search(Nothing, True, pFCursor)
'Initialize first (only) feature
Dim pFeat As IFeature
pFeat = pFCursor.NextFeature
'Update attributes with user input
pFeat.Value(pFeat.Fields.FindField("YEAR")) = txtPrjYear.Text
pFeat.Value(pFeat.Fields.FindField("PROJECTYPE")) = txtPrjType.Text
pFeat.Value(pFeat.Fields.FindField("LOCATION")) = txtLocation.Text
pFeat.Value(pFeat.Fields.FindField("AGENCY")) = txtAgency.Text
pFeat.Value(pFeat.Fields.FindField("DESCRIPTION")) = txtDescrip.Text
pFeat.Value(pFeat.Fields.FindField("COST")) = txtCost.Text
pFeat.Value(pFeat.Fields.FindField("DATEEDITED")) = txtDate.Text
pFeat.Value(pFeat.Fields.FindField("USEREDITED")) = txtUser.Text
'Store changes to feature
pFeat.Store()
'Stop editing and save edits
pEditor.StopEditing(True)
'Refresh map
pMxDoc.ActiveView.Refresh()
'Kill form
Me.Close()
'Avoid error handler
Exit Sub
EH:
'Stop editing, trash edits
If pEditor.EditState <> esriEditState.esriStateEditing Then
pEditor.StopEditing(False)
End If
'Display error
MsgBox("A Runtime Error Occured. Error Number: " & CStr(Err.Number) & _
vbCrLf & "Error Description: " & Err.Description, vbExclamation + vbOKOnly)
End Sub
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click
'Kill form
Me.Close()
'Clear selected features
Dim pActiveView As IActiveView
pActiveView = pMap
pMap.ClearSelection()
pActiveView.Refresh()
End Sub
Public Sub Initialize()
'Initalize global variables
pMxDoc = Application.Document
pMap = pMxDoc.FocusMap
'Instantiate the editor
pEditor = Application.FindExtensionByName("ESRI Object Editor")
End Sub
Public Function GetLayerByTOC(ByVal lyrName As String) As IFeatureLayer
'This function finds a feature layer based on its TOC Name
Call Initialize()
Dim lyrCntr As Integer
Dim pFeatLyr As IFeatureLayer
For lyrCntr = 0 To pMap.LayerCount - 1
'Ensure that the layer is valid
If pMap.Layer(lyrCntr).Valid = True Then
'Ensure that the layer is a feature layer
If TypeOf pMap.Layer(lyrCntr) Is IFeatureLayer Then
pFeatLyr = pMap.Layer(lyrCntr)
If UCase(pMap.Layer(lyrCntr).Name) = UCase(lyrName) Then
GetLayerByTOC = pFeatLyr
Exit Function
End If
End If
End If
Next lyrCntr
'Layer not found. Show a message
MsgBox("Layer " & lyrName & " not found !", vbCritical, "Error")
End Function
Public Function GetSelFeat(ByVal pFeatLyr As IFeatureLayer) As IFeature
'Gets selected feature from feature layer and returns feature
'Call this function only when you are sure that only one feature is selected
'Initialize the required variables
Call Initialize()
Dim pFeatSel As IFeatureSelection
pFeatSel = pFeatLyr
Dim pSelectionSet As ISelectionSet
pSelectionSet = pFeatSel.SelectionSet
Dim pFeatCur As IFeatureCursor
pSelectionSet.Search(Nothing, True, pFeatCur)
'Return the selected feature
GetSelFeat = pFeatCur.NextFeature
End Function
Public Function GetSelection(ByVal pFeatLyr As IFeatureLayer) As ISelectionSet
'Gets selection of feature layer and returns selection set
'Initialize the required variables
Call Initialize()
Dim pFeatSel As IFeatureSelection
pFeatSel = pFeatLyr
GetSelection = pFeatSel.SelectionSet
End Function
End Class
... View more
12-15-2011
08:21 AM
|
0
|
0
|
227
|
POST
|
Greetings! I'm trying to convert my 9.3 code to ArcGIS 10..and am having some problems. My goal is to allow users to select a feature, click on a button, and the feature's attributes will appear in a user form that they can edit. I have coverted everything using Visual Basic Express 2008 and am able to get the window to pop-open when a feature isn't selected (obviously the user form does not contain attribute information at this time)....but my ArcMap crashes everytime I have a feature selected and I press my button. Any suggestions?
... View more
11-29-2011
01:50 PM
|
0
|
2
|
1892
|
Title | Kudos | Posted |
---|---|---|
1 | 06-27-2011 09:26 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|