I am not sure how I should have my syntax to use this with a tool ?
# Set Editingworkspace = r'C:\xyz'edit = arcpy.da.Editor(workspace) edit.startEditing(False, True) edit.startOperation()edit = arcpy.GetParameterAsText(3)
Not working yet based on your suggestions. So it just starts an edit session ? How does it know to edit the selected feature, I am not seeing it in the code.
Thanks for the feedback. You are exactly correct that I want the user to use the map document default tool to stop and save edits.
Most edits will be attributes but some point feature creation and lines.
I will work on this.
You need to make the edit session starting dependent on whether or not the Starting Editting box is checked, right now it runs regardless. I set the result of GetParameterAsText(3) to a variable(InputEdit) then created an if statement that would run if that variable was True.
workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\abc.gdb'</SPAN> mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN> df <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> df<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> <SPAN class="number token">350</SPAN> <SPAN class="comment token"># Set the tool parameters</SPAN> InputFeatureClass <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> InputField <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> InputValue <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> InputEdit <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> InputEdit<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token">#Starting Editing Session</SPAN> edit <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Editor<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">)</SPAN> edit<SPAN class="punctuation token">.</SPAN>startEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN> edit<SPAN class="punctuation token">.</SPAN>startOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># SQL expression used in selecting a feature</SPAN> <SPAN class="comment token"># The equation needs to be enclosed with double quote marks, in addition, since the input FacilityID is string, it needs to be enclosed with #single quote marks. </SPAN> whereclause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"""{} = '{}'"""</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>AddFieldDelimiters<SPAN class="punctuation token">(</SPAN>InputFeatureClass<SPAN class="punctuation token">,</SPAN>InputField<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>InputValue<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Select feature by facilityid (InputValue)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>InputFeatureClass<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> whereclause<SPAN class="punctuation token">)</SPAN> df<SPAN class="punctuation token">.</SPAN>zoomToSelectedFeatures<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Not sure how you would logic the ending of the edit session into your code, since it seems like what you want your code to do is zoom to the select feature ID and edit if they choose. You might have the user close the editting session within the map document itself when they are done. What sort of edits would someone be doing to this feature(geometry, attributes, etc.)?
What is the goal of this script?
I want a user with the option to check the Start Editing after typing in the string FacilityID.
I am having trouble passing the selected feature to arcpy.GetParameterAsText() tool parameter.
Also, I have used editing arcpy syntax.
<SPAN class="comment token">#Set to current mxd and dataframe</SPAN> mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"CURRENT"</SPAN><SPAN class="punctuation token">)</SPAN> df <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListDataFrames<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> df<SPAN class="punctuation token">.</SPAN>scale <SPAN class="operator token">=</SPAN> <SPAN class="number token">350</SPAN> <SPAN class="comment token"># Set Editing</SPAN> workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\abc.gdb'</SPAN> edit <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Editor<SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">)</SPAN> edit<SPAN class="punctuation token">.</SPAN>startEditing<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN> edit<SPAN class="punctuation token">.</SPAN>startOperation<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> edit <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Set the tool parameters</SPAN> InputFeatureClass <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> InputField <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> InputValue <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># SQL expression used in selecting a feature</SPAN> <SPAN class="comment token"># The equation needs to be enclosed with double quote marks, in addition, since the input FacilityID is string, it needs to be enclosed with #single quote marks. </SPAN> whereclause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"""{} = '{}'"""</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>AddFieldDelimiters<SPAN class="punctuation token">(</SPAN>InputFeatureClass<SPAN class="punctuation token">,</SPAN>InputField<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>InputValue<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">#Select feature by facilityid (InputValue)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>InputFeatureClass<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NEW_SELECTION"</SPAN><SPAN class="punctuation token">,</SPAN> whereclause<SPAN class="punctuation token">)</SPAN> df<SPAN class="punctuation token">.</SPAN>zoomToSelectedFeatures<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RefreshActiveView<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The last line definitely looks odd. What is arcpy.GetParameterAsText(3) returning? Better yet, can you elaborate a bit more on what you are trying to do?
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.