I need a python script that I can use to create a schematic diagram, and add it to an mxd. This must be done in an independent script and I cannot do it in arcmap.
The problem is I can't get arcpy to add the diagram layer to the map. I run arcpy.schematics.CreateDiagram to create the diagram and that works, but when I try to use arcpy.mapping.AddLayer to add the return from the diagram it throws an AssertionError. I have also tried to use arcpy.mapping.Layer but that throws the same error.
Can someone PLEASE tell me how to add a schematic diagram to an MXD with arcpy?
I had to deal with the same requirement and I ended up to convert the diagram to features which results in feature classes in a feature dataset. You can easily add these feature classes to the MXD then. You need a template-MXD with the correct symbology for all layers, because the symbology is lost when converting the diagrams to features. You can then programatically switch the data sources from the template-MXD to point to the converted feature classes.
If you want to export the map/layout to PDF/PNG and you have rotated symbols or label expressions, please note that you might have to use python 32 bit and not 64 bit because of the following Bugs: BUG-000093736; BUG-000092016
As far as I know this is the only solution but if somebody knows another solution I'm happy to hear about it.
I've been working my way through options to try not to do what you've suggested but I've not been able to find an alternative that works.
MakeFeatureLayer doesn't appear to support Schematic Datasets and gives an error using arcpy.
You can't update the data source on a Schematic Dataset using arcpy tools. Top note in the 'known limitations' section.
I've been considering trying to make one schematic that I keep overwriting so that I only need one mxd, or having 1000 mxd files but those sound terrible and painful.
I'm going to implement the idea you mentioned above. I'm going to export my schematic to a temporary geodatabase and use that to create a grid on top of, generate my pdf series for that schematic #with Data Driven pages, then move on to the next schematic.
schematics ddp data driven pages
Some slight changes to my process now that I've actually gotten something working, this keeps almost all the data created during the process.
Nice things I get from this are all of the feature classes and schematic diagrams continue to exist after the bulk process. You could open or update them individually if you wanted to make a one off. You could let this data structure live forever and next time through just update instead of create everything from scratch. I haven't saved out individual mxd files yet after repointing the data, but that could be done. This process is being used to automate generating 900-1000 diagrams.