import arcpy from arcpy import env environments = arcpy.ListEnvironments("workspace") for environment in environments: # As the environment is passed as a variable, use Python's getattr function # to evaluate the environment's value # envSetting = getattr(env, environment) # Format and print each environment and its current setting # print "%-28s: %s" % (environment, envSetting) desc = arcpy.Describe (envSetting) print desc.workspaceType wrkspc = desc.workspaceType print wrkspc mxd = arcpy.mapping.MapDocument ("CURRENT") df = arcpy.mapping.ListDataFrames (mxd, "Layers") [0] fcList = arcpy.mapping.ListLayers (mxd) if (desc.workspaceType == 'FileSystem'): if arcpy.Exists ("gridIndexFeatures.shp"): arcpy.Delete_management ("gridIndexFeatures.shp") else: if arcpy.Exists ("gridIndexFeatures"): arcpy.Delete_management ("gridIndexFeatures") dfAsScale = df.scale dfAsRotation = df.rotation dfAsmapUnits = df.mapUnits dfAsExtent = df.extent dfXMax = dfAsExtent.XMax dfXMin = dfAsExtent.XMin dfYMax = dfAsExtent.YMax dfYMin = dfAsExtent.YMin dfAsWidth = abs(abs(dfXMax) - abs(dfXMin)) dfAsHeight = abs(abs(dfYMin) - abs(dfYMax)) print dfAsExtent print dfXMax print dfXMin print dfYMax print dfYMin print dfAsWidth print dfAsHeight print dfAsRotation print dfAsmapUnits print fcList # Set local variables if (desc.workspaceType == 'FileSystem'): outFeatureClass = "gridIndexFeatures.shp" inFeatures = fc #inFeatures2 = "gridIndexFeatures.shp" noIntersect = "INTERSECTFEATURE" usePageUnit = "NO_USEPAGEUNIT" scale = dfAsScale polygonWidth = dfAsWidth polygonHeight= dfAsHeight else: outFeatureClass = "gridIndexFeatures" inFeatures = fc #inFeatures2 = "gridIndexFeatures" noIntersect = "INTERSECTFEATURE" usePageUnit = "NO_USEPAGEUNIT" scale = dfAsScale polygonWidth = dfAsWidth polygonHeight= dfAsHeight # Execute GridIndexFeatures arcpy.GridIndexFeatures_cartography(outFeatureClass, inFeatures, noIntersect, usePageUnit, scale, polygonWidth, polygonHeight) if (desc.workspaceType == 'FileSystem'): inFeatures = "gridIndexFeatures.shp" else: inFeatures = "gridIndexFeatures" fieldName1 = "Rotation" fieldPrecision = 18 fieldAlias = "Rotation" fieldName2 = "status" fieldLength = 10 expression = dfAsRotation arcpy.AddField_management(inFeatures, fieldName1, "DOUBLE", fieldPrecision, "", "8", fieldAlias, "NULLABLE") arcpy.CalculateField_management (inFeatures,"Rotation", expression,"PYTHON") # Set dataframe rotation to rotation of grid df.rotation = expression
Solved! Go to Solution.