[Connect Update 16 .NET] Updating element inside of cell

I've gone through all the threads I could find regarding ReplaceInModel method when it applies to elements within a cell and so far no one has provided any direction. In the code below:

TextElement origElem = (TextElement)Element.GetFromElementRef(elem.GetNativeElementRef());
TextElement t = (TextElement)elem;
TextBlock tb = t.GetTextPart(id);


tb.Remove(tb.CreateStartCaret(), tb.CreateEndCaret());

tb.InsertText(tb.CreateStartCaret(), newValue);

if (TextReplaceStatus.Success == t.ReplaceTextPart(id, tb))
{
    t.ReplaceInModel(origElem);

}

If the TextElement is within CellElement, the t.ReplaceInModel will crash microstation. Do I need to somehow update the CellElement? And if its a multi-level Cell, like Cell within a Cell, do I need to update the top level Cell?

Thanks.

Parents
  • Sure. A lot of threads report .NET API has a bug for modifying sub elements in cell. I can replicate this as well.

    Two workarounds: 1.Use Interop API as below:

    using BIM = Bentley.Interop.MicroStationDGN;
    using BMI = Bentley.MstnPlatformNET.InteropServices;
    public static void ReplaceInCell(string unparsed)
            {
                BIM.Application app = BMI.Utilities.ComApp;
                BIM.CellElement myCell = app.ActiveModelReference.GetElementByID64(583L) as BIM.CellElement;
                myCell.ResetElementEnumeration();
                int nestDepth = 0;
                while(myCell.MoveToNextElement(true, ref nestDepth))
                {
                    BIM.Element tempEl = myCell.CopyCurrentElement();
                    if (tempEl.IsTextElement())
                    {
                        BIM.TextElement oldTextEl = tempEl.AsTextElement();
                        BIM.Point3d org = oldTextEl.get_Origin();
                        BIM.Matrix3d matrix = oldTextEl.get_Rotation();
                        BIM.TextElement newTextEl = app.CreateTextElement1(oldTextEl, "ReplaceText", ref org, ref matrix);
                        myCell.ReplaceCurrentElement(newTextEl);
                    }
                }
                myCell.Rewrite();
            }

    2. Use C++ API.



  • what is the c++ version of modifiying elements within cell?

Reply Children