Select to view content in your preferred language

Why do dimensions disapear when close and open map.

510
1
06-06-2019 01:27 AM
GARYLESTER
Emerging Contributor

I create dimension feature class I change the style, add dimensions to my map but when I reopen the map the dimensions are gone? Is there documentation I can read about this behavior. I am also interested in creating dimensions with python code but I have found no examples.

Update- I created a button that creates a dim with style inside a geodatabase, now when I close and open the map the dimensions are just red polygons.

after close and open arcmap                                                                      before close and open

Here is the code I sued to create the dimension feature class.

IFeatureLayer pFeatureLayer = (IFeatureLayer)pBoundaryLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
string strCatalogPath = GetCatalogPath(pFeatureClass);
IWorkspace pWorkspace = FileGDBWorkspaceFromPropertySet(strCatalogPath);
IObjectClassDescription ocDescription = new DimensionClassDescription();
IFields pRequiredFields = ocDescription.RequiredFields;
int intShapeFieldPosition = pRequiredFields.FindField("Shape");
IField pShapeField = pRequiredFields.get_Field(intShapeFieldPosition);
IGeometryDef pGeomDef = pShapeField.GeometryDef;
IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;
ISpatialReferenceFactory3 pSpatRefFac = new SpatialReferenceEnvironmentClass();
ISpatialReference pSpatRef = pSpatRefFac.CreateSpatialReference(6578);
IProjectedCoordinateSystem pProSpatRef = (IProjectedCoordinateSystem)pSpatRef;
ILinearUnit linUnit = pProSpatRef.CoordinateUnit;
pGeomDefEdit.SpatialReference_2 = pSpatRef;
IFeatureWorkspace pFeatWorkspace = (IFeatureWorkspace)pWorkspace;
string pName = "DIM";
IFeatureClass pNewFeatureClass = pFeatWorkspace.CreateFeatureClass(pName.ToString(), pRequiredFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTDimension, "Shape", "");
ISchemaLock schemaLock = (ISchemaLock)pNewFeatureClass;
try
{
    schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);


    IDimensionClassExtension dimExtension = (IDimensionClassExtension)pNewFeatureClass.Extension;


    dimExtension.ReferenceScale = 12000;
                    
    dimExtension.ReferenceScaleUnits = esriUnits.esriFeet;


    IDimensionStyle dimensionStyle = new DimensionStyleClass();
    dimensionStyle.Name = "BEARING_DISTANCE";
    IDimensionStyleText dimText = (IDimensionStyleText)dimensionStyle;
    string expression =  "def FindLabel ( [DIMLENGTH], [BEGINX] , [BEGINY] , [ENDX] , [ENDY]  ):" + Environment.NewLine +
                            "  import math" + Environment.NewLine +
                            "  dY = float([ENDY]) -float( [BEGINY])" + Environment.NewLine +
                            "  dX = float( [ENDX])-float( [BEGINX])" + Environment.NewLine +
                            "  azimuth = math.atan2(dX, dY) * 180 / math.pi" + Environment.NewLine +
                            "  if azimuth < 0:" + Environment.NewLine +
                            "    azimuth = azimuth + 360" + Environment.NewLine +
                            "    if azimuth > 270 and azimuth<= 360:" + Environment.NewLine +
                            "      bearing = 360 - azimuth" + Environment.NewLine +
                            "      minutes,seconds = divmod(bearing * 3600, 60)" + Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)" + Environment.NewLine +
                            "      dmsBearing = \"N \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" W\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"" + Environment.NewLine +
                            "    if azimuth > 180 and azimuth<= 270:" + Environment.NewLine +
                            "      bearing = azimuth - 180" + Environment.NewLine +
                            "      minutes,seconds = divmod(bearing * 3600, 60)"+ Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)"+ Environment.NewLine +
                            "      dmsBearing = \"S \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" W\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"" + Environment.NewLine +
                            "    if azimuth > 90 and azimuth<= 180:" + Environment.NewLine +
                            "      bearing = 180 - azimuth" + Environment.NewLine +
                            "      minutes,seconds = divmod(bearing * 3600, 60)" + Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)" + Environment.NewLine +
                            "      dmsBearing = \"S \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" E\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"" + Environment.NewLine +
                            "    if azimuth >= 0 and azimuth<= 90:" + Environment.NewLine +
                            "      minutes,seconds = divmod(azimuth * 3600, 60)" + Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)" + Environment.NewLine +
                            "      dmsBearing = \"N \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" E\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"" + Environment.NewLine +
                            "  else:" + Environment.NewLine +
                            "    if azimuth > 270 and azimuth<= 360:" + Environment.NewLine +
                            "      bearing = 360 - azimuth" + Environment.NewLine +
                            "      minutes,seconds = divmod(bearing * 3600, 60)" + Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)" + Environment.NewLine +
                            "      dmsBearing = \"N \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" W\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"" + Environment.NewLine +
                            "    if azimuth > 180 and azimuth<= 270:" + Environment.NewLine +
                            "      bearing = azimuth - 180" + Environment.NewLine +
                            "      minutes,seconds = divmod(bearing * 3600, 60)" + Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)" + Environment.NewLine +
                            "      dmsBearing = \"S \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" W\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"" + Environment.NewLine +
                            "    if azimuth > 90 and azimuth<= 180:" + Environment.NewLine +
                            "      bearing = 180 - azimuth" + Environment.NewLine +
                            "      minutes,seconds = divmod(bearing * 3600, 60)" + Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)" + Environment.NewLine +
                            "      dmsBearing = \"S \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" E\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"" + Environment.NewLine +
                            "    if azimuth >= 0 and azimuth<= 90:" + Environment.NewLine +
                            "      minutes,seconds = divmod(azimuth * 3600, 60)" + Environment.NewLine +
                            "      degrees,minutes = divmod(minutes, 60)" + Environment.NewLine +
                            "      dmsBearing = \"N \" + str(int(degrees)) + \"°\" + str(int(minutes)) + \"'\" + str(round(seconds, 2)) + \" E\"" + Environment.NewLine +
                            "      return dmsBearing + \" \" + str(round(float( [DIMLENGTH]), 2))+\"'\"";
                    
    dimText.Expression = expression;
    dimText.ExpressionSimple = false;
    dimText.ExpressionParserName = "Python";
    dimText.TextDisplay = esriDimensionTextDisplay.esriDimensionTDExpression;
    dimText.ExtendLineOnFit = false;


    stdole.IFontDisp iFont = new stdole.StdFontClass() as stdole.IFontDisp;
    iFont.Name = "Arial";
    iFont.Size = 8;
    ITextSymbol txtSymbol = new TextSymbol();
    txtSymbol.Font = iFont;
    dimText.TextSymbol = txtSymbol;
    IDimensionStyleDisplay dimDisplay = (IDimensionStyleDisplay)dimensionStyle;


    dimDisplay.MarkerDisplay = esriDimensionDisplay.esriDimensionDisplayBoth;


    IArrowMarkerSymbol mrkrSym = new ArrowMarkerSymbolClass();
    mrkrSym.Size = 6;


    IMarkerSymbol newMrkrSym = (IMarkerSymbol)mrkrSym;


    dimDisplay.BeginMarkerSymbol = newMrkrSym;
    dimDisplay.EndMarkerSymbol = newMrkrSym;


    dimDisplay.MarkerFit = esriDimensionMarkerFit.esriDimensionMarkerFitText;
    IDimensionStyles dimensionStyles = dimExtension.DimensionStyles;
    dimensionStyles.AddStyle(dimensionStyle);




}
catch(COMException comExcept)
{
    MessageBox.Show(comExcept.StackTrace.ToString());
}
finally
{


    schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
    MessageBox.Show("The Dimension Feature Class Has Been Created");
}

Is there something I can add to make this layer persist?

0 Kudos
1 Reply
GARYLESTER
Emerging Contributor

I implemented persistence on the Dimension Style and now the Dimensions show up when I open a map with dimensions,

0 Kudos