POST
|
OK I think I just can not fully explain myself. I will just continue to do it manually. Thanks for every thing.
... View more
08-08-2014
07:14 AM
|
0
|
0
|
453
|
POST
|
OK , but for the"convert labels to annotation", is there a simple way to ingrate it into a python script ? (because that's what makes me lose time, imagine I have more than 500 shapefiles to create and then convert all the labels to annotation to export all of them to CAD). That's why I was asking you to understand the "add layer" , to after activate the labels and then convert into annotation, all of this in the same python script. (Sorry if my english is not good, I'm french) Thanks.
... View more
08-08-2014
07:12 AM
|
0
|
1
|
453
|
POST
|
I understand your point, but I have more than 500 shapefiles with their labels (contour field) to create and then export all of them to CAD. Even if I create a toolbox, it takes to much time to do: - Clip Raster - Create Contour - Convert Labels to Annotations - Export to CAD So I thought by creating a tool that compile all this functions will saved me time and then share it to my colleagues. And it was a good opportunity to see how python works for future tasks.
... View more
08-08-2014
06:44 AM
|
0
|
9
|
453
|
POST
|
Yes, I want to add my OuputSHPFile (contour feature class - param3) to my currend MXD, the script is described below. So instead of expressing "OutputSHPFile", I should write "str = inputWorkspace + "\\" + OutputSHPFile", or something like that ? Because I don't want to use the path of the class, to allow my script to be used by other users. Thank you very much. import arcpy import os class Toolbox(object): def __init__(self): """Define the toolbox (the name of the toolbox is the name of the .pyt file).""" self.label = "Clip and contour Analysis" self.alias = "" # List of tool classes associated with this toolbox self.tools = [Tool] class Tool(object): def __init__(self): """Define the tool (tool name is the name of the class).""" self.label = "clip and contour" self.description = "" self.canRunInBackground = False def getParameterInfo(self): """Define parameter definitions""" param0 = arcpy.Parameter( displayName="Select shapefile (output extent):", name="in_SourceSHP", datatype="GPFeatureLayer", parameterType="Required", direction="Input") param1 = arcpy.Parameter( displayName="Raster", name="in_TargetRaster", datatype="GPRasterLayer", parameterType="Required", direction="Input") param2 = arcpy.Parameter( displayName="Raster clip", name="out_raster", datatype="DERasterDataset", parameterType="Required", direction="Output") param3 = arcpy.Parameter( displayName="Contour", name="out_features", datatype="GPFeatureLayer", parameterType="Required", direction="Output") param4 = arcpy.Parameter( displayName="Interval contour:", name="in_Interval", datatype="GPDouble", parameterType="Required", direction="Input") param4.value = 0.5 params = [param0, param1, param2, param3, param4] return params def execute(self, parameters, messages): """The source code of the tool.""" mxd =arcpy.mapping.MapDocument("CURRENT") Interval = float(parameters[4].valueAsText) OutputSHPFile = parameters[3].valueAsText RasterFile = parameters[1].valueAsText OutRasterFile = parameters[2].valueAsText ShapeFileName = parameters[0].valueAsText # Process : Clip arcpy.Clip_management(RasterFile, "#", OutRasterFile, ShapeFileName, "0", "ClippingGeometry") # Process: Contour arcpy.Contour_3d(OutRasterFile, OutputSHPFile, Interval, "0", "1") # Add shp to mxd mxd =arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] addLayer = arcpy.mapping.Layer(OutputSHPFile) arcpy.mapping.AddLayer(df, addLayer, "TOP") arcpy.RefreshActiveView() arcpy.RefreshTOC()
... View more
08-08-2014
06:01 AM
|
0
|
1
|
398
|
POST
|
Hello! I'm having the same problem... Just to better understand, if I'm not using path but defined parameters, I can not write : # Add shp to mxd mxd =arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] addLayer = arcpy.mapping.Layer(OutputSHPFile) arcpy.mapping.AddLayer(df, addLayer, "TOP") arcpy.RefreshActiveView() arcpy.RefreshTOC() Where OuputSHPFile = parameters[3].valueAsText ?? Is there a way to get my OutputSHPfile as a string and then use it in the "addLayer" ? Thanks.
... View more
08-08-2014
05:02 AM
|
0
|
4
|
3475
|
POST
|
I create this python toolbox to facilitate a big number of tasks by automating a sucession of tools. But I find out the solution thanks to all for your advices. I was just complicating myself with a tons of parameters. Thanks everyone!
... View more
08-07-2014
07:27 AM
|
0
|
1
|
366
|
POST
|
I think I went to far with my script by trying things. I'm going to simplify it as possible. For the clip, I'll try what you say to see if it works ! Thankss Johannes!
... View more
08-07-2014
06:14 AM
|
0
|
0
|
757
|
POST
|
Thank you very much for the advice Sol, I'm going to see if they can help me in the python forum. Sandrine
... View more
08-07-2014
06:06 AM
|
0
|
0
|
757
|
POST
|
The messages didn't show me something wrong. It seems that the problem come from the shapefile (inputWorkspace + "\\" + ShapeFileName + ".shp") that I used as an extent for the Clip tool. Maybe I should use an other function to obtain the extent values from the shapefile, and then put it directly in the clip tool. But I don't know how to do that... I'm going to continue my research.
... View more
08-07-2014
05:54 AM
|
0
|
2
|
757
|
POST
|
Hi Sol, Yes I've already done that. But the problem is that I want to generalize my script, so that the user of my tool will be able to choose is own shapefile (for extent to the clip tool) and his raster file. But I can't find the properly form to insert my parameters in my tool. Can you have a look to my script in attachment above, to see if you have any ideas ? Thanks for helping.
... View more
08-07-2014
05:29 AM
|
0
|
1
|
757
|
POST
|
humm this is not the answer that I was looking for...But thanks for answering me back When I start my script, there is an Error: "Traceback (most recent call last): File "<string>", line 88, in execute File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 12021, in Clip raise e ExecuteError: ERROR 999999: Error executing function. Failed to execute (Clip)." So how can I get the extent from my shapefile to make my clip tool work: arcpy.Clip_management(RasterWorkspace + "\\" + RasterFile, "#", RasterWorkspace + "\\" + OutRasterFile, inputWorkspace + "\\" + ShapeFileName + ".shp", "0", "ClippingGeometry") ?
... View more
08-07-2014
04:44 AM
|
0
|
6
|
757
|
POST
|
I'm very new at python, and I don't understand how to use the defined parameters in the source code of the tool. I'm trying to create a tool (with clip and contour tools) who can be used by any user (not specified folders or classes). My script is in attachment. Can somebody take a look ? :S Thanks
... View more
08-07-2014
04:15 AM
|
0
|
14
|
6549
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|