I made a script that works with a GDB, the script do the topology process with 8 rules to control, and at the end I have realised a exception of errors because all of datas generated in the GDB aren´t errors for example, dangles, then all of these process I have repeated for each element of topology and to add the 8 rules too.
I'am looking and trying to apply functions to perform my script, but I can´t understand on the whole how it work, I am new in the progamation but I think its is possible, I posted part of the script below. sorry for my english, Thanks again
Topology in 3 elements (cerca_l_Topolgia, rio_l_Topolgia, via_l_Topolgia ) repeat three times the same process in diferent elements.
## Define the DataSet and the FeatureClass
ds = DataSet , fc = FeatureClass ##
elif ds == "GS_ASOCIADO_A_POBLADOS" and fc == "cerca_l_Topolgia" :
input_dataset = ds
input_Fclass = fc
topo_name = "Planimetria_Topologia"
cluster_tol = 0.001
topoReglas = ["Must Not Overlap (Line)", "Must Not Intersect (Line)", "Must Not Have Dangles (Line)", "Must Not Have Pseudo-Nodes (Line)", "Must Not Self-Overlap (Line)","Must Not Self-Intersect (Line)","Must Not Intersect Or Touch Interior (Line)", "Must Be Single Part (Line)"]
validate = "true"
#Crear topologia de Planimetria
out_topo = arcpy.CreateTopology_management(input_dataset, topo_name, cluster_tol)
print("Created topology.")
#Añadir FeatureClass a la Topologia
arcpy.AddFeatureClassToTopology_management(out_topo, fc, 1, 1 )
print(arcpy.GetMessages())
arcpy.AddMessage("Iniciando Topología de Planimetría.")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[0], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[1], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[2], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[3], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[4], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[5], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[6], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[7], fc,"","","")
arcpy.AddMessage("Validando Topología de Planimetría")
arcpy.ValidateTopology_management(out_topo)
arcpy.AddMessage("Topología de Planimetría Finalizada.")
# Exportar errores de Planimetria
arcpy.ExportTopologyErrors_management(out_topo, ds, "Errores_Planimetria")
arcpy.AddMessage("Finalizado.")
#Topologia de Hidrografia
#Definicion de Variables
elif ds == "HO_AGUAS_INTERIORES" and fc == "rio_l_Topolgia":
input_dataset = ds
input_Fclass = fc
topo_name = "Hidrografia_Topology"
cluster_tol = 0.001
topoReglas = ["Must Not Overlap (Line)", "Must Not Intersect (Line)", "Must Not Have Dangles (Line)", "Must Not Have Pseudo-Nodes (Line)", "Must Not Self-Overlap (Line)","Must Not Self-Intersect (Line)","Must Not Intersect Or Touch Interior (Line)", "Must Be Single Part (Line)"]
validate = "true"
#Crear topologia de Hidrografia
out_topo = arcpy.CreateTopology_management(input_dataset, topo_name, cluster_tol)
print("Created topology.")
#Añadir FeatureClass a la Topologia
arcpy.AddFeatureClassToTopology_management(out_topo, fc, 1, 1 )
print(arcpy.GetMessages())
arcpy.AddMessage("Iniciando Topología de Hidrografia.")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[0], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[1], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[2], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[3], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[4], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[5], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[6], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[7], fc,"","","")
arcpy.AddMessage("Validando Topología de Hidrografía")
arcpy.ValidateTopology_management(out_topo)
arcpy.AddMessage("Topología de Hidrografía Finalizada.")
# Exportar errores de Hidrografia
arcpy.ExportTopologyErrors_management(out_topo, ds, "Errores_Hidrografia")
arcpy.AddMessage("Finalizado.")
#Topologia de Vialidad
#Definicion de Variables
elif ds == "IT_TRANSPORTE_TERRESTRE" and fc == "via_l_Topolgia":
input_dataset = ds
input_Fclass = fc
topo_name = "Vialidad_Topology"
cluster_tol = 0.001
topoReglas = ["Must Not Overlap (Line)", "Must Not Intersect (Line)", "Must Not Have Dangles (Line)", "Must Not Have Pseudo-Nodes (Line)", "Must Not Self-Overlap (Line)","Must Not Self-Intersect (Line)","Must Not Intersect Or Touch Interior (Line)", "Must Be Single Part (Line)"]
validate = "true"
#Crear topologia de Vialidad
out_topo = arcpy.CreateTopology_management(input_dataset, topo_name, cluster_tol)
#Añadir FeatureClass a la Topologia
arcpy.AddFeatureClassToTopology_management(out_topo, fc, 1, 1 )
print(arcpy.GetMessages())
arcpy.AddMessage("Iniciando Topología de Vialidad.")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[0], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[1], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[2], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[3], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[4], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[5], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[6], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[7], fc,"","","")
arcpy.AddMessage("Validando Topología de Vialidad")
arcpy.ValidateTopology_management(out_topo)
#print(arcpy.GetMessages())
arcpy.AddMessage("Topología de Vialidad Finalizada.")
# Exportar errores de Vialidad
arcpy.ExportTopologyErrors_management(out_topo, ds, "Errores_Vialidad")
arcpy.AddMessage("Finalizado.")
If you use the "syntax highlighter", your code will be easier for people to make suggestions and comments. Expand the toolbar ...
and click on "Syntax highlighter".
Once using the highlighter, select "Python" and paste your code in the box. This will provide line numbers that will assist in discussing your code.
For more, see: Code Formatting... the basics++
Thanks I posted again the script..!!
In the future, please don't re-post the question (see https://community.esri.com/thread/217650-recursive-or-functions-script-topology ). Either update the original text of the question or state the update/clarification as a comment to the original thread.
Sorry Joshua I apologize, I am new in the community, I´ll try to do the quiestions in the correct way in the future
I haven't worked with topology, but after exploring the documentation, I wonder if "(Line)" should be included in your rules.
topoReglas = ["Must Not Overlap (Line)", "Must Not Intersect (Line)", "Must Not Have Dangles (Line)", "Must Not Have Pseudo-Nodes (Line)", "Must Not Self-Overlap (Line)","Must Not Self-Intersect (Line)","Must Not Intersect Or Touch Interior (Line)", "Must Be Single Part (Line)"]
# should it be? :
topoReglas = ["Must Not Overlap", "Must Not Intersect", "Must Not Have Dangles", "Must Not Have Pseudo-Nodes", "Must Not Self-Overlap","Must Not Self-Intersect", "Must Not Intersect Or Touch Interior", "Must Be Single Part"]
And it might make your code more readable and indexing simpler ...
# instead of:
arcpy.AddRuleToTopology_management(out_topo, topoReglas[0], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[1], fc,"","","")
arcpy.AddRuleToTopology_management(out_topo, topoReglas[2], fc,"","","")
...
# try
for regla in topoReglas:
arcpy.AddRuleToTopology_management(out_topo, regla, fc,"","","")