We are working to get the text block with fractional value, and create text element with it. The code below is the implementation we have performed, but while creating text element with text block as fractional value, it does not creates element and returns null, while for normal value it works fine.
private static TextBlock GetTextBlockColumn() { DgnFont df = DgnFontManager.FindSystemFont("WORKING", DgnFontFilterFlags.All); DgnFile activeDgnFile = GetActiveDgnFile(); DgnModel activeDgnModel = GetActiveDgnModel(); ModelInfo modelInfo = activeDgnModel.GetModelInfo(); double uorscale = modelInfo.UorPerMaster; DPoint3d scalefactor = Bentley.MstnPlatformNET.Settings.Scale; DgnTextStyle bomColumnStyleFraction = new DgnTextStyle("bom_columnstyle_fraction", activeDgnFile); bomColumnStyleFraction.SetProperty(TextStyleProperty.Height, (uorscale * scalefactor.X * 2.0)); bomColumnStyleFraction.SetProperty(TextStyleProperty.Width, (uorscale * scalefactor.X * 1.64)); bomColumnStyleFraction.SetProperty(TextStyleProperty.Fractions, true); bomColumnStyleFraction.SetFontProperty(TextStyleProperty.Font, df); bomColumnStyleFraction.Add(activeDgnFile); TextBlockProperties textBlockProperties = new TextBlockProperties(bomColumnStyleFraction, activeDgnModel); //textBlockProperties.MaxCharactersPerLine = 70; textBlockProperties.IsViewIndependent = false; ParagraphProperties paragraphProperties = new ParagraphProperties(bomColumnStyleFraction, activeDgnModel); paragraphProperties.Justification = TextElementJustification.LeftTop; //paragraphProperties.LineSpacingType = DgnLineSpacingType.Automatic; RunProperties runProperties = new RunProperties(bomColumnStyleFraction, activeDgnModel); return new TextBlock(textBlockProperties, paragraphProperties, runProperties, activeDgnModel); } private static void SetFraction(string value, ref TextBlock tb) { int pindex = value.IndexOf("/"); if (pindex == -1) { tb.AppendText(value); } else { char[] characters = value.ToCharArray(); char[] nospacedcharacters = new char[characters.Length]; int length = characters.Length; //remove spaces for (int cindex = 0, index2 = 0; cindex < length; cindex++) { if (characters[cindex] == ' ') continue; nospacedcharacters[index2] = characters[cindex]; index2++; } int nslength = nospacedcharacters.Length; for (int cindex = 0; cindex < nslength;) { if (nospacedcharacters[cindex] == '\0') { break; } if ((cindex == nslength - 1) || (nospacedcharacters[cindex + 1] == '\0')) { tb.AppendText(nospacedcharacters[cindex].ToString()); break; } if (nospacedcharacters[cindex] == '/') { tb.AppendStackedFraction(nospacedcharacters[cindex - 1].ToString(), nospacedcharacters[cindex + 1].ToString(), StackedFractionType.DiagonalBar, StackedFractionAlignment.Middle); cindex = cindex + 2; continue; } if (nospacedcharacters[cindex + 1] != '/') { tb.AppendText(nospacedcharacters[cindex].ToString()); } cindex++; } } } static public void PlaceText ( DPoint3d rDpOrginP, DgnModel dgnModel, Structure.EGD_SIMPLE_SYMBOLOGY symbologyP, TextBlock textBlock, bool rBoolCreateFlag ) { TextElement telement = TextElement.CreateElement(null, textBlock) as TextElement; // PROBLEM HERE WHEN TEXT IS FRACTION if(telement != null) { LevelId levelId = dgnModel.GetLevelCache().GetLevelByName(symbologyP.levelName).LevelId; ElementPropertiesGetter getter = new ElementPropertiesGetter(telement); ElementPropertiesSetter setter = new ElementPropertiesSetter(); setter.SetColor(symbologyP.color); setter.SetWeight(symbologyP.weight); setter.SetLinestyle(symbologyP.LineStyle, getter.LineStyle); setter.SetLevel(levelId); setter.Apply(telement); } if (rBoolCreateFlag) telement.AddToModel(); else SelectionSetManager.AddElement(telement, dgnModel.GetParentModelRef()); } Structure.EGD_SIMPLE_SYMBOLOGY symbology1; symbology1.color = 0; symbology1.weight = 0; symbology1.LineStyle = 0; symbology1.levelName = "Level 49"; //Consumer DPoint3d[] dpoints = new DPoint3d[2]; dPoints[0] = //3d point TextBlock textBlockSize = GetTextBlockColumn(); SetFraction(bomelement.SIZE, ref textBlockSize); // Value is 1/2 textBlockSize.SetUserOrigin(dPoints[0]); PlaceText(dPoints[0], dgnModel, symbology1, textBlockSize, true);
Any help, completes our solution
Regards,
Varsha