AnsweredAssumed Answered

Lyr.replaceDataSource

Question asked by dantuck_7 on Feb 14, 2018
Latest reply on Feb 15, 2018 by plsmith

Guys, I'm having problems with Lyr.replaceDataSource - it doesn’t seem to update as I’d hoped. See some testing below...

 

If it had worked we should have seen C:\Scratch\CarPositions\Import\239PM\temp\p1500_1510.txt on 2nd output line.

 

Any help appreciated. Cheers Dan

Richard Fairhurst?

 

import arcpy
... import os
... mxd = arcpy.mapping.MapDocument("CURRENT")
... df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
... lyr = arcpy.mapping.ListLayers(mxd, "*", df)[0]
... for file in os.listdir(r"C:\Scratch\CarPositions\Import\239PM\temp"):
... print file
... lyr.replaceDataSource(r"C:\Scratch\CarPositions\Import\239PM\temp", "TEXT_WORKSPACE", str(file))
... TextElement = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitleText")[0]
... TextElement.text = 'Paramics Vehicle Data: ' + str(file)[1:-11]+':'+str(file)[3:-9]+' - '+str(file)[6:-6]+':'+str(file)[8:-4]
... arcpy.RefreshActiveView()
... arcpy.RefreshTOC()
... print lyr.dataSource
...
p1500_1510.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1510_1520.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1520_1530.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1530_1540.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1540_1550.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1550_1600.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1600_1610.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1610_1620.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1620_1630.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1630_1640.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1640_1650.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1650_1700.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1700_1710.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1710_1720.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1720_1728.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1720_1730.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1730_1739.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1730_1740.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1740_1750.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
P1750_1800.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1800_1805.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1805_1810.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1810_1815.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1815_1820.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1820_1825.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1825_1830.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1830_1840.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1840_1850.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1850_1900.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1900_1910.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1910_1920.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1920_1930.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1930_1940.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1940_1950.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt
p1950_2000.txt
C:\Scratch\CarPositions\Import\239PM\proc1\p1600_1615.txt

Attachments

Outcomes