+ Reply to Thread
Results 1 to 4 of 4

Thread: I can't make "findAndReplaceWorkspacePath" work

  1. #1
    Eric Aubert
    Join Date
    Oct 2010
    Posts
    8
    Points
    0
    Answers Provided
    0


    0

    Default I can't make "findAndReplaceWorkspacePath" work

    Hello, I'm trying to repath hundreds of layer files but I have not been able to make "findAndReplaceWorkspacePath" work as intended, even using this basic example:

    Re-pointing a layer file from C to D drive:
    ---------------------------------------
    lyr = arcpy.mapping.Layer(r"C:\temp\index.lyr")
    workPath = lyr.workspacePath # workPath points to "C:\temp\index.gdb"
    workPathNew = workPath.replace("C:\","D:\")
    lyr.findAndReplaceWorkspacePath(" ", workPathNew)
    lyr.save() # result: index.lyr still points to C:\temp\index.gdb

    I tried,
    lyr.findAndReplaceWorkspacePath(workPath, workPathNew)
    lyr.save() # result: "Unexpected error"

    I tried to run the script in the Python window or Pythonwin but the results are the same.

    Thanks for any help I can get.

    BTW: lyr.saveACopy("C:\temp\index_new.lyr", "9.3") does not work for me. Here is the message I get: "function takes exactly 1 argument (2 given)"

    Eric
    Last edited by eaub490; 10-22-2010 at 10:46 AM.

  2. #2
    Jeffrey Barrette

    Join Date
    Oct 2009
    Posts
    711
    Points
    201
    Answers Provided
    64


    0

    Default Re: I can't make "findAndReplaceWorkspacePath" work

    Hello Eric,

    I'm not sure if the problem you are having is with your .replace statement. You are not using the raw (r) format, the back slashes may be causing a problem.

    Try:

    lyr = arcpy.mapping.Layer(r"C:\temp\index.lyr")
    lyr.findAndReplaceWorkspacePath(r"C:\", r"D:\")
    lyr.save()

  3. #3
    Eric Aubert
    Join Date
    Oct 2010
    Posts
    8
    Points
    0
    Answers Provided
    0


    0

    Default Re: I can't make "findAndReplaceWorkspacePath" work

    Jeff, thanks for the reply. You are correct, I should have used the "raw" format in my example, my fault.

    After carefully reading the documentation, I realized that by default the "validate" is set to True. In my case ,the database that I was trying to re-point the layer file did not exist yet. This syntax now works:

    lyr.findAndReplaceWorkspacePath("", workPathNew, False)
    or
    lyr.findAndReplaceWorkspacePath(workPath, workPathNew, False)

    Eric
    Last edited by eaub490; 10-25-2010 at 11:35 AM.

  4. #4
    Jeffrey Barrette

    Join Date
    Oct 2009
    Posts
    711
    Points
    201
    Answers Provided
    64


    0

    Default Re: I can't make "findAndReplaceWorkspacePath" work

    Hello Eric,

    Based on the testing we've done together, it appears your issue is resolved with SP1. Several issues have been addressed that are specific to change SDE data sources.

    Thanks for your help,
    Jeff

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts