“Feature class to feature class” problem in the model builder

2355
3
06-04-2017 08:51 AM
AlessandroSinglitico
New Contributor II

Hello everyone,

I'm using ArcMap10.3, in the Model builder. I'm experiencing a problem with the Feature Class to Feature Class tool. My model is actually a sub-model so it has one of the input changing at every iteration, identical fields but different rows. This is the part of the model (see the pictures).

The problem is right at where the red circle is I guess. When I run the model with my default (or first) values ("ForestCentroid_modV2") everything is ok an this is the RES_PRE.shp

But, when I run the model with new inputs (same fields, same names, just different number of rows), I have all the fields coming from that input set to 0.

And also, the input layer of the FCtoFC class seems ok. Another weird thing I noticed is that If I run the default input first, and then I change manually to the second input it gives me good results (not the zeros), while if I start from the beginning with the second input it gives me the zeros. So it happens that in a submodel this second condition will occur, the zeros.

Does anyone have any idea to solve this?

Alessandro

0 Kudos
3 Replies
curtvprice
MVP Esteemed Contributor

There two workarounds I can think of

1. Delete the layer you had as input right after you use it by connecting it to a Delete tool with the output of Feature Class to Feature class as a precondition. It's possible deleting that layer will remove a conflict of multiple layers in memory with the same name. (A shortcoming of how Esri references layers by name only.)

2. More tricky, use the Calculate Value tool with a python function that uses the arcpy.FieldMappings() objects to generate a field map on each run. I have found this (although it is a bit of work) works better than letting ModelBuilder generate the field map automatically. 

I should add that you are reaching the level of complexity (many layers, joins, field maps etc) where it starts to make sense to dig into python scripting. Model Builder is great and very useful but there is a point where you really should consider going to Python. Big models take forever to validate, and things get unstable, or you want better control of input parameter validation and the tool dialog. I think you'll know when you have reached that tipping point!

PaulLohr
Occasional Contributor III

For anyone who is having trouble with field mappings in Modelbuilder, Curtis's post on the page linked below may be helpful. This has been a great help to me. Thank you, Curtis.

"%Output Values%" is the input feature class / layer from which the field mapping is built.

The output variable from Calculate Value gets connected to the tool needing a properly built field map.

As Curtis mentioned, make sure the Calculate Value tool outputs a Field Mappings data type.

https://community.esri.com/message/836404-re-merge-buffers-after-creatingcalculating-field?commentID... 

0 Kudos
curtvprice
MVP Esteemed Contributor

Thanks so much Paul Lohr for the kudos! I appreciate very much to know that my post helped you. Could you post your Calculate Value code you used to do the field map? Always great to have actual working examples!

I would suggest making Output Values a precondition to Calculate Value to make sure the layer is created before Calculate Value runs. It did work for you without precondition set up but doing adding that connection both 1) makes absolutely sure things happen in the order they should and 2) helps users of the model easily see the flow of things in your processing.

0 Kudos