Choose your top Archicad wishes!

Read more
Archicad C++ API
About Archicad add-on development using the C++ API.

APIERR_REFUSEDCMD when delete story

Not applicable
		API_StoryInfo storyInfo;
		BNZeroMemory(&storyInfo, sizeof(API_StoryInfo));
		GSErrCode err = ACAPI_Environment(APIEnv_GetStorySettingsID, &storyInfo, nullptr);
		API_StoryType** storyType=;
		API_StoryType* temAdress = (*storyType);
		for (int i=storyInfo.firstStory;i<= storyInfo.lastStory; i++)
			API_StoryCmdType changeType;
			BNZeroMemory(&changeType, sizeof(API_StoryCmdType));
			changeType.action = APIStory_Delete;
			changeType.index = temAdress->index;
			changeType.dispOnSections = true;
			changeType.dontRebuild = true;
			changeType.elevation = temAdress->level;
			//changeType.uName = temAdress->uName;
			err= ACAPI_Environment(APIEnv_ChangeStorySettingsID, &changeType, nullptr);
I try to delete story by the code above ,but it didn‘t work , and the error code was "APIERR_REFUSEDCMD -2130312312 81060388 The passed identifier is not subject to the operation. ".I can not find why.
Viktor Kovacs
Probably it doesn't work because you try to run a command that modifies the database, and the command is not in a command scope. Try to do it like this:

ACAPI_CallUndoableCommand ("Delete Story", [&] () -> GSErrCode {
    // call APIEnv_ChangeStorySettingsID here
It's your choice if you create a separate undo step for all stories, or to do the whole modification in one undo step.

More information here (under the undo scope section):