Use derived output of script tool as parameter in tool in Model Builder?

1774
5
Jump to solution
02-03-2022 03:45 PM
by Anonymous User
Not applicable

Hi All,

I am creating a model in ArcGIS Pro 2.9 that achieves the following:

1. Creates a spatial join of zoning to tree points, outputs updated feature class to a FGDB

2. Imports table from AGOL into the same FGDB listed above

3. Removes duplicate values from the same table, keeping only the most recent record

4. Creates a table join on tree feature class from step one, with the updated table from step three as the join table

For step three, I created a script tool, which I added into the model. Everything runs fine up until the point where I try to set up the table join. The issue is that it wont let me add the output from the script tool as the join table. It just doesn't recognize it at all. For reference, below are screenshots of the script tool code and parameters:

lfremonti_0-1643926974759.png

lfremonti_1-1643927001607.png

Can anyone point out what I am doing wrong in this scenario, and how to allow for the output of the script tool can be implemented into the table join step of the model?

Thanks in advance!!

 

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

I could read the screen shot, but it looked like there was more code below the screen shot under the scrollbar. Looks like the answer to my question was no. To return derived parameters, you must populate the value with arcpy.SetParameterAsText(). Hope this example helps:

 

import arcpy
arcpy.env.autoCommit = 2000

treetable = arcpy.GetParameterAsText(0)
globalid = 'REL_GLOBALID'
date_field_sort = 'DATE D'
update_cursor = arcpy.UpdateCursor(treetable, '', '', globalid, date_field_sort)

keep_list = list()
for row in update_cursor:
    row_val = row.getValue(globalid)
    if row_val not in keep_list:
        keep_list.append(row_val)
    elif row_val in keep_list:
        update_cursor.deleteRow(row)
    else:
        pass

arcpy.SetParameterAsText(1, treetable)

 

 

View solution in original post

0 Kudos
5 Replies
curtvprice
MVP Esteemed Contributor

Is the derived output parameter being set with arcpy.SetParameterAsText() ?

0 Kudos
by Anonymous User
Not applicable

Here is the code I used. Sorry, didn't realize that the pictures were so low resolution!

import arcpy
arcpy.env.autoCommit = 2000

treetable = arcpy.GetParameterAsText(0)
globalid = 'REL_GLOBALID'
date_field_sort = 'DATE D'
update_cursor = arcpy.UpdateCursor(treetable, '', '', globalid, date_field_sort)

keep_list = list()
for row in update_cursor:
row_val = row.getValue(globalid)
if row_val not in keep_list:
keep_list.append(row_val)
elif row_val in keep_list:
update_cursor.deleteRow(row)
else:
pass

0 Kudos
curtvprice
MVP Esteemed Contributor

I could read the screen shot, but it looked like there was more code below the screen shot under the scrollbar. Looks like the answer to my question was no. To return derived parameters, you must populate the value with arcpy.SetParameterAsText(). Hope this example helps:

 

import arcpy
arcpy.env.autoCommit = 2000

treetable = arcpy.GetParameterAsText(0)
globalid = 'REL_GLOBALID'
date_field_sort = 'DATE D'
update_cursor = arcpy.UpdateCursor(treetable, '', '', globalid, date_field_sort)

keep_list = list()
for row in update_cursor:
    row_val = row.getValue(globalid)
    if row_val not in keep_list:
        keep_list.append(row_val)
    elif row_val in keep_list:
        update_cursor.deleteRow(row)
    else:
        pass

arcpy.SetParameterAsText(1, treetable)

 

 

0 Kudos
curtvprice
MVP Esteemed Contributor

One more thing, you may want to look at the tools Sort and Delete Identical they may do what you want without having to use a custom script.

0 Kudos
by Anonymous User
Not applicable

Thanks so much for the tips! The arcpy.SetParameterAsText() function achieved exactly what I had hoped for! That was really the only think I was missing, as it turns out.

Also, thanks for the tips on Sort and Delete identical. I was unaware of the Sort tool, and I didn't use Delete Identical because it seems to just choose a random duplicate to delete. 

Thanks again for your advice, that was a big help!

0 Kudos