Python or Model Builder

4546
22
11-13-2014 07:51 AM
RickWarner
New Contributor III

I have developed a model that the first step is to select records for a table with field name Sales, I manually now change sql expression from Sale 1 to Sale 2 etc, there are about 50 groups of sales. Once the  group is selected, it then is joined with a polygon feature Parcels, records copied, join removed and then onto the next group of sales (There are upto 50 sales for each parcel, so a simple join doesn't work,)

I would like to automate the sql expression that initially selects the records,  so that once the first group of sales is copied, join removed,  the table then selects the next group of sales.  Also I need a way to change the name of the copied features to match the sales group, so it doesn't overwrite.

The model works fine now, except that I must manually change the sql expression after each sale group and change the copied features name so it doesn't overwrite the previous sales group.

How can I automate the sql expression, if that is the appropriate approach?

Thank you.

Tags (2)
0 Kudos
22 Replies
RichardFairhurst
MVP Honored Contributor

I am using list comprehensions all over my code now and have experienced no problems.  Until one crops up, I will continue to use them.

0 Kudos
XanderBakker
Esri Esteemed Contributor

I haven't had any negative experience with them either and truly believe that a day without list comprehensions is a day not lived (or coded actually)...

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I think insert and update cursors were more the target for enabling with statements than search cursors, but people have a tendency to want to keep best practices simple.  Instead of having one best practice for insert and update cursors and a different one for search cursors, we have ended up with one for all three.

I like list comprehensions, and I think they can work well with search cursors.  I was just pointing out the trade-offs of the two approaches, not trying to evangelize one over the other.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Xander is that in Python Snippets?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Dan,

I have a separate post on that... Using Python List Comprehensions

May have to rethink the python snippets and move things over to the python snippets place..

0 Kudos
RickWarner
New Contributor III

Thank you, does this then allow me to group by sales grouping, ie Sales 1, say 100 records, then join them to a parcel map, copy features, then go on to the next Sales Group 2, say 200 records  and repeat join copy records?

0 Kudos
RickWarner
New Contributor III

Thank you for your help,

I'm getting this error, what do you Think I'm doing wrong??

Runtime error  Traceback (most recent call last):   File "<string>", line 24, in <module>   File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5748, in MakeFeatureLayer     raise e ExecuteError: ERROR 000840: The value is not a Feature Layer. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

What is the backend storage format?  File geodatabase?  ArcSDE geodatabase?  I ask because there may be other approaches that work more efficiently if the data is all stored in a DBMS.

RickWarner
New Contributor III

I'm now getting a "Parsing error SyntaxError: invalid syntax (line 1)", which is the import arcpy statement. what could I now be doing wrong? I'm typing   import arcpy??

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Can you include more of the error message?

0 Kudos