I am new to coding in python, my problems is the machine crashing halfway through first loop, and yet another five with its modules .
i have "Serious Application Error" with the opportunity to send info to Esri.
i use script in toolbox, i have arcmap 10.6 .
Could you format your code so that there are line numbers and indentation can be checked
Code Formatting... the basics++
The script launches is carried out a first step [1/5] without XY event and Feature Class conversion, and in step 2/5 at the level of xy event and feature class crash conversion because the text file is created.
can be a memory problem, with the selections of different objects in different layers, is possible?
Can you describe what you want your script tool to do? A description of the tool's function may assist in getting an answer to your question.
I would suggest that you do some testing of the code before putting it in a script tool. This will help debug the script as error messages will display and help pinpoint the source of the problem.
I've retyped your code as Dan Patterson has suggested (using the syntax highlighter). This format will give some line numbers to aid in the discussion.
import arcpy, math, osarcpy.env.workspace = arcpy.GetParameter(0)arcpy.env.overwriteOutput = TrueParemListFea = arcpy.GetParameter(1)ParemSpat = arcpy.GetParameter(2)try: SpatRef = ParemSpat SelectMob = arcpy.SelectLayerByAttribute_management(MobFeat, "NEW_SELECTION", "nom = '1105'") ComMob = arcpy.GetCount_management(SelectMob) MobFeat = "Mobilier_Urbain_L" OutMob = "Mobilier0" OutTempMob = "MobilierTemp" Dbf_Mob = "Mobilier_Urbaine_L.dbf" OutTxt_Mob = "Mobilier_U_L.txt" if ListFeatIn == "Mobilier_Urbain_L.shp" and ComMob > 0: arcpy.TableToTable_conversion(Dbf_mob, arcpy.env.workspace, OutTxt_Mob) arcpy.MakeXYEventLayer_management(OutTxtMob, FieldX1, FieldY1, OutTempMob, ParemSpat, FieldZ1) arcpy.FeatureClassToFeatureClass_conversion(OutTempMob, arcpy.env.workspace, OutMob)
From the code snippet above, I notice that several variables are referenced before they are defined.
In line 9, MobFeat is being referenced, but it is not defined until line 12. Perhaps line 12 should be moved before line 9 ?
And in line 17 the value of ListFeatIn is being checked to see if it matches the name of a shape file. Perhaps ListFeatIn is supposed to be ParemListFea ? I do not see a reference to ParemListFea being used later in the script.
Line 17 also references ConMob. This value will be zero or None if the SelectLayerByAttibute fails at line 9. The where clause in line 9 is referencing a field nom and checking for a certain text string '1105' that may be a number 1105. This will affect what is being returned by the query.
These are just a few quick observations. Please tell us more about your project.
I want my script to make some layers, with different orientations, the input layer is always of type line, * _L, the orientation varies according to the layer. it is for the purpose of automation, that's why I check if the layer contains objects because all the objects of the layers are not to orientate.
if ListFeatIn == "Mobilier_Urbain_L.shp" and ComMob > 0:
the process starts without reporting an error except when I run it in the background select layer announces an error.
don't run it in the background, fails have been reported in that environment when things work in the foreground and that is the recommended solutioin
Ok, i tested my code with an orientation operation and no problem but with 5 crashes, and i have in toolbox Windows, that message: [< geoprocessing value object at 0x30AC4F98>, <geoprocessing value object object at 0x30AC4FE0>] when 5 operation.
Thank you for the additional description of your project. I am still trying to understand the work flow.
Is arcpy.GetParameter(1) around line 5 fetching a list of shapefiles, such as [ 'Mobilier_Urbain_L.shp', 'M_U_L.shp', ....] ?
And starting around line 15 to 19, is the .dbf file being converted to a text file and then into an XY layer file? Since the .dbf would be part of the shape file, is there a reason to do an XY conversion? Perhaps it would be better to converting the shape file to a feature layer with MakeFeatureLayer and then saving it with FeatureClassToFeatureClass?
tmplyr = arcpy.MakeFeatureLayer_management(r'C:\path\to\shapefile.shp','tmplyr')arcpy.FeatureClassToFeatureClass_conversion("tmplyr",r'C:\path\to\file.gdb','shp_conv')
I need to transform lines into points, because my X1Y1 are the center of the objects and X2Y2 allows me to calculate the orientation of the future symbol
The additional information is helpful. Could you share a sample of what the Mobilier_Urbain_L.shp file is like? Also, is it safe to assume that all your shape files use the same format?
I noticed that the FieldX1 used in the MakeXYEventLayer may be the field name and probably should be quoted. I am assuming there is a field in the shape file with this name. If not, you would need to set it to the field's name, such as FieldX1 = 'XfieldName'.
arcpy.MakeXYEventLayer_management(OutTxtMob, 'FieldX1', 'FieldY1', OutTempMob, ParemSpat, 'FieldZ1')
While experimenting with a line shape file, I realized that you do not need to convert the .dbf table to a text file to make use MakeXYEventLayer if it contains X and Y values. For my experiment, I created some lines and save them as a shape file. I used AddGeometryAttributes to add an XY value for the mid-point of the line. The .dbf and .prj files were used to create a point feature. Perhaps the test code will give you some ideas for your project.
import arcpy, osarcpy.env.workspace = r'C:\Users\Randy\Documents\ArcGIS\PythonScripts\test\rbTest'arcpy.env.overwriteOutput = Truedbf = 'line_test.dbf' # shape file data tablesr = arcpy.SpatialReference(os.path.join(arcpy.env.workspace,'line_test.prj')) # shape file spatial reference# print sr.name, sr.factoryCodeFieldX1 = 'MID_X' # midpoint of line featureFieldY1 = 'MID_y'FieldZ1 = NoneoutShape = 'point_test.shp'points = arcpy.MakeXYEventLayer_management(dbf, FieldX1, FieldY1, 'points', sr, FieldZ1) # make a point layerresult = arcpy.FeatureClassToFeatureClass_conversion(points, arcpy.env.workspace, outShape)print result'''# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script# The following inputs are layers or table views: "line_test"CENTROID - Adds attributes to store the centroid coordinates of each feature. (CENTROID_X, CENTROID_Y) CENTROID_INSIDE - Adds attributes to store the coordinates of a central point inside or on each feature. (INSIDE_X, INSIDE_Y)LINE_START_MID_END - Adds attributes to store the coordinates of the start, mid, and end points of each feature. (START_X, START_Y, MID_X, MID_Y, END_X, END_Y)LINE_BEARING - Adds an attribute to store the start-to-end bearing of each line feature.Values range from 0 to 360, with 0 meaning north, 90 east, 180 south, 270 west, and so on. (BEARING) arcpy.AddGeometryAttributes_management( Input_Features="line_test", Geometry_Properties="LINE_START_MID_END;CENTROID;CENTROID_INSIDE;LINE_BEARING", Length_Unit="", Area_Unit="", Coordinate_System="")'''
Hope this helps.
Retrieving data ...