Hello.
I have been working on a tool that does a bunch of stuff, but the piece I am currently stuck on is getting the script to create fields where the field names are stored in a list, and the list is created using an already existing feature class. The idea is that the fields will be identical to the existing feature class in order to run the append tool. Here is what I have so far...I am having a hard time figuring out how to tell the script to create the fields based on the items in the fieldnames list using the types in the fieldtypes list.
<SPAN class="comment token">#Get list of fields and parameters from original FC.</SPAN>
fieldnames <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
fieldtypes <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
fields <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>bound<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> field <SPAN class="keyword token">in</SPAN> fields<SPAN class="punctuation token">:</SPAN>
fieldnames<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> field <SPAN class="keyword token">in</SPAN> fields<SPAN class="punctuation token">:</SPAN>
fieldtypes<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>field<SPAN class="punctuation token">.</SPAN>type<SPAN class="punctuation token">)</SPAN>
fieldnames<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">)</SPAN>
fieldnames<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SHAPE"</SPAN><SPAN class="punctuation token">)</SPAN>
fieldtypes<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"OID"</SPAN><SPAN class="punctuation token">)</SPAN>
fieldtypes<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Geometry"</SPAN><SPAN class="punctuation token">)</SPAN>
fieldtypes <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"TEXT"</SPAN> <SPAN class="keyword token">if</SPAN> x<SPAN class="operator token">==</SPAN><SPAN class="string token">"String"</SPAN> <SPAN class="keyword token">else</SPAN> x <SPAN class="keyword token">for</SPAN> x <SPAN class="keyword token">in</SPAN> fieldtypes<SPAN class="punctuation token">]</SPAN>
fieldtypes <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"DOUBLE"</SPAN> <SPAN class="keyword token">if</SPAN> x<SPAN class="operator token">==</SPAN><SPAN class="string token">"Double"</SPAN> <SPAN class="keyword token">else</SPAN> x <SPAN class="keyword token">for</SPAN> x <SPAN class="keyword token">in</SPAN> fieldtypes<SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#Add fields from list with field types.</SPAN>
<SPAN class="keyword token">for</SPAN> field <SPAN class="keyword token">in</SPAN> fieldnames<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddField_management<SPAN class="punctuation token">(</SPAN>newfc<SPAN class="punctuation token">,</SPAN> field<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">,</SPAN> field<SPAN class="punctuation token">.</SPAN>type<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks!