0

I have a modelbuilder model setup that, in short, takes all selected features from ArcMap and exports it to a dwg. I need to add two things to this model which I'm not sure can be done in modelbuilder. The ArcMap document has several feature classes which don't necessarily overlap so first I need the model to run only on the feature classes that HAVE selected features and ignore the rest of the feature classes. Second, I need the model to NOT run if more than 10000 features are selected from any of the feature classes in ArcMap. This can probably be easily done in Python but I have no experience in Python hence I'd like to confirm if it can be done in modelbuilder. If not, I'll have to explore Python.

Edit: I need a statement where if the number of features are greater than 0 and less than 10000 then it should be true and proceed. I think the "Get Count" and "Calculate Value" tools can be used to do this in modelbuilder, just not sure how.

Steve
  • 773
  • 10
  • 21

1 Answers1

2

Well, what I would do, if you are serious about wanting to do this in Model Builder, is use some python snippets within model builder as you state in your edit. What you can do is, for example with the not running if more than 10,000 features are selected, use the Get Count geoprocessing tool on that layer. It will output the number of features selected if there is a selection, or the total number of features if there is no selection or the selection returned 0 features thus resulting in no selection (because of this 0 will never be returned by Get Count tool unless run against an empty feature class, and if there are less than 10000 features total in your feature class when you run this, it will run even if there is no selection, though not if there is a selection of less than 10000). In model builder you can specify the name of the resulting value, for example call the output of the Get Count tool RowCount. Then you can use the model builder only tool called "Calculate Value" (find it under the insert menu > model only tools > Calculate Value within model builder).

Within that you could put in the Expression:

ifSelected(%RowCount%)

Within the code block:

def ifSelected(e):
  if e < 10000:
    return "TRUE"
  else:
    return "FALSE"

Data Type:

Boolean

Then, in the model, set the output of calculate value as a precondition to the operation you want to only run if true.

Also, if you regularly have feature classes with less than 10000 total features that you want to run this against, you could run two get count tools, one before a selection is made and one after and do something like the following in the calculate value tool instead

ifSelected(%TotalCount%,%SelectedCount%), 

def ifSelected(Total,Selected):
    if Selected < 10000 and Selected < Total:
        return "TRUE"
    else:
        return "FALSE"

Hope that helps.

