this is probably a dumb question but...im still learning/grasping on the c++ api works, im used to vba and C#, to update an element there was always .redraw.
i have a text element that i added a field to. but now i need to redraw the text element to the model. looking through the examples for text they all place new elements or just change properties...want to make sure im doing it correctly.
i saw there is a RedrawElems but thats for dynamics .. i see a ReplaceInModel method in the EditElementhandle. but i dont think thats what i want.
looking at the TexthandlerBase i see a ReplaceTextPart. this is what im currently thinking is the way to go. but just want to check if thats correct. have not tested it yet, want to make sure im going in the right direction.
thanks
Hi John,
John Drsek said:to update an element there was always .redraw
Redraw in VBA and old COM/Interop API has no function and has been obsolete from V8 XM Edition (in V8i when you call redraw, nothing happens).
John Drsek said:but now i need to redraw the text element
No such need is necessary from V8i, when an element is added to a model, all views are updated automatically.
John Drsek said:and now i need to update that text element with the textblock
Ok, it's better formulation, you need to update, not redraw the element.
Without knowing your code, to understand the situation better: When you added the field to text and added the text to model, nothing happened? And when e.g. reopen model or update fields manually?
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Jan Ĺ legr said:Without knowing your code, to understand the situation better
..
DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); ElementId elemId = ElementID; //text element ElementHandle elem(elemId, pActiveModel); //text element if (!elem.IsValid()) { return false; } TextBlockPtr pTextBlock = TextHandlerBase::GetFirstTextPartValue(elem); // "DgnElementSchema" and "ArcElement" are found from ...\MicroStation\ECSchemas\Dgn\DgnElementSchema.01.00.ecschema.xml DgnFileP pDgnFile = ISessionMgr::GetActiveDgnFile(); SchemaInfo schemaInfo(ECN::SchemaKey(L"DgnElementSchema", 1, 0), *pDgnFile); DgnECManagerR ecMan = DgnECManager::GetManager(); ECN::ECSchemaPtr pSchema = ecMan.LocateSchemaInDgnFile(schemaInfo, ECN::SchemaMatchType::SCHEMAMATCHTYPE_LatestCompatible); if (pSchema == NULL) return NULL; ECN::ECClassCR ecClass = *pSchema->GetClassCP(L"ArcElement"); ElementId elem2Id; elem2Id = 3597; // Arc element used to link to in field ElementHandle elem2(elem2Id, pActiveModel); if (!elem2.IsValid()) return NULL; DgnElementECInstancePtr pElemInst = ecMan.FindInstanceOnElement(elem2, ecClass); TextFieldPtr pField = TextField::CreateForElement(*pElemInst, L"Length", nullptr, *pActiveModel); if (pField != NULL) pTextBlock->AppendField(*pField); //add field to text block EditElementHandle eeh(elemId, pActiveModel); //need to update text element with updated textblock
thinking I need to use TextHandlerBase::ReplaceTextPart ???
well..after a lot of searching and trail and error..I am closer...
so im using iTextEdit to change the text but how do I get that to update in the text element in the model.
when I use AddToModel() it creates a new text element and that element has the changes made to the text via code (adding a field).so that part is working .
So whats the correct way to apply this change to the text element? I can not simply delete the old text element since that element is being using to link other things and deleting it would break those links.
here is my code...
DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); ElementId elemId = ElementID; //text element ElementHandle elem(elemId, pActiveModel); //text element if (!elem.IsValid()) { return false; } TextBlockPtr pTextBlock = TextHandlerBase::GetFirstTextPartValue(elem); // "DgnElementSchema" and "ArcElement" are found from ...\MicroStation\ECSchemas\Dgn\DgnElementSchema.01.00.ecschema.xml DgnFileP pDgnFile = ISessionMgr::GetActiveDgnFile(); SchemaInfo schemaInfo(ECN::SchemaKey(L"DgnElementSchema", 1, 0), *pDgnFile); DgnECManagerR ecMan = DgnECManager::GetManager(); ECN::ECSchemaPtr pSchema = ecMan.LocateSchemaInDgnFile(schemaInfo, ECN::SchemaMatchType::SCHEMAMATCHTYPE_LatestCompatible); if (pSchema == NULL) return NULL; ECN::ECClassCR ecClass = *pSchema->GetClassCP(L"ArcElement"); ElementId elem2Id; elem2Id = 3597; // Arc element used to link to in field ElementHandle elem2(elem2Id, pActiveModel); if (!elem2.IsValid()) return NULL; DgnElementECInstancePtr pElemInst = ecMan.FindInstanceOnElement(elem2, ecClass); TextFieldPtr pField = TextField::CreateForElement(*pElemInst, L"Length", nullptr, *pActiveModel); if (pField != NULL) pTextBlock->AppendField(*pField); //add field to text block EditElementHandle eeh(elemId, pActiveModel); //need to update text element with updated textblock ITextEditP et = eeh.GetITextEdit(); T_ITextPartIdPtrVector partIds; et->GetTextPartIds(eeh, *ITextQueryOptions::CreateDefault(), partIds); et->ReplaceTextPart(eeh, *partIds[0], *pTextBlock); //apply this change somehow to the model without creating a new element //eeh.AddToModel(); //this creates a new element, need to update existing element
I feel like im soo close..please help!! thanks
Answer Verified By: John Drsek
To write the modified element back to the file, use EditElementHandle::ReplaceInModel().
ahh..thanks
eeh.ReplaceInModel(elem.GetElementRef());