I have a series of models. One of the models creates/overwrites a feature class based on a user selection of features. A second tool is trying to run an 'Union' tool using the extents of the feature class mentioned. Initially I had extents of feature class as an environment input into Union in my model, however, I found that I have to revalidate the model every time before I run, otherwise it just uses the same extents coordinates.
I tried using the 'Calculate Value' saving value as 'Extent' object to recalculate the extent and use that everytime, but it doesnt work. It runs without errors but does not appear to use the extents Im trying to pass through. Ive tried several syntax options but none work.
Any ideas on how to do this? Below is very simple model
Those extent objects can be a bit tricky, I might amend it to something like:
#create a copy of extent object to modify
new_extent = objDes.extent
#set values for extent object
new_extent.XMin = objDes.extent.XMin
new_extent.XMax = objDes.extent.XMax
new_extent.YMin = objDes.extent.YMin
new_extent.YMax = objDes.extent.YMax
No idea if that will work as I struggle with these also. You may just want to run the 'Feature envelope to polygon' tool on the data then use that polygon as the extent if not.
Hi David - thanks for the suggestion, but unfortunately trying to set the values didnt seem to work either. Ill look into the envelope option - that sounds promising.
(I realize this is a somewhat old question, but having just run into the issue today, I wanted to make sure there's a googleable answer for the next time it stymies me!)
This is a weird one, and the esri documentation is uncharacteristically unhelpful. Here's what I found that worked...
Basically, the function needs to return a string, not an extent object; the output type is being set to enable you to chain items in ModelBuilder but isn't actually relevant to the value you return! What worked for me was to return a string in the format "xmin ymin xmax ymax" and set the output type to Extent. Arcpy/ModelBuilder are smart enough to know from the output type that you should be able to use the output of your function as input to an Extent parameter of another tool, and are also smart enough to handle the coercion from the string formatting of the extent to the expected Extent object.