I have a layer Test generated by arcpy.MakeFeatureLayer_management and Dissolved by arcpy.Dissolve_management ..
I know that this layer is in .gdb data source..
How can i add this layer to my .MXD and save that .MXD using PYTHON?
Solved! Go to Solution.
ok I got how to save MXD , and add Layer in MXD...
But that layer is exist on disk with .lyr extension ..
My layer data is in .gdb datasource.... how to add layer from .gdb source to MXD?
Am i Getting it right?
Hi Waqar, you just need to make a feature layer first, then add the layer the way Tim describes:
C = r"C:\...\featureclass"
The accepted answer on StackExchange works for ArcGIS Desktop, which is what the OP was asking about, but the accepted answer won't work for ArcGIS Pro.
Provides access to layer properties and methods. It can either reference layers in a map document (.mxd) or layers in a layer (.lyr) file.
It turns out, the accepted answer on StackExchange was never supposed to work but it does. Originally, arcpy.mapping Layer was designed to work on layers in MXDs or existing layer files, but there was a bug that allowed it to work directly against some data sources (but not all). Since the hack was fairly common place, the bug wasn't fixed, until ArcGIS Pro. To avoid confusion over changed functionality and having people submit bug reports, Layer was renamed LayerFile to emphasize how it is designed to work.
I can't remember right off the top what the workflow is in Pro. I will post it later if I find it or remember.
After you make the feature layer, use the add layer scrip. For example:
AddLayer (data_frame, "cities_lyr")