POST
|
Thanks Jeff for your response. I still believe that being able to open up an mxd into the current (active) session is not crossing too far into the "realm of desktop customization", it would open up so many possibilities. Let's put it that way, would it be nice to have a method like this one: arcpy.mapping.MapDocumentOpen(mxd_path) Ok, I'll stop pushing your button 🙂 Eric
... View more
01-13-2011
07:32 AM
|
0
|
0
|
1457
|
POST
|
I�??m converting a mapping system into ArcPy. I�??ve made great progress but hit a stumbling block!!! I want my users to be able to pick, from a pick list, a pre-made mxd and load it into their current ArcMap session. I�??ve created this simple toolbox but�?� could not find any ArcPy method for loading an mxd into the current session? I could load layer files instead but that would defeat my purpose since the mxds have several elements in the layout (header, footer, north arrow, tailored legend, etc.) that I want to preserve . Since we can�??t create these elements in ArcPy, I am kind of stuck! Using ArcObject to do such a simple task would be kind of ridiculous too. Am I missing something here or was it an oversight in ArcPy? I can open up an mxd into a �??separate�?� session though, but that�??s not want I�??m trying to achieve: mxd = r"C:\Temp\eaub490\SUMA\Products\Timber Sales Map\Timber Sales Map.mxd" os.startfile(mxd) Any helps or comments would be greatly appreciated. Eric
... View more
01-12-2011
02:42 PM
|
0
|
8
|
11011
|
POST
|
Gaston, great question! One possible way would be to change the definition query dynamically. I wish we could dynamically query out a dataset in a DataDrivenPage but I'm afraid it's not possible for the time being in arcpy. Try this: if tile == "TILE X": [INDENT]layer.definitionQuery = "PARCEL_ID = 89 and EASEMENT = "RIGHT-OF-WAY"[/INDENT]
... View more
12-15-2010
08:13 AM
|
0
|
0
|
173
|
POST
|
Cosmin, I'm assuming that you are running your script though the ArcPy window, am I correct? If so, why not using IDLE or PythonWin instead? That way you would not need to open up an ArcMap session to do what you need to do, you would just refer to your map document object instead: mxd = arcpy.mapping.MapDocument(<mxd path>) Your issue description does not tell me why you need to "close" ArcMap. If you could elaborate then I might be able to help.
... View more
12-06-2010
07:57 AM
|
0
|
0
|
625
|
POST
|
Ok, after hours trying to figure out what's going on with the "findAndReplaceWorkspacePath" I'm just giving up and reaching out for help. So far, I am thinking that this method provides completely unexpected/unstable/unreliable results. But before I get to far with my frustrations, I need somebody to review this code and let me know what I am doing wrong. The problem is that the workspace path of the layer files don't get re-pointed to the new SDE connection file, whether I use validate = True or False. When set to True the script crashes miserably, even though the connection file/parameters is valid, so it this example I set it to False, which you would expect to work, but it does not! This scripts loops through a root folder, recursively finds all the ".lyr" file under the root and re-points the workspacePath location. It can be executed in PythonWin/Idle or the ArcMap Python window, the results are the same i.e. unexpected/unstable/unreliable i.e. the layers don't get re-pointed.
import arcpy, sys, os, traceback, time, sys, random, string
root = r"D:\eaub490\repath_layers\DNR Map Layers\Forest Management"
for path, folders, fileList in os.walk(root):
print "*************\nFolder: " + path + "\n*************"
for f in fileList:
print f
if f.endswith(".lyr"):
lyr = arcpy.mapping.Layer(path + "\\" + f)
if lyr.isGroupLayer == False:
if lyr.supports("WORKSPACEPATH"):
if ".sde" in lyr.workspacePath:
workPath = lyr.workspacePath
print " * Old:", workPath
if lyr.isFeatureLayer:
workPathNew = r"D:\eaub490\repath_layers\sde_connections_read\ropa_v10.sde" # this is a valid connection file
lyr.findAndReplaceWorkspacePath("", workPathNew, False) # when validate = True then it becomes extremely unstable and unpredictable
else:
workPathNew = r"D:\eaub490\repath_layers\sde_connections_read\raster_v10.sde"
lyr.findAndReplaceWorkspacePath("", workPathNew, False)
lyr.visible = False # turn the visibility off
lyr.save() # save to v.10
if lyr.workspacePath <> workPathNew: # check because the findAndReplaceWorkspacePath does not always works
print " * Dang! the findAndReplaceWorkspacePath does not work:", lyr.workspacePath
else:
print " * New:", lyr.workspacePath
else:
print " * Not a SDE layer"
else:
print " * Workspacepath not supported"
else:
print " * Group layer, cannot be re-pathed" # as far as I know
else:
print " * Not a layer file"
print "\nEnd of program\n"
... View more
10-29-2010
09:38 AM
|
0
|
3
|
344
|
POST
|
I don't think you can copy paste a text element since you can't create object with ArcPy.mapping. However, you can create a pool of text elements outside of yourt page layout (on the margin), and cursor through them and move them where ever you want to on your layout page. This is how I've been creating dynamic tables using ArcPy.mapping i.e. by using text elements (white background and border line), populate them, for each data driven page. Hope this helps.
... View more
10-28-2010
03:23 PM
|
0
|
0
|
290
|
POST
|
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
... View more
10-25-2010
08:56 AM
|
1
|
0
|
347
|
POST
|
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
... View more
10-21-2010
01:11 PM
|
0
|
3
|
2836
|
Title | Kudos | Posted |
---|---|---|
1 | 10-25-2010 08:56 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|