is it possible to convert this AML into python? (arcedit)

1604
4
09-14-2016 07:15 AM
FredericPiche
New Contributor II

I'm trying to replicate this code (both delete) in python, my previous question is related to this

arcpy 10.3.1 being used with proper license

using coverage files

display 0
arcedit
&if [show program] ne ARCEDIT &then &do /*IF1
   &type ERROR: The Arcedit module could not be invoked 
   &setvar run_status := -1002
   &return
&end /*IF1


/*** Remove non-topological lines
/*
graphics off
edit %path_poly_cover%

editfeature line
select line_type in {%valid_line_type_list%}
nselect
&if [show number select] gt 0 &then &do /*IF1
   delete
&end /*IF1


/*** Remove non-topological points 
/*
editfeature point
select pnt_type in {%valid_pnt_type_list%}
nselect
&if [show number select] gt 0 &then &do /*IF1
   delete
&end /*IF1


save
removeedit %path_poly_cover% yes


/*** Return to the arc module
/*
&if [show program] eq ARCEDIT &then &do /*IF1
   removeedit all yes
   quit yes
&end /*IF1
0 Kudos
4 Replies
RebeccaStrauch__GISP
MVP Esteemed Contributor

My first answer would be "probably".  I don't have a chance to look at it now, but if you don't get a response, I'll take a close look later.

In the meantime, if you are familiar with both AML and Python, this is a good resource...

Using AML with script tools—Help | ArcGIS for Desktop 

it has section for conversion for both AML functions and directives to arcpy, where available.  Somethings may not be a direct conversion and may take a little more effort, but it doesn't look to bad.  You are basically doing a couple selects/reselects and deleting some features. 

Suggestion....do it manually using the standard coverage tools to do conversions, if needed, then copy the python snippets from the "results" table.

Oh, and in you originally had ArcInfo Workstation and still have the concurrent license, Workstation will still load and run on a win7 machine.....no so lucky with a win10 machine so far.

RebeccaStrauch__GISP
MVP Esteemed Contributor

I suggest taking a look at http://desktop.arcgis.com/en/arcmap/10.3/tools/coverage-toolbox/select.htm  or ArcGIS Help 10.1    if pre-10.1, you'll need to do a quick web search for the help

So, I can get you part way there.  I haven't figured out the correct syntax for the reselect and nselect yet.  The error I'm getting is

Enter a logical expression. (Enter a blank line when finished)
>: RESELECT FID LT 16
** Item "FID" not found **
>: NSELECT
NSELECT cannot be the first selection expression.
Character string expected.
** An expression must start with RES, ASEL, NSEL or ITEMS.
** NO VALID EXPRESSION ENTERED **
*** UNABLE TO PERFORM ACTION ***
Bailing out of EVALUATE
Failed to execute (Reselect).
Failed at Wed Sep 14 19:03:52 2016 (Elapsed Time: 0.37 seconds)

I have also tried it with RES and NSEL.

Here is the code that I have so far.  Again, it gives some good info up to the infoExpress  and the Reselect_arc part

import arcpy

inCover = r"C:\Workspace\test\bl01"
# inCover = r"c:\Data\cea01apr"     # this assumes cea01apr is the Coverage name
arcpy.env.workspace = inCover

featureType = 'point'   # this is the feature type
recCountIn = int(arcpy.GetCount_management(featureType).getOutput(0))
print("Number of {0} records in {1}: {2}".format(featureType, inCover, recCountIn))

# these aren't used, but good info
featureClassList = arcpy.ListFeatureClasses()
fieldList = arcpy.ListFields(inCover, "", featureType)
fieldString = [str(x.name) for x in fieldList]
print(fieldString)

tempCover = r"C:\Workspace\test\cl01testIn"
try:
     arcpy.Copy_management(inCover, tempCover)
     print("\nCopy worked")
except:
     print("\nCopy didnt work, may already exist")

tempCoverOut = r"C:\Workspace\test\cl01Out"

fidfilter= 'fid < 16'    # just for the sake of showing 15 vs  one record...

# take a look at http://resources.arcgis.com/en/help/main/10.1/index.html#/Select/001300000005000000/
# or http://desktop.arcgis.com/en/arcmap/10.3/tools/coverage-toolbox/select.htm 

print("\nReselect {0} from {1} then nselect for the other {2} and save to new coverage".format(fidfilter, recCountIn, (recCountIn - int(fidfilter[-3:]))))

infoExpress = ["RESELECT FID LT 16",
               "NSELECT"]

print("\n my test infoExpress: {0}\n  but doesn't work".format(infoExpress))

"""
# sample from help pages
infoExpress = ["RESELECT stream_name CN 'AQUEDUCT'",
               "NSELECT",
               "RESELECT stream_order > 3",
               "ASELECT length > 10000"]
"""


# Execute Reselect
arcpy.Reselect_arc(tempCover, tempCoverOut, infoExpress, featureType, "", "")

Unless you have to do it all in the source coverage, I would use a copy (just in case) and then do a Reselect to a new coverage.  If you run it more than once, you will have to so clean up, of course.  And that assumes you get it to work, which as mentioned, right now the infoExpress is not quite right yet.  Also, change to your input/workstation, etc.

As mentioned in the other thread, you might be better off moving to a FGDB and featureclasses now, but I was always a coverage fan, and know there may be reasons....so, work with what you need to.  have fun!

FredericPiche
New Contributor II

like you I'm not able to make the infoexpress work and I am able to a clean_arc call.

the reselect_arc would have been a nice alternative to my delete row issue.

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

It could be a bug, since not many report issues with the Coverage tools anymore, so might never get written up. And if so, I doubt they will fix it, but might be worth putting a tech support request to ask.

But if not a bug, it's just a matter, in my opinion, of getting the right infoExpress syntax with quotes and all...and maybe so one step at a time, vs in a series as infoExpress is supposed to allow.  It would create more temp coverage perhaps, but if the main thing is to get it to work, temp coverages can always be deleted at the end of the script.

0 Kudos