Is Persistence Possible For Dimension Features Using ArcObjects?

258
0
06-15-2019 05:03 AM
GARYLESTER
New Contributor

I have a dimension feature class with a custom text expression, I would like to persist this dimension style so that the dimensions in my map do not disappear. I am currently trying to get schema lock on dimension feature class and Add the dimension style back to the Feature Class when the map opens. When I save and then reopen the map all the dimension style is present except the bearing expression but when I look at properties of dimension style in the feature class the expression is there. The next thing I am going to try is to write the dimension shape and properties to the stream and then recreate the feature class and add the features when the map is reopened, These dimensions are really hard to work with is there a workaround that behave similarly to bearing and distance style dimension I can use for property plats?

Here is the Load and Save methods I am using.

public void Load(IVariantStream Stream)
        {
            //TODO: Load persisted data from document stream
            if(Stream!=null)
            {
                string sName = "";
                int iRefScale = 0;
                string sExpression = "";
                ITextSymbol pTextSymbol = null;
                ILineSymbol pLineSymbol = null;
                IMarkerSymbol pMrkrSymbol = null;
            
                sName = (string)Stream.Read();
                iRefScale = (int)Stream.Read();
                sExpression = (string)Stream.Read();
                pTextSymbol = (ITextSymbol)Stream.Read();
                pLineSymbol = (ILineSymbol)Stream.Read();
                pMrkrSymbol = (IMarkerSymbol)Stream.Read();

                ILayer pLayer = ReturnLayerByName("DIM");
                IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                ISchemaLock pSchemaLock = (ISchemaLock)pFeatureClass;
                try
                {
                    pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                    IDimensionClassExtension pDimExt = (IDimensionClassExtension)pFeatureClass.Extension;
                    pDimExt.ReferenceScale = iRefScale;
                    pDimExt.ReferenceScaleUnits = esriUnits.esriFeet;
                    IDimensionStyle pDimStyle = new DimensionStyleClass
                    {
                        Name = sName
                    };
                    IDimensionStyleDisplay pNewDimDisplay = (IDimensionStyleDisplay)pDimStyle;
                    pNewDimDisplay.MarkerDisplay = esriDimensionDisplay.esriDimensionDisplayBoth;
                    pNewDimDisplay.DimensionLineSymbol = pLineSymbol;
                    pNewDimDisplay.BeginMarkerSymbol = pMrkrSymbol;
                    pNewDimDisplay.EndMarkerSymbol = pMrkrSymbol;
                    pNewDimDisplay.MarkerFit = esriDimensionMarkerFit.esriDimensionMarkerFitText;
                    pNewDimDisplay.MarkerDisplay = esriDimensionDisplay.esriDimensionDisplayBoth;
                    pNewDimDisplay.DrawLineOnFit = false;
                    IDimensionStyleText pNewDimText = (IDimensionStyleText)pDimStyle;
                    pNewDimText.Expression = sExpression;
                    pNewDimText.ExpressionParserName = "Python";
                    pNewDimText.TextDisplay = esriDimensionTextDisplay.esriDimensionTDExpression;
                    pNewDimText.TextSymbol = pTextSymbol;

                    pDimExt.UpdateProperties();

                    IDimensionStyles pDimStyles = pDimExt.DimensionStyles;
                    pDimStyles.AddStyle(pDimStyle);
                }
                catch (COMException comExcept)
                {
                    MessageBox.Show(comExcept.StackTrace.ToString());
                }
                finally
                {
                    pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                }

                
            }
            Marshal.ReleaseComObject(Stream);



        }

public void Save(IVariantStream Stream)
        {
            //TODO: Save extension related data to document stream
            if (DimStyleModel.Name != "")
            {
                Stream.Write(DimStyleModel.Name.ToString());
                MessageBox.Show(DimStyleModel.Name.ToString());
                Stream.Write(DimStyleModel.RefScale);
                Stream.Write(DimStyleModel.Expression);
                Stream.Write(DimStyleModel.TextSymbol);
                Stream.Write(DimStyleModel.LineSymbol);
                Stream.Write(DimStyleModel.MrkrSymbol);
            }
            Marshal.ReleaseComObject(Stream);
        }
0 Kudos
0 Replies