[CONNECT C++] Loop TextFields in existing text element and then get field properties and set field Properties?

Could anyone offer any help with how to do this? I see a TextFieldDictionary in the API. but not really sure how to implement this.

what im trying to do is for a given text element get all the text fields that are linked to a property of a item type. as well as change what property that field is linked to.

I used the code from Yongan.Fu in post https://communities.bentley.com/communities/other_communities/chinafirst/f/microstation-projectwise/180135/msce-c-textblock to create a text field but that's pretty much the only example of textfields I could find.

JD

Parents
  • The way the the API treats text in memory in the CONNECT MicroStationAPI is abstract.  It has nothing to do with DGN elements (Text and Text Nodes) and discards completely the V8 way of handling text elements directly with the mdlText_api.

    The TextBlock is the foundation of CONNECT MicroStationAPI  text handling.  It is well-documented in MicroStationAPI  help.  There are examples but, perversely, they are in the deprecated mdlText_api documentation...

    mdlText_api deprecated

     
    Regards, Jon Summers
    LA Solutions

  • okay so im still a little lost...

    so I get my textBlock from my element like this...

    ElementHandle eh(elemId, pActiveModel);
    TextBlockPtr textBlock = TextHandlerBase::GetFirstTextPartValue(eh);

    then I see this getfield method that takes a caretCR….

    TextFieldPtr firstfield = textBlock->CreateStartCaret->GetField();

    so I know that isn't right..but confused as to how I would iterate the textblock to get all the textfields...

    any guidance? not really sure what start caret is meaning.

  • any guidance?

    From the questions posted here in the last year or two I think there are several of us who would welcome more hints about C++ text processing from Bentley Systems.

    not really sure what start caret is meaning

    Interpret it as a pointer into some component of a TextBlock.  In C++ terms, an iterator.  It's volatile and may become invalid as you manipulate a TextBlock.

    Behind the scenes, I believe that a TextBlock is an API that manages an XML document.  The TextBlock API is manipulating the XML elements of that document.  The XML may be simple — just one word — or complex, containing multiple paragraphs, styles and text fields.  When you write the TextBlock to a DGN model it converts to the appropriate text element or text node element.

     
    Regards, Jon Summers
    LA Solutions

  • 1. Obtain the starting Caret using CreateStartCaret.

    2. Use GetCurrentField to get TextField at current Caret position, if any.

    3. Use Caret::MoveToNextField() to move to next TextField and go to step 2. It returns ERROR when it has reached the end.

  • Thanks Paul,

    so i can loop the textfields but after i get the text field i dont see any methods available to see the field properties. like is this field linked to a element, model... what im really after is to tell if the field is linked to a itemtype and what property its linked to. So like the access string. all i see is getdisplayvalue, formatvalue,GetFormatter, and then all the create methods. 

    any help how i could get this?

    anyways here is the code i have so far..not complete yet, im just getting the displayvalue of the field right now.

        DgnModelP       pActiveModel = ISessionMgr::GetActiveDgnModelP();
    	
    	ElementId  elemId = ElementID;  // An arc element id
    	ElementHandle elem(elemId, pActiveModel);
    	if (!elem.IsValid())
    	{
    		return false;
    	}
    
    	TextBlockPtr pTextBlock = TextHandlerBase::GetFirstTextPartValue(elem);
    	CaretPtr curCaret = pTextBlock->CreateStartCaret();
    	TextFieldPtr curField = curCaret->GetCurrentField();
    	WString disValue;
    	if (curField != NULL) 
    	{
    		curField->GetDisplayValue(disValue);
    	}
    	bool stop = false;
    	while (stop == false)
    	{
    		BentleyStatus result;
    		result = curCaret->MoveToNextField();
    		if (result == BentleyStatus::ERROR) 
    		{
    			stop = true;
    		}
    		if (stop == false) 
    		{
    			curField = curCaret->GetCurrentField();
    			if (curField != NULL) 
    			{
    				curField->GetDisplayValue(disValue);
    			}
    		}
    	}

  • Hi John,

    any help how i could get this?

    It seems you have not missed anything and there is no direct access to "field linking" available.

    I have not tested it, but my assumption is that the link between text field and data source is stored at the text field object itself when e.g. TextField::CreateForElement method is used. The link representation is probably some EC relationshop class, but how to receive it is not clear.

    Accordingly to general concepts used by CE API I would expect something like to obtain TextFieldHandler (exists as type definition in SDK, but it seems nowhere else), used something like FindECClassesOnElement or FindRelationshipEntriesOnElement to receive the relationship definition and to analyze it.

    But maybe I am wrong completely ;-)

    , would you be so kind to provide some insight into this area? Whereas it was discussed and is quite clear how to create TextField, how to obtain all information from existing object seems to be not straightforward.

    Regards,

      Jan

  • I don't see any methods available to see the field properties

    From MicroStationAPI help...

    void SetFieldCreationContext  ( bool   )  
    
    This method is deprecated.
    

    When I see comments like that in the documentation it suggests to me that the TextField public API is a work-in-progress.

     
    Regards, Jon Summers
    LA Solutions

  • The TextField API is complete, it's just mostly unpublished. I don't know the official process for requesting an API to become published. Perhaps summoning is sufficient.

  • its been some time. just wondering if any progress has been made here.

    the most i can do it loop fields and get the display value. i would like to be able to get more info about the field like what the field is linking to.

    also not as important but dont see a way to figure out the location of the field in the textblock. my app is displaying the text and i want to highlight the text that represents the given field in my app. Assuming this can be done from within the TextFieldApi 

  • just wondering if any progress has been made

    suggested requesting to brew whatever potion is needed to render the currently private text field APIs public.

     
    Regards, Jon Summers
    LA Solutions

  • Hi  and ,

    I received an update that a developer in this area will provide a review and update on this as soon as possible that I will pass along once available.

    Thank you,
    Bob



Reply Children