POST
|
I've got thousands of DWG files that used to be published as MapServices since ArcGIS 10.1. In ArcGIS 10.1, CAD FeatureClass are no longer supported for MapServices I'm using CADToGeodatabase_conversion to export them to FGB format and then I add them to a map document as Layers. Now I need to apply the CAD File symbology to these Layers. Has anyone achieved this ? Here is what I've been doing so far : I first validated that the process could be done manually in ArcMap : I add my dwg file, get to its FeatureClass layer properties, change "CAD unique entity value" to "Unique values, many fields" (which match perfectly) and export it as a .lyr file. Then I could apply my .lyr file symbology to the associated CADToGeodatabase_conversion FeatureClass layer. It works fine. But I'm stuck trying to script the process : I've made a layer from the CAD file and test the symbology type :
for dwg in glob.glob("*.dwg"):
dwgPath = os.path.abspathdwg
arcpy.env.workspace = dwgPath
dwgFcList = arcpy.ListFeatureClasses()
for dwgFc in dwgFcList :
arcpy.MakeFeatureLayer_management(dwgFc,myFeatLayName)
layer = arcpy.mapping.Layer(myFeatLayName)
print layer.symbologyType
It says "OTHER" as it supposes to. If I'm adding the layer to a map document at this stage, the layer is recognized as "CAD Feature Class" but its symbology is "uniqueValue". Anyway, I thought I could change the symbology type to "Unique values, many fields", save it as a .lyr file and then apply it to my CADToGeodatabase_conversion FeatureClass layer as I've done manually. However the documentation says that you can not convert the symbology if the symbology type is "OTHER" : Depending on the symbology type, a layer's symbology can be modified. There are a limited number of supported symbology types for which properties and methods are available. It is good practice to first test the layer's symbologyType property. If a value of OTHER is returned, then the layer's symbology can't be modified. http://resources.arcgis.com/fr/help/main/10.1/index.html#//00s300000008000000 Has anyone an idea to get this working ?
... View more
09-30-2013
02:57 AM
|
0
|
1
|
703
|
POST
|
Hello khibma, I hope you didn't spend too much time writing your answer, I have absolutely no problem with the scratch directory. The problem comes from log files that are not released when executed from the toolbox. I solved it by using a text file instead of using 'logging' facilities.
... View more
08-12-2013
12:14 AM
|
0
|
0
|
2964
|
POST
|
I found something else interesting about writing logs in a text file. http://support.esri.com/es/knowledgebase/techarticles/detail/38445 Why not using python logging ? Is it possible it get in conflict with ArcGIS logging configuration ?
... View more
08-09-2013
12:28 AM
|
0
|
0
|
2964
|
POST
|
Thank you for having a look at it. This is surprising that it is not working for me. This is the problem I can see : There are two 'print' 'addMessage' in the script - The name and directory of the logfile I want to create - The actual log handlers base file arcpy.AddMessage("my log file name : "+str(outputFileLog))
print ("my log file name : "+str(outputFileLog)) and for handler in logger.handlers:
print ("my log file handler : "+handler.baseFilename) When I run this from python IDLE my two prints appear in the console and they match each other, which is what I want : >>>
my log file name : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_f4ccc4d1-00c3-11e3-835e-123142ff4c42.log
I'm getting here
my log file handler : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_f4ccc4d1-00c3-11e3-835e-123142ff4c42.log
>>> ================================ RESTART ================================
>>>
my log file name : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_0e69ed9e-00c4-11e3-840d-123142ff4c42.log
I'm getting here
my log file handler : C:\Users\ADMINI~1\AppData\Local\Temp\2\scratch\WebMap_0e69ed9e-00c4-11e3-840d-123142ff4c42.log
>>> It means a new log file is created each time. However each time I run it from the toolbox graphic interface, a new file handler pointing to the correct logfile is created but previous ones are not released and logs are written in all of them (see attachment). When I publish it to the server, not even new logs are created, the geoprocessing service just keep writing in the first log generated the first time the service started. Could it be related to the way logs are managed in ArcGIS, I saw this in the ArcGIS Server documentation that looks really similar to the problem I'm experiencing : [HTML]By default, the log files are written to <installation_location>\server\user\log on every machine. Each time ArcGIS Server restarts, new log files are created, and the server will continue to write messages to those log files until they reach the maximum log size.[/HTML] Here is my code : import arcpy, uuid, os, logging
from arcpy import env
env.overwriteOutput = True
outputDir = arcpy.env.scratchFolder
outputName = 'WebMap_{}'.format(str(uuid.uuid1()))
outputLogName = outputName + r".log"
outputFileLog = os.path.join(outputDir, outputLogName)
arcpy.AddMessage("my log file name : "+str(outputFileLog))
print ("my log file name : "+str(outputFileLog))
def createLogger(logFile):
arcpy.AddMessage("I'm getting here")
print ("I'm getting here")
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
for handler in logger.handlers:
arcpy.AddMessage("my log file name : "+handler.baseFilename)
print ("my log file handler : "+handler.baseFilename)
handler=[]
handler = logging.FileHandler(logFile)
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
for handler in logger.handlers:
arcpy.AddMessage("my log file name : "+handler.baseFilename)
print ("my log file handler : "+handler.baseFilename)
return logger
logger = createLogger(outputFileLog)
logger.info("I'm created")
del logger
I'm afraid I will have to write logs on a plain text file...
... View more
08-09-2013
12:14 AM
|
0
|
0
|
2964
|
POST
|
I have attached the sample of the script with its toolbox. That would be great if someone could have a quick look. You should notice that running it from python IDLE doesn't give the same result than running it from the toolbox (graphic interface). Running it from the toolbox graphic interface doesn't recreate the log file. I'm probably doing something wrong but I can see what it is. Thanks
... View more
08-08-2013
03:58 AM
|
0
|
0
|
2964
|
POST
|
Hello I have some difficulties with log files The problem is that running it from ArcGIS Toolbox interface doesn't give me the same result than running it from python IDLE. In python IDLE, a new logFile is created each time. When executed from ArcGIS toolbox interface, the logFile is only created once and kept in memory. Each time you run the script logs are written in the first logfile (created the first time the script is executed) rather than creating a new one. Please have a look at the sample script attached in my second post
... View more
08-08-2013
02:29 AM
|
0
|
6
|
5026
|
POST
|
Hello I'm making a geoprocessing service that returns a .pdf file As I saw in some examples I used the scratchFolder :
outputFile = os.path.join(arcpy.env.scratchFolder, myPDFFile)
arcpy.SetParameterAsText(7, outputFile)
Once published on the server, the file is recorded here : D:\arcgisserver\directories\arcgisjobs\myGeoprocessing\j8ba6feb42bce4586971ad1abc33aac81\scratch\myPDFFILE.pdf When I use the geoprocessingService it returns an 'url' : http://myServer:6080/arcgis/rest/dir.../myPDFFILE.pdf ---------------------------------------------------------- Here is my problem : I'd like to return more than just a file. I'd like to return an object that contains my file directory and other pieces of information.
def packResultsToJson(result):
# -- result looks like :
# result={}
# result['succeed']=True
# result['url']=myPDFFile
# result['failedLayers']=failedServices
# result['error']="NoError"
# result['timeElapsed'] = str(time.time() - start_time) + " seconds"
arcpy.SetParameterAsText(7, result)
In this case, my pdf directory is inside an object. Once published on the server, the physical windows path is no longer converted as a server 'url' (so the client receives : 'D:\arcgisserver\directories\arcgisjobs\myGeoprocessing\j8ba6feb42bce4586971ad1abc33aac81\scratch\myPDFFILE.pdf') Is it possible to explicitly call the function that convert the physical windows path to an url ? If this is not possible, is there a better way to achieve what I'm trying to do ?
... View more
08-05-2013
11:12 PM
|
0
|
1
|
3827
|
POST
|
Hi, I've scripted something that does what you described excepted that no .csv file is added to the map. I'm not sure you really need the csv in the mapDocument but if you really do, try to google something like 'arcpy 10.1 AddTableView' I let you read the comments in the code to understand the process. Only 'toto.mxd' and 'test.csv' exist at the first place. 'toto.lyr' and 'toto.shp' are generated from the script I've attached the folder that contains the whole thing just in case Here you go :
import arcpy, os
from arcpy import env
env.overwriteOutput = True # -----------------------------------------------------> IF YOU WANT THE OUTPUT TO BE OVERWRITED
# ------- DEFINE VARIABLES
directory = r'D:\GAIA\AG\script' # -------------------------------------------------> WHERE MY STUFF IS
mxd = arcpy.mapping.MapDocument(os.path.join(directory, r'toto.mxd')) # ------------> MXD REFERENCE
tableCSV = os.path.join(directory, r'test.csv') # ----------------------------------> TABLE REFERENCE
temp_Layer = os.path.join(directory,r'toto.lyr') # ---------------------------------> NAME FOR THE TEMPORARY LAYER TO BE GENERATED FROM 'MakeXYEventLayer_management'
temp_Layer_toShapefile = os.path.join(directory,r'toto.shp') # ---------------------> NAME FOR THE SHAPEFILE TO SAVE
# -------- CREATE XY EVENT TABLE AND SAVE IT AS A SHAPEFILE :
arcpy.MakeXYEventLayer_management(tableCSV, "X_COORD", "Y_COORD", temp_Layer) # ----> TABLE TO XY Event LAYER (temporary Layer) (inputTable, ColumnNameForX, ColumnNameForY, LayerToSave)
arcpy.CopyFeatures_management(temp_Layer, temp_Layer_toShapefile) # ----------------> COPY TEMP LAYER TO PROPER SHAPEFILE
# -------- ADD SHAPEFILE TO THE MAP :
layer_ToAdd = arcpy.mapping.Layer(temp_Layer_toShapefile) # ------------------------> CAST SHAPEFILE AS LAYER OBJECT
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] # ------------------------------> DATAFRAME REFERENCE IN MXD (DEFAULT = "Layers")
arcpy.mapping.AddLayer(df, layer_ToAdd, "TOP") # -----------------------------------> ADD LAYER TO MXD
# -------- SAVE, CLEAN UP, EXIT
mxd.save() # -----------------------------------------------------------------------> SAVE MXD
del mxd
del temp_Layer_toShapefile # --------------------------------------------------------------------------> DELETE MEMORY REFERENCE TO THE MXD (kill lock)
print 'JOB DONE'
... View more
08-05-2013
06:52 AM
|
0
|
0
|
417
|
POST
|
I've tested the "arcpy.CreateDatabaseConnection_management" and I found out that, unlike the manual process, it's possible to create a connection file from invalid user's login without receiving any alert message: try:
arcpy.CreateDatabaseConnection_management(my valid parameters, non-existing user)
except Exception as (e):
return
The connection file is created anyway. Should it be possible to had a new parameter to the method in order to check if the connection works ? (like the "validate" parameter of the MapDocument "findAndReplaceWorkspacePaths" method ) ? For now I fixed it by using "arcpy.ListUsers(myConnection)" to test the connection. Is there a better way of doing it ?
... View more
07-22-2013
08:50 AM
|
0
|
2
|
2792
|
POST
|
Hola, Que te parece usar : replaceWorkspaces Works great for me : [HTML]mxdArray = [mxdInfra, mxdCroquis, mxdOverView, mxdTerritoires, mxdPaysageA4, mxdPaysageA3, mxdPaysageA2, mxdPaysageA1, mxdPaysageA0, mxdLegend, mxdSimpleCarte] for mxd in mxdArray: for df in arcpy.mapping.ListDataFrames(mxd): print ('-----------------------------------') print ("LISTE DES SOURCES DE DONNEES A REMPLACER :") print ('-----------------------------------') for lyr in arcpy.mapping.ListLayers(mxd, data_frame=df): if lyr.supports("DATASOURCE"): print lyr.dataSource print ('-----------------------------------') print ("REMPLACEMENT DES SOURCES DE DONNEES :") print ('-----------------------------------') mxd.replaceWorkspaces(originalDataSourceGAIA, "FILEGDB_WORKSPACE", newDataSourceGAIA, "SDE_WORKSPACE", False) mxd.replaceWorkspaces(originalDataSourceSIGEXT, "FILEGDB_WORKSPACE", newDataSourceSIGEXT, "SDE_WORKSPACE", False) mxd.replaceWorkspaces(originalDataSourceSIGGAIA, "FILEGDB_WORKSPACE", newDataSourceSIGGAIA, "SDE_WORKSPACE", False) print ('-----------------------------------') print ("REMPLACEMENT DES SOURCES DE DONNEES EFFECTUE") print ('-----------------------------------') print ('-----------------------------------') print ("LISTE DES NOUVELLES SOURCES DE DONNEES :") print ('-----------------------------------') for lyrChanged in arcpy.mapping.ListLayers(mxd, data_frame=df): if lyrChanged.supports("DATASOURCE"): print lyrChanged.dataSource print ('-----------------------------------') print ("SAUVEGARDE DU MXD :") print ('-----------------------------------') mxd.save() del mxd, df[/HTML]
... View more
07-05-2013
02:41 PM
|
0
|
0
|
410
|
POST
|
Hi, The only case I've got stuck with that was because the "enabling SOE debugging" option was enabled (see attachment). For some reasons when the SOE debugging option is enabled, then the "Publishing Tool" geoprocessing service fails. Otherwise, check the ArcGIS Server logs, it must be saying something about it.
... View more
07-05-2013
02:18 PM
|
0
|
0
|
805
|
POST
|
I didn't explain the whole context : I'm trying to get the service layer properties from a map document created from the "ConvertWebMapToMapDocument" function. If I manually had a service layer into a map document and then run the script above, then it works. The top node of the serviceLayer supports "serviceProperties" However if I run the same script against a mxd that have been generated from the "ConvertWebMapToMapDocument" then the top node of the serviceLayer doesn't seem to be recognized as the ServiceLayer root and doesn't supports "serviceProperties".
... View more
06-20-2013
04:09 AM
|
0
|
0
|
847
|
Online Status |
Offline
|
Date Last Visited |
11-16-2022
02:19 PM
|