I am trying to persist a custom dimension style in ArcMap with Arcobjects, I am getting this error when adding the style from the Stream in the Load method.
at ESRI.Carto.IDimensionStyles.AddStyle() as DimToolbar.ApplicationExtension1.Load() in ...\DimToolbar
ApplicationExtension1.cs: line 254
Here is the Load method line 254 is line 59 below.
public void Load(IVariantStream Stream)
{
//TODO: Load persisted data from document stream
if(Stream!=null)
{
var count = (int)Stream.Read();
MessageBox.Show(count.ToString());
if (count > c_Version || count <= 0)
throw new Exception("Wrong version!");
string sName = "";
int iRefScale = 0;
string sExpression = "";
ITextSymbol pTextSymbol = null;
ILineSymbol pLineSymbol = null;
IMarkerSymbol pMrkrSymbol = null;
if (count == 2)
{
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;
IDimensionStyles pDimStyles = pDimExt.DimensionStyles;
pDimExt.UpdateProperties();
pDimStyles.AddStyle(pDimStyle);
}
catch (COMException comExcept)
{
MessageBox.Show(comExcept.StackTrace.ToString());
}
finally
{
pSchemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
}
}
}
Marshal.ReleaseComObject(Stream);
}
I am reading the stream in the same order it was written the dimension style seems to be added but there is something wrong with the text, the expression is in the dimension style after Load method runs but the text is not displayed, Here is screenshot of the python expression in the extension.