[CONNECT C++] Meaning of Returned Status Code(s) from DgnECInstance::WriteChanges()

I'm attempting to modify a property value of an ItemTpe instance on an element. When I try to WriteChanges(), I get non-zero return result. I've gotten a return code of 3 and 7 at during various attempts. The function returns a StatusInt, but I can't seem to determine what those values mean.

ItemTypeLibraryPtr			l_itemTypeLib = ItemTypeLibrary::FindByName(L"MyItemLib", *ACTIVEMODEL->GetDgnFileP());
if (l_itemTypeLib.IsValid())
{
	wprintf(L"itemTypeLib.IsValid()\n");
	ItemTypeP			pItemType = l_itemTypeLib->GetItemTypeByName(L"MyItem");
	if (pItemType != nullptr)
	{
		CustomItemHost				itemHost = CustomItemHost(eeh);
		DgnECInstancePtr			pInstance = itemHost.ApplyCustomItem(*pItemType, true);
		if (pInstance.IsValid())
		{
			// modify the value of the Status property (19april2018 doesnt seem to work...)
			if (pInstance.IsValid())
			{
				wprintf(L"Changing Status value\n");
				ECValue					statusValue(L"Proposed");
				ECObjectsStatus		oStatus = pInstance->SetValue(L"Status", statusValue);	// case-sensitive
				if (oStatus == ECObjectsStatus::ECOBJECTS_STATUS_Success)
				{
					wprintf(L"ECObjectsStatus::ECOBJECTS_STATUS_Success\n");
					StatusInt	iStatus = pInstance->WriteChanges();	// <--- iStatus returned as 3 or 7
					wprintf(L"pInstance->WriteChanges(), iStatus=%d\n", iStatus );
				}
				else
					wprintf(L"ECObjectsStatus=%d\n", oStatus);
			}
			wprintf(L"*********** Instance attached\n");
			eeh.ReplaceInModel(eeh.GetElementRef());
		}
		else
			wprintf(L"Instance NOT attached\n");
	}
	else
		wprintf(L"pItemType == nullptr\n");
}
else
{
	wprintf(L"NOT itemTypeLib.IsValid()\n");
}

Bruce

Parents
  • StatusInt as a return type is not very helpful unfortunately. Usually you can expect SUCCESS or ERROR. If you get something else, it's probably a DgnECInstanceStatus (but you cannot rely on that to be true 100% of the time).

    Specifically:

    3 = invalid element ref: Your eeh does not have an element ref (presumably because it's a non-persistent element, or has been modified).

    7 = no instance found: Trying to replace an ECInstance which does not exist.

    Probably relevant to ask from where you obtained your EditElementHandle...

  • Probably relevant to ask from where you obtained your EditElementHandle...

    It's the EditElementHandleR passed into _OnElementModify() in a DgnElementSetTool...

    The "no instance found" I can sort-of understand, I'm attempting to add an ItemType to a user-picked line element. The posted code is essentially all the code inside _OnElementModify().

    The ItemType DOES get attached, even with the non-zero return code, but the property value is just not updated. This is essentially the process used in the "ReportsExampleAttachItemsTypes" example..

  • DgnElementSetTool expects your _OnElementModify() implementation to modify the EditElementHandle in a non-persistent manner. It will write your changes for you.

    You are:

    1. Writing an ECInstance directly to the element (your CustomItemHost specifies the Item should *not* be scheduled - but it should be)

    2. Rewriting that ECInstance after SetValue() via WriteChanges() (you probably want ScheduleChanges())

    3. Directly invoking ReplaceInModel() which again rewrites the element (and is superfluous because WriteChanges() already rewrote the element and you made no further changes to it).

  • your CustomItemHost specifies the Item should *not* be scheduled - but it should be

    CustomItemHost itemHost = CustomItemHost(eeh);

    Isn't the default for the second parameter (scheduleItem) "true" ?

    I have (since the posting of the code) removed the ReplaceInModel() call and see no difference. I have removed the WriteChanges() function call as well. I have tried using both "true" and "false" when creating the CustomItemHost() and still see the ItemType attached to the element, but the property value is not updated..

    you probably want ScheduleChanges()

    As in DgnECInstanceEnabler::ScheduleInstanceOnElement() ? If so, how does one know to use DgnECManger/DgnECInstanceEnabler verses ItemTypeLibrary/ItemType/CustomItemHost ?

Reply
  • your CustomItemHost specifies the Item should *not* be scheduled - but it should be

    CustomItemHost itemHost = CustomItemHost(eeh);

    Isn't the default for the second parameter (scheduleItem) "true" ?

    I have (since the posting of the code) removed the ReplaceInModel() call and see no difference. I have removed the WriteChanges() function call as well. I have tried using both "true" and "false" when creating the CustomItemHost() and still see the ItemType attached to the element, but the property value is not updated..

    you probably want ScheduleChanges()

    As in DgnECInstanceEnabler::ScheduleInstanceOnElement() ? If so, how does one know to use DgnECManger/DgnECInstanceEnabler verses ItemTypeLibrary/ItemType/CustomItemHost ?

Children
No Data