[MicroStation 10.14 C#] Create Note dimension element text

Referencing a previous post about creating dimension elements in C#: https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/112608/c-connect-how-to-create-dimension-elements

I've been trying to create a Note type dimension element, I've successfully been able to create the correct leader for the note using the DimensionType.Note parameter from the code in the article above. I'm trying to figure out how to add text to the note. I see where I can get the textparts if the dimension already exists (and replace the text if it already exists), just can't figure out how to add text.

Below is the code for what I have so far

Symbology symbology = new Symbology();
symbology.Color = SymbologyValue.ColorByLevel;
symbology.Weight = SymbologyValue.WeightByLevel;
symbology.Style =(int) SymbologyValue.StyleByLevel;
FileLevelCache fileLevelCache = Session.Instance.GetActiveDgnFile().GetLevelCache();
LevelHandle levelHandle = fileLevelCache.GetLevelByName(textLevelName, true);
DirectionFormatter directionFormatter = new DirectionFormatter(Session.Instance.GetActiveDgnModel());

//following class implemented from BDN article 
//https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/112608/c-connect-how-to-create-dimension-elements
CreateDimCallback createDimCallback = new CreateDimCallback(dimensionStyle, textStyle, symbology, levelHandle.LevelId, directionFormatter);
DimensionElement dimensionElement = new DimensionElement(Session.Instance.GetActiveDgnModel(), createDimCallback , DimensionType.Note);
DPoint3d firstPt = new DPoint3d(0, 0, 0);
DPoint3d secondPt = new DPoint3d(100,100,0);
DPoint3d thirdPt = new DPoint3d(200,200, 0);
dimensionElement.InsertPoint(firstPt, null, dimensionStyle, 0);
dimensionElement.InsertPoint(secondPt, null, dimensionStyle, 0);
dimensionElement.InsertPoint(thirdPt, null, dimensionStyle, 0);
dimensionElement.SetHeight(100);
dimensionElement.ApplyDimensionStyle(dimensionStyle, true);

TextQueryOptions textQueryOptions = new TextQueryOptions();
textQueryOptions.ShouldIncludeEmptyParts = true;
TextPartIdCollection textPartIds = dimensionElement.GetTextPartIds(textQueryOptions); //this method returns no TextPartIds on a new dimensionElement
foreach (TextPartId txi in textPartIds)
{
    TextBlock textBlock = dimensionElement.GetTextPart(txi);
}

Parents Reply
  • Thanks Jan, that did what I needed.

    Little strange it requires 2 different methods that "out" my leaderElement but it works.

    DgnModel activeModel = Session.Instance.GetActiveDgnModel();
    TextBlock textBlock = new TextBlock(textStyle, activeModel);
    textBlock.AppendText("My Note");
    Element leaderElement = null;
    DPoint3d[] leaderPoints = new DPoint3d[3] { firstPt, secondPt, thirdPt }; //3 pts for leader already defined
    NoteCellHeaderElement noteCellHeaderElement = new NoteCellHeaderElement(out leaderElement, textBlock, dimensionStyle, activeDgnModel, leaderPoints);
    noteCellHeaderElement.AddToModel(out leaderElement, dgnModel);

    Answer Verified By: Mike Robertson 

Children
No Data