John
  • 3,853
  • 12
  • 17
  • Thanks for the response! There are no feature classes with less than 10000 total features so I can skip the second part for now. Couple questions on the get count and calculate value tools. Does the get count tool need to be connected to the collect values tool as a precondition? The collect value tool would connect to the copy features tool. How do I set the output of calculate value as a precondition (if true) to copy features precondition. Heres a screenshot of what I have: https://sites.google.com/site/shobuddy/misc Click on "export graphic.jpg – Steve Feb 11 '14 at 19:59
  • It looks from that image like you have it set up correctly as far as those two tools are concerned. You would have the layer file input to the get count, count output precondition to calc value, calc value output precondition to copy features (if calc value type is Boolean, it will use the returned True or False as the precondition) and the original layer input to copy features. If original input is a raw shapefile/feature class input to get count it will of course only return the total number of features, but if it is a layer it will return selected features if available. That make sense? – John Feb 11 '14 at 20:56
  • The original input is a feature class that should only return selected features. With the model configured as shown in screenshot, the copy features tool does not run. I'm not sure whats missing to get it to run. The output for the calculate value tool is set to true. – Steve Feb 11 '14 at 21:09
  • Well you would probably need to connect the original feature class or layer to the copy features as the copy features tool needs some input for it to know what to copy. – John Feb 11 '14 at 21:33
  • But if it's just a feature class, then it can't have a selection applied to it (feature classes can't have selections). You would have to make it a layer first. To do this you could use either a layer file (right click on a layer in ArcMap Table of Contents and save a layer file), or use the Make Feature Layer geoprocessing tool, or use a layer from the ArcMap table of contents directly if you are running the model from ArcMap. With a layer you can apply a selection, but it's not possible to my knowledge to apply a selection to the feature class/shapefile directly. – John Feb 11 '14 at 21:36
  • Thanks again! I'll verify if its using a selection and if not, I'll use "make feature layer". It looks like the model is running well till the export to cad tool. There are about 13 feature classes that go into the export. The export to CAD does not run completely and gives the message "all the inputs are not current". I'm guessing this is because not all the the calculate value clauses are "true"? If so, is there a way to force it to run? I'll investigate further tomorrow. – Steve Feb 11 '14 at 22:15
  • Well, per the diagram you provided, the calculate value precondition would only directly affect the copy features tool, meaning that's not the issue if the copy features tool is running correctly. I would do some more research on the export to CAD tool and make sure it's not something particular about that (aka: try running that tool manually first to make sure you know what all the inputs need to be and such as that first. The put it in context of the model, just my thoughts anyway.) – John Feb 11 '14 at 22:26
  • I've attached a screenshot of what the model looks like: https://sites.google.com/site/shobuddy/misc click on "export graphic". The model runs completely when each input to the Export to CAD tool has features. If an input to the export to cad tool doesn't have features, the tool doesn't run at all. You can see from the screenshot which outputs are empty from the copy features tool because they don't have a drop shadow. I'm not sure how to fix this but I was looking at this link: http://www.techques.com/question/26-27707/Use-%27if%27-statement-in-ModelBuilder-to-stop-model – Steve Feb 12 '14 at 14:34
  • The link above suggests changing the TRUE/FALSE to lower case but the calculate value tool wont' let me change that. When I change to lower case and click ok, it goes back to all caps. – Steve Feb 12 '14 at 14:45
  • I should add that the export to cad seems to run in the log file but does not give the drop shadow in the model. Below is the log file for just the export to cad tool. – Steve Feb 12 '14 at 14:58
  • Executing (Export to CAD): ExportCAD in_memory\V_WATR_INST;in_memory\V_SSWR_MHOL;in_memory\V_WATR_STRC;in_memory\V_WATR_PIPE;in_memory\V_PROP_LINE_MOCO;in_memory\V_BLDG_OUTL_MOCO;in_memory\V_PROP_LINE_PGCO;in_memory\V_BLDG_OUTL_PGCO;in_memory\V_ROAD_ASPH_PGCO DWG_R2010 E:\Workspace\CADGIS\test.DWG Ignore_Filenames_in_Tables Overwrite_Existing_Files E:\Workspace\CADGIS\SeedFile.dwg Start Time: Wed Feb 12 09:50:38 2014 All the inputs are not current. Succeeded at Wed Feb 12 09:50:38 2014 (Elapsed Time: 0.00 seconds – Steve Feb 12 '14 at 14:59
  • Based on that screen shot, I would suggest you first try deleting the couple of threads from that model that didn't run successful and see if the rest of it left as is runs fine. If it does, I would re-try those threads, each individually, in their own model and see what's going on with them specifically and solve them individually first. If it doesn't run even with those threads removed from the main model though, I'm not sure what to do as I don't know the export to cad tool... could it be an issue with your inputs and seed file conflicting... if that's possible... I have no clue – John Feb 12 '14 at 16:06
  • Thanks for all your help on this. The issue is not with specific threads but rather with threads that don't output any features. This could change based on the selection set. For any given selection, if I remove threads that don't output any featuers, the export to CAD works great. Just when an input to "export to CAD" is empty does the tool not run. All it takes is one empty input and that tool doesn't run. The "techques" link I included above seems to be having the same issue except the fix there of turning true/false to lower case doesn't take in my model. It reverts to all caps. – Steve Feb 12 '14 at 17:42
  • So, just as a thought, may or may not help, depending on how the export to cad tool works, but you may try changing the If statement in calculate value to if e < 10000 and e > 0: And if that doesn't work on it's own, try doing that and using the Model Only tool Collect Values and have all the copy features output go to the collect values and then input that tool's output to the export to cad (not sure if the collect values will strip off empty inputs or not but it may...) – John Feb 12 '14 at 18:42
  • Thanks again, I tried changing the query and that alone did not work. I have previously tried the collect value tool and it did not work. I tried it again after changing the calculate value statement and it still didn't work. It gave the message: Cannot open in_memory\V_PROP_LINE_PGCO That dataset is one thats empty and I guess collect values still outputs it out. The export to CAD tool just does not seem to like empty values. – Steve Feb 12 '14 at 19:29
  • The data I'm working with covers two counties. Some feature classes cover both Counties and some are split into two feature classes, one for each County of the same data. Therefore, when you select an area in one County, some feature classes that dont' get any records selected, thus the empty features. I tried doing a merge where if a split dataset is merged and then output to "export to cad" but even the merge tool doesn't run when the calculate value tool returns false. Merging the split datasets prior to running the model is not an option at this point. – Steve Feb 12 '14 at 19:54
  • Sorry, yea, it may be time to break down and look at doing it in python (or you could maybe look at using models and sub-models and such as that, but... I'm not sure if that would make any difference, so... sorry. Good luck – John Feb 12 '14 at 20:05
  • Thanks for all your help on this. I'll update with any progress. – Steve Feb 12 '14 at 20:09
  • 1
    Since the export to cad tool was not working when it didn't receive features, I'm using a geodatabase as the input. The gdb has feature classes, some have features and some don't and this is fine with the export to cad tool. Previously the export to cad tool was not working because it was not seeing a feature class at all, vs an empty feature class. – Steve Feb 16 '14 at 15:44
  • Good to know. Glad it worked for you. So I guess when in doubt, maybe try changing input from a multi-feature class list to a workspace... Thanks for the feedback. – John Feb 17 '14 at 17:06