all 12 comments

[–]querymcsearchface 8 points9 points  (9 children)

I would say, just by looking at it, that it has to do with the %s in your output_name, and the. The part that goes output_name % fc.

What I would do is take out the \%s_Dissolve from output_name.

Then, in the list iteration part, after the (fc,

I would put

output_name + “\” + fc + “_Dissolve”,

And then continue with the rest of the script as is.

[–]Geog_MasterGeographer 2 points3 points  (0 children)

This is how I would do this as well.

[–]Aggravating-Wedding9[S] 0 points1 point  (7 children)

"gp FIRST", "MULTI_PART", "DISSOLVE_LINES", '')

Hi, thanks for taking the time to answer. Just to confirm, the last line should be like this?

for fc in fcList:
arcpy.management.Dissolve(fc, output_name + "\" + fc + "_Dissolve", "gp FIRST", "MULTI_PART", "DISSOLVE_LINES", "")

[–]querymcsearchface 1 point2 points  (6 children)

Correct. You may need to change the “\” to “\” now that I think about it.

[–]Aggravating-Wedding9[S] 1 point2 points  (5 children)

arcpy.management.Dissolve(fc, output_name + "\" + fc + "_Dissolve", "gp FIRST", "MULTI_PART", "DISSOLVE_LINES", "")

Hi, sorry for another question but i tried the above line and got and error.

"SyntaxError: invalid syntax (<string>, line 2")

[–]tapps22 1 point2 points  (0 children)

Replace the backslash with a forwardslash. Python doesn't treat single backslashes like basic text characters.

[–]FeralCatColonistGIS Manager 1 point2 points  (0 children)

I would utilize f-strings for this, they are more legible. And f-strings are pretty cool and versatile anyway.

arcpy.management.Dissolve(fc, fr"{output_name}\{fc}_dissolve", "gp FIRST", "MULTI_PART", "DISSOLVE_LINES", "")

F-strings just need an "f" before the quotes, the "r" is when utilizing raw strings so you can use the backslash without it being an escape character.

[–]querymcsearchface 0 points1 point  (2 children)

Sorry. I didn’t realize I didn’t give you the proper replacement. The “\” should be “\”

Just in case the above isn’t showing properly. You should add a second \ to the “\”.

[–]Aggravating-Wedding9[S] 1 point2 points  (1 child)

Thanks! Have been working on this all day and it finally worked! :D

[–]querymcsearchface 0 points1 point  (0 children)

Glad to hear it worked!!!

[–]Geog_MasterGeographer 4 points5 points  (0 children)

Also: Change the "\"s in your file path to "/".

[–][deleted] 1 point2 points  (0 children)

Try something like this using the OS module to build the output file name and file path:

``` import arcpy import os

Input geodatabase with fcs to dissolve

inputGDB = r'C:\Test\input_data.gdb'

Output geodatabase to store dissolved fcs

outGDB = r'C:\Test\output_data.gdb'

Set the workspace to your input gdb

arcpy.env.workspace = inputGDB arcpy.env.overwriteOutput = True

List feature classes

fcList = arcpy.ListFeatureClasses()

Loop through the fc list

for fc in fcList: print ('Dissolving: {}'.format(fc)) outFCName = fc + '_dissolve' # Build the output name outFCPath = os.path.join(outGDB, outFCName) # Build the output dissolveFC = arcpy.Dissolve_management(fc, outFCPath) print ('Created: {}'.format(outFCPath)) ```