Hi,
I'm working on a code that I would like to share and, ideally, I want to use relative paths. However, I've tried several approaches and found that it only works when I use the complete path.
Here's a simplified example where I attempt to insert a feature from a geodatabase:
# Path to your feature class in the geodatabase
feature_class_path = feature_path
# Get the current project
project = arcpy.mp.ArcGISProject("CURRENT")
# Get the active map (or specify which map to use)
map_object = project.listMaps()[0] # Assuming you want the first map
# Add the feature class to the map
map_object.addDataFromPath(feature_class_path)
print(f"Feature class '{feature_class_path}' added to the map.")
When I set feature_class_path using a relative path like this:
feature_class_path = r".\UpdatePoints\UpdatePoints.gdb\Earthquakes_points"
it doesn't work. If I use:
feature_class_path = os.path.join(".", "UpdatePoints", "UpdatePoints.gdb", "Earthquakes_points")
it still doesn't work.
The code only functions correctly when I use the full path:
feature_class_path = r"C:\Users\YourUsername\Documents\UpdatePoints\UpdatePoints.gdb\Earthquakes_points"
Why is that?