POST
|
Hi Andrew. Just seeing this now. Here it is. I was hoping to do this outside of ArcMap but found that you have to start an editing session to get it to work so created it as an Add-In. I have reported this to ESRI as a bug but don't think it has been fixed yet. Protected Overrides Sub OnClick()
Dim ipDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument 'ArcMapUI
ipDoc = CType(My.ArcMap.Application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument)
Dim pMap As ESRI.ArcGIS.Carto.IMap
pMap = ipDoc.FocusMap
Dim pDocInfo As IDocumentInfo2 = CType(ipDoc, IDocumentInfo2)
Dim pEnumLayer As IEnumLayer
Dim pLayer As ILayer
Dim pFeatureLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Dim pDataset As IDataset
Dim Plan_Num As String
Dim idx As Integer
Dim m_editor As IEditor
Dim editorUid As New UID()
editorUid.Value = "esriEditor.Editor"
m_editor = TryCast(My.ArcMap.Application.FindExtensionByCLSID(editorUid), IEditor)
'Gets numbers from the name of the map which is the Plan_Num and will be used to set default values
Plan_Num = Integer.Parse(Regex.Replace(pDocInfo.Name, "[^\d]", ""))
pEnumLayer = pMap.Layers(Nothing, True)
pEnumLayer.Reset()
pLayer = pEnumLayer.Next
For idx = 0 To pMap.LayerCount - 1
Do Until pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer2 And Not TypeOf pLayer Is RasterLayer Then
Try
pFeatureLayer = pLayer
pFeatureClass = pFeatureLayer.FeatureClass
If Not pFeatureClass.FeatureDataset Is Nothing Then
pDataset = pFeatureClass.FeatureDataset
'Loop through layers in the Plans feature dataset and set default value for Plan_Num
If pDataset.Name = "REF.SDE.Plans" Then
Dim pWorkSpace As IWorkspace = pDataset.Workspace
Dim pWorkEdit As IWorkspaceEdit = pWorkSpace
If pWorkEdit.IsBeingEdited = False Then
'Start an edit session
m_editor.StartEditing(pDataset.Workspace)
pFeatureLayer = pLayer
Dim pLayerExt As ESRI.ArcGIS.Carto.ILayerExtensions
pLayerExt = CType(pFeatureLayer, ESRI.ArcGIS.Carto.ILayerExtensions)
Dim jdx As Integer
For jdx = 0 To pLayerExt.ExtensionCount - 1
Dim obj As Object = pLayerExt.Extension(jdx)
If TypeOf obj Is ESRI.ArcGIS.Carto.IEditTemplateManager Then
Dim pEditTemplateMgr As ESRI.ArcGIS.Carto.IEditTemplateManager
pEditTemplateMgr = CType(obj, ESRI.ArcGIS.Carto.IEditTemplateManager)
Dim pEditTemplate As IEditTemplate = pEditTemplateMgr.EditTemplate(jdx)
Dim kdx As Integer
For kdx = 0 To pEditTemplateMgr.Count - 1
pEditTemplateMgr.EditTemplate(kdx).SetDefaultValue("Plan_num", Plan_Num, True)
Next
End If
Next
m_editor.StopEditing(False)
Else
MsgBox("Please stop editing and try to run tool again")
End If
End If
End If
Catch ex As Exception
MsgBox("Error! Default value not set for " + pLayer.Name)
End Try
End If
pLayer = pEnumLayer.Next
Loop
Next
My.ArcMap.Application.SaveDocument()
MsgBox("Process complete. Map can be closed.")
My.ArcMap.Application.CurrentTool = Nothing
End Sub
... View more
09-06-2017
01:40 PM
|
0
|
0
|
656
|
POST
|
I have created an extension Add In that should start listening to editor events when it is checked on. Everything is working great if the extension is not checked on startup. I check the extension on and everything works as expected. The problem is when I leave the extension checked on. When I reopen the map, I see my message boxes on startup, but the editor listeners do not work. This is an autoload extension not a Just In Time (JIT) so autoload is set to true in my config file. I have searched every example and help topic I can find and am stumped. Any help would be appreciated! Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Editor
Imports ESRI.ArcGIS.Desktop.AddIns
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Framework
Public Class Default_GDRC_Num_ext
Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
Public Sub New()
End Sub
Private Shared s_Extension As Default_Num_ext
Protected Overrides Sub OnStartup()
s_Extension = Me
Initialize()
End Sub
Protected Overrides Function OnSetState(ByVal state As ESRI.ArcGIS.Desktop.AddIns.ExtensionState) As Boolean
Me.State = state
If state = ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled Then
MsgBox("Enabled text")
Initialize()
AddHandler Events.OnStartEditing, AddressOf Events_OnStartEditing
AddHandler Events.OnStopEditing, AddressOf Events_OnStopEditing
Else
MsgBox("Not Enabled text")
Uninitialize()
End If
Return MyBase.OnSetState(state)
End Function
Protected Overrides Function OnGetState() As ESRI.ArcGIS.Desktop.AddIns.ExtensionState
Return Me.State
End Function
Private Sub Initialize()
If Me.State <> ExtensionState.Enabled Then
Return
End If
MsgBox("Initializing")
AddHandler Events.OnStartEditing, AddressOf Events_OnStartEditing
AddHandler Events.OnStopEditing, AddressOf Events_OnStopEditing
End Sub
Private Sub Uninitialize()
If s_Extension Is Nothing Then
Return
End If
MsgBox("Uninitializing")
RemoveHandler Events.OnStartEditing, AddressOf Events_OnStartEditing
End Sub
Private ReadOnly Property MyEditor() As IEditor
Get
Dim m_editor As IEditor
Dim editorUid As New UID()
editorUid.Value = "esriEditor.Editor"
m_editor = TryCast(My.ArcMap.Application.FindExtensionByCLSID(editorUid), IEditor)
Return TryCast(m_editor, IEditor)
End Get
End Property
Private ReadOnly Property Events() As IEditEvents_Event
Get
Dim m_editorEvents As IEditEvents_Event = TryCast(MyEditor, IEditEvents_Event)
Return TryCast(m_editorEvents, IEditEvents_Event)
End Get
End Property
Private Sub Events_OnStartEditing()
MsgBox("you are now editing")
End Sub
Private Sub Events_OnStopEditing()
MsgBox("You will stop editing")
End Sub
Protected Overrides Sub OnShutdown()
s_Extension = Nothing
Uninitialize()
RemoveHandler Events.OnStartEditing, AddressOf Events_OnStartEditing
End Sub
... View more
08-25-2016
11:21 AM
|
0
|
0
|
797
|
POST
|
Thank you for your answers! Both have helped me solve different problems I had with my script.
... View more
08-11-2016
04:10 PM
|
0
|
0
|
559
|
POST
|
Hi Nils. Sorry it took me so long to answer you. There is no way to do this with ArcPy. I had to learn some ArcObjects to accomplish this. You can set a default value through the layer extensions (ILayerExtension) and then access the template manager (IEditTemplateManager) and edit the template (IEditTemplate). One problem I ran into that is now logged as a bug is that you have to start an edit session for this to work. If you would like some sample code let me know.
... View more
08-05-2016
02:22 PM
|
1
|
2
|
656
|
POST
|
I have been struggling with getting two types of addins to work together for some time now. I have created an editor extension addin and have been able to listen to events on start editing with success. I also have created a regular (desktop) extension and can check it on and off with success. What I am having trouble with is that I would like the editor event listener to only work when the extension in ArcMap is enabled (checked). I am working with the desktop extension addin now but whenever I add the event handlers to start listening when the extension is enabled it causes ArcMap to crash. Any ideas or sample code would be greatly appreciated! The handlers are commented out since that is what is causing ArcMap to crash. Imports ESRI.ArcGIS.Editor
Public Class MyEditListener
Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
Public Sub New()
End Sub
Protected Overrides Sub OnStartup()
' TODO: Uncomment to start listening to document events
'WireDocumentEvents()
End Sub
Private m_editorEvent As IEditEvents_Event
Protected Overrides Function OnSetState(ByVal state As ESRI.ArcGIS.Desktop.AddIns.ExtensionState) As Boolean
Me.State = state
If state = ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled Then
MsgBox("Enabled")
'AddHandler m_editorEvent.OnStartEditing, AddressOf Events_OnStartEditing
'AddHandler m_editorEvent.OnStopEditing, AddressOf Events_OnStopEditing
Else
MsgBox("Not Enabled")
End If
Return MyBase.OnSetState(state)
End Function
Private Sub Events_OnStartEditing()
MsgBox("start editing")
End Sub
Private Sub Events_OnStopEditing()
MsgBox("stop editing")
End Sub
... View more
08-05-2016
02:04 PM
|
0
|
3
|
1827
|
POST
|
Thank you Duncan. Yes I am setting "Lake" as the default value. The problem is that I can access all of the properties on the Edit Template Interface but it seems that the methods cannot be accessed as shown on the object diagram. I can get my tool to run as an add-in but have to start an editing session and then the tool will run without error. My original project however is a standalone form that does not access the ArcMap application, I use the Map Document interface, so it will greatly complicate things if I have to go through the editor in my script. I have been working a bit with ESRI on this and they will be letting me know if this is an issue since the documentation states you can update default values through the template manager. Any insights you have on setting the default value without the editor would be great!
... View more
10-09-2015
08:46 AM
|
0
|
0
|
358
|
POST
|
I am trying to set a default value for a field. I have created a script in VB.Net that will access the layers I am interested in and get the edit template for each one. I can access all of the properties in the IEditTemplate interface but when I try and access the SetDefaultValue method I get an error - Error HRESULT E_FAIL has been returned from a call to a COM component. I have 3 message boxes that display the values without error but as soon as it reaches the SetDefaultValue it errors out. Any help would be greatly appreciated! Dim idx As Integer
Dim pLayer As ILayer
Dim pFeatureLayer As IFeatureLayer2
Dim pFeatureClass As IFeatureClass
Dim pDataset As IDataset
Dim pEnumLayer As IEnumLayer
pEnumLayer = pMap.Layers(Nothing, True)
pEnumLayer.Reset()
pLayer = pEnumLayer.Next
For idx = 0 To pMap.LayerCount - 1
Do Until pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer2 And Not TypeOf pLayer Is RasterLayer Then
pFeatureLayer = pLayer
pFeatureClass = pFeatureLayer.FeatureClass
If pFeatureLayer.DataSourceType = "SDE Feature Class" Then
If Not pFeatureClass.FeatureDataset Is Nothing Then
pDataset = pFeatureClass.FeatureDataset
Dim pLayerExt As ILayerExtensions
pLayerExt = pLayer
Dim pEditTemplateMgr As IEditTemplateManager
Dim jdx As Integer
For jdx = 0 To pLayerExt.ExtensionCount - 1
Dim extension As Object = pLayerExt.Extension(jdx)
If TypeOf extension Is IEditTemplateManager Then
pEditTemplateMgr = extension
Dim pEditTemplate As IEditTemplate = pEditTemplateMgr.EditTemplate(0)
MsgBox(pLayerExt.ExtensionCount)
MsgBox(pEditTemplate.Name)
MsgBox(pEditTemplate.DefaultValue("Feature_Type"))
pEditTemplate.SetDefaultValue("Feature_Type", "Lake", True)
End If
Next
End If
End If
End If
pLayer = pEnumLayer.Next
Loop
Next
... View more
10-02-2015
11:44 AM
|
0
|
2
|
2013
|
POST
|
Thank you Freddie. This is very helpful. Could you let me know what results.ContainsKey is doing and what the equivalent is in VB.NET. I am new to ArcObject and so far have not been using c#.
... View more
09-22-2015
04:21 PM
|
0
|
1
|
383
|
POST
|
I am trying to loop through layers in a map and return the name of the feature dataset. I will then be performing some task on features in a specific feature dataset. My map however is complex and includes some layers that do not reside in a feature dataset. My code errors at this point. I would like to somehow step over these layers without error. The line If pFeatureLayer.DataSourceType = "SDE Feature Class" is an attempt to limit my results since all of those layers reside in a feature dataset but that doesn't seem to be working. I am new to ArcObject so any help would be greatly appreciated! Here is my code: Dim pMapDocument As IMapDocument = New MapDocument()
If pMapDocument.IsMapDocument(destfile) Then
pMapDocument.Open(destfile, Nothing)
Dim pMap As IMap
Dim i As Integer
For i = 0 To pMapDocument.MapCount - 1 Step 1 + 1
pMap = pMapDocument.Map(i)
MsgBox(pMapDocument.DocumentFilename)
Dim pEnumLayer As IEnumLayer
Dim pID As New UID
Dim pFeatureClass As IFeatureClass
Dim pDataset As IDataset
Dim pFeatureLayer As IFeatureLayer2
pID.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"
pEnumLayer = pMap.Layers(pID, True)
pEnumLayer.Reset()
pFeatureLayer = CType(pEnumLayer.Next, IFeatureLayer2)
Do Until pFeatureLayer Is Nothing
If pFeatureLayer.DataSourceType = "SDE Feature Class" Then
pFeatureClass = pFeatureLayer.FeatureClass
pDataset = pFeatureClass.FeatureDataset
MsgBox(pDataset.Name)
End If
pFeatureLayer = CType(pEnumLayer.Next, IFeatureLayer2)
Loop
Next i
End If
Next
... View more
09-22-2015
02:20 PM
|
0
|
3
|
2716
|
POST
|
Thanks Jeff. I will look at that. Thanks to all others who tried to help me! Just to be sure,before I give up, there is no way to access the Create Feature Template Properties with python and I cannot use field.defaultValue to assign a default? Many thanks!
... View more
05-06-2015
01:07 PM
|
0
|
4
|
656
|
POST
|
Thanks Dan. I haven't used functions much. I did get it to run but as I thought, the default value was assigned to the feature class itself so when I go to another map the same default value is present. That is why I was trying to use the defaultValue property for the field. What I really need is a default on a field that will exist for in the mxd only. Just like how you can set it in the template properties when creating a new feature. Maybe this is not possible.
... View more
05-06-2015
11:33 AM
|
0
|
2
|
656
|
POST
|
import os
import arcpy
tbl = "Roads"
fld = "Project_Name"
def AssignDefault(tbl, fld):
try:
fname = arcpy.ListFields(tbl, fld)[0].name
mxd = arcpy.mapping.MapDocument("CURRENT")
default = os.path.splitext(arcpy.Describe(mxd.filePath).name)[0]
arcpy.AssignDefaultToField_management(tbl, fname, default)
print default
except:
print("Could not assign default")
Thanks Curtis. I will be creating a tool for the user to enter their Project Name but am keeping this simple for now since I don't even know what I am trying to do is possible. I ran your code frmo ArcMap but nothing happened. I added a print statement and that was not displayed either. Any ideas?
... View more
05-06-2015
10:45 AM
|
0
|
2
|
1863
|
POST
|
Thanks Christian and Sephe. I have tried th Assign Default to Field tool and the default value then gets applied to the entire feature class so anyone editing will have the same default value. I need the default to change from map to map. Any ideas on that?
... View more
05-06-2015
09:43 AM
|
0
|
4
|
1863
|
POST
|
I have been trying to figure out how I can set a default value to a field in ArcMap. I see there is a tool called Assign Default to field but that is applied to the entire dataset. I would like the default to apply to the current ArcMap session only. In the Create Features window you can right click a layer and set a default there to get the behavior I would like but am trying to accomplish this for multiple layers in the TOC using python. This is what I have been trying, starting with one layer first, but get an error "The attribute 'defaultValue' is not supported on this instance of Field" I can print the defaultValue however. feature_class = "Roads" fields = arcpy.ListFields(feature_class) for field in fields: if field.name == "Project_Name": field.defaultValue = "Test_Project" Forgive me if I am making an obvious mistake. I am still a beginner. Thanks for any help!
... View more
05-06-2015
09:30 AM
|
0
|
18
|
10011
|
POST
|
Thank you so much Xander. That worked perfectly! I did as you suggested and looked at the geoprocessing results and just couln't figure out how to get my raster list in that format using Python. I think I really wanted it to be a list since I am used to working with those and am new to Python. I can now sleep tonight without Python code running through my head
... View more
04-14-2015
04:46 PM
|
0
|
1
|
960
|
Title | Kudos | Posted |
---|---|---|
1 | 08-05-2016 02:22 PM | |
1 | 04-14-2015 03:22 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|