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.
You need to create a Layer Object from your feature class then add that layer to your mxd.
This might help: ArcGIS Desktop
and look at the save method here: ArcGIS Help 10.1
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"
arcpy.MakeFeatureLayer_management(FC, "nameoffeatureclass")
Sir I am making Feature layer first.
arcpy.MakeFeatureLayer_management creates datasource of the layer in .gdb
how to add that datasouce in MXD?
You need to create a Layer Object from your feature class then add that layer to your mxd.
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.
The arcpy.mapping Layer function was removed in ArcGIS Pro, it has been replaced with LayerFile. If one looks at the Summary for Layer:
Summary
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:
arcpy.MakeFeatureLayer_management("C:/data/mexico.gdb/cities","cities_lyr")
AddLayer (data_frame, "cities_lyr")
Thanks all of you for your help...........