I always told myself I'm lazy but in order to achieve peak laziness and offload coding to chat GPT, I have to log in during off peak hours and remote in from home. I don't know If It's good I'm working more or bad that I'm spending all day at the office wishing I was home so I could get work done.
Currently trying to get it to make a geoprocessing script to run CAD to Geodatabase, then run Spit by Attribute on the resulting feature classes. The biggest issue I'm running into is passing along my parameters to the person using the tool.
UPDATE:
For clarity, I've only ever done Visual Basic, Excel functions and a bit of arcade label engine coding. Importing libraries is a concept that scares me, but I'm familiar with the concept of syntax, variables and looking through documentation. GPT has given me a broken skeleton I can fix and in doing so, I feel more confident that I can code my own expressions from scratch if needed.
This code is mostly generated with chat GPT but I had to do a lot of digging to figure out what it did wrong to get to this point and I know there's a lot of looping that could be done with Feature_Type_Array="Point","Line"...
The code (parameters in picture):
import arcpy
import os
# Get user-defined parameters
input_cad_dataset = arcpy.GetParameterAsText(0) # CAD dataset
new_gdb_loc = arcpy.GetParameterAsText(1) # Output geodatabase location
prefix_name = arcpy.GetParameterAsText(2) # Prefix for gdb names
# Define placeholder geodatabase
placeholder_gdb = prefix_name + "_PLACEHOLDER.gdb"
# Create a new geodatabase for each feature class
annotation_gdb = prefix_name + "_Annotation"
multipatch_gdb = prefix_name + "_MultiPatch"
point_gdb = prefix_name + "_Point"
polygon_gdb = prefix_name + "_Polygon"
polyline_gdb = prefix_name + "_Polyline"
arcpy.CreateFileGDB_management(new_gdb_loc, annotation_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, multipatch_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, point_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, polygon_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, polyline_gdb)
arcpy.CreateFileGDB_management(new_gdb_loc, placeholder_gdb)
#make a path for each
placeholder_gdb_path = os.path.join(new_gdb_loc, placeholder_gdb)
#the results of cad to geodatabase will be here. split by attibute aims here
pre_Annotation_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Annotation")
pre_Point_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Point")
pre_Polyline_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Polyline")
pre_Polygon_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Polygon")
pre_Multipatch_path = os.path.join(placeholder_gdb_path + "\\" + prefix_name, "Multipatch")
#the results of split by attribute dump here into the new databases
post_Annotation_path = os.path.join(new_gdb_loc, prefix_name + "_Annotation.gdb")
post_Point_path = os.path.join(new_gdb_loc, prefix_name + "_Point.gdb")
post_Polyline_path = os.path.join(new_gdb_loc, prefix_name + "_Polyline.gdb")
post_Polygon_path = os.path.join(new_gdb_loc, prefix_name + "_Polygon.gdb")
post_Multipatch_path = os.path.join(new_gdb_loc, prefix_name + "_Multipatch.gdb")
# Convert the CAD file to a feature class
arcpy.CADToGeodatabase_conversion(input_cad_dataset, placeholder_gdb_path, prefix_name,1000)
# Set the workspace to the placeholder geodatabase
arcpy.env.workspace = placeholder_gdb
# Split the feature classes by Layer
arcpy.SplitByAttributes_analysis(pre_Annotation_path, post_Annotation_path, "Layer")
arcpy.SplitByAttributes_analysis(pre_Multipatch_path, post_Multipatch_path, "Layer")
arcpy.SplitByAttributes_analysis(pre_Point_path,post_Point_path , "Layer")
arcpy.SplitByAttributes_analysis(pre_Polyline_path, post_Polyline_path, "Layer")
arcpy.SplitByAttributes_analysis(pre_Polygon_path, post_Polygon_path, "Layer")
Chat GPT has a few problems. There's the lack of loop awareness, placing default argument inputs from documentation in as an expression within a function's argument, occasional use of variables before they get defined, it stops mid code sometimes and it has difficulty explaining some concepts like setting parameters to new users.
To a user unfamiliar with arcpy and script tools, It can be difficult to know what GPT wants you to set for parameters, or even how to set parameters in Pro (script properties). In fact it's methodology for setting up parameters is wonky.
example:
arcpy.management.CreateFileGDB(out_folder_path, out_name, {out_version})
is the given syntax from documentation. The code it gives me is:
import arcpy
new_gdb_loc = arcpy.GetParameterAsText(1) # Output geodatabase location
prefix_name = arcpy.GetParameterAsText(2) # Prefix for gdb names
arcpy.management.CreateFileGDB(out_folder_path=new_gdb_loc, out_name=prefix_name, out_version=1000)
which gives errors "out_folder_path variable undefined" which I was able to squish easy once I knew what was wrong.
In conclusion: I'll be using GPT more, but I'm never going to expect it to give me something correct the first time. I need to use my human brain to spot it's mistakes, but once I do, it's a lot more than what I could do by myself before and I can do a lot more by myself after now.