Microstation ConnectSDK I cannot modify existing text in textblock

Hello, I am scanning a file for text and pass the MSElementDescr to my function for modification.  I have tried a number of methods from the examples file.  I can ADD text, but my ability to modify the existing simple text string seems to be lacking something.  Is there an element add needed, or am I using the incorrect process for modifying existing text?  I am fairly new to programming for Microstation, are there any books explaining how to program for Microstation using Visual Studio 2017 in c++?

Public void getText(MSElementDescr *elm) {

ElementHandle eh(elm,false);
EditElementHandle eeh(elm, true, true, 0);

TextBlockPtr textBlock = TextHandlerBase::GetFirstTextPartValue(eh);
CaretPtr searchStart =textBlock->CreateStartCaret();
CaretPtr searchEnd = textBlock->CreateEndCaret();
ITextQueryCP textQueryHandler = eh.GetITextQuery();

if (!textQueryHandler || !textQueryHandler->IsTextElement(eh)) {
return;
}


ITextEditP textEdit = eh.GetITextEdit();
ITextPartIdPtr textPart;
TextBlockPtr textBlock = textEdit->GetTextPart(eh, *textPart);

if (!textBlock.IsNull() && !textBlock->IsEmpty())
{
WString strW = textBlock->ToString();
 CaretPtr startCaret = textBlock->CreateStartCaret();
  CaretPtr endCaret = textBlock->CreateEndCaret();
   WString originalString = textBlock->ToString();


if (0 == originalString.compare(L"TEXT_TO_MATCH"))

{
std::wostringstream oss;
oss << "this is a test";
textBlock->ReplaceText(oss.str().c_str(), *textBlock->CreateStartCaret(), *textBlock->CreateEndCaret());//CHANGES TEXT IN TEXTBLOCK, BUT NOT IN DESIGN FILE
textBlock->PerformLayout();//DESPERATE TEST TO SEE IF IT WOULD UPDATE FILE... BUT NO
textEdit->ReplaceTextPart(eeh, *textPart, *textBlock);

//THESE REMAIN FROM MY FAILED TESTS BELOW
//ElementRefP erp = eeh.GetElementRef();
//MSElementCP msecp = eeh.GetElementCP();


//eeh.ReplaceInModel(erp); //doesn't work
//eeh.ReplaceElement(msecp); doesn't work
//textBlock->AppendText(oss.str().c_str());//doesn't work
//eeh.AddToModel();//will add element to file, keeps old element this works.
}

}

}

Parents
  • Hello Jan, I'm still struggling with no success trying to change a simple text string from aaaaaa to bbbbb.  Is there a working example that will do this somewhere that I can see what I'm missing?  All I can find in the provided examples are number increments and property changes.
    Thanks,
    John

  • Still nothing, 2 weeks of simply trying to modify an existing text string.  Non of the examples demonstrate what I'm trying to do, which is change a string of text in a design file from aaaa to bbbbbbbb.  There has to be something missing, the "eeh.ReplaceInModel(erp)" shown in my code above returns a status of 32768.  But then, none of the other examples show any type of element rewrite back into the file, simply change the textblock using textBlock->ReplaceText(ts.GetWCharCP(), *caretStart, *caretEnd) according to the sample routines should do the trick, but doesn't.

    Help....please!

Reply
  • Still nothing, 2 weeks of simply trying to modify an existing text string.  Non of the examples demonstrate what I'm trying to do, which is change a string of text in a design file from aaaa to bbbbbbbb.  There has to be something missing, the "eeh.ReplaceInModel(erp)" shown in my code above returns a status of 32768.  But then, none of the other examples show any type of element rewrite back into the file, simply change the textblock using textBlock->ReplaceText(ts.GetWCharCP(), *caretStart, *caretEnd) according to the sample routines should do the trick, but doesn't.

    Help....please!

Children
No Data