Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

ACAPI_Automate - OpenID

Anonymous
Not applicable
I started to play around with ACAPI_Automate. But I stuck I very beginning...
I have two problems:
Problem 1: When I pass GS::UniString as a parameter in the constructor the part of extension is eaten.
Problem 2: When I try to Open I got an error: 2130312312 APIERR_REFUSEDCMD

Example code with commented problems based on DoOpen form Automation example:
DoOpen() {
	//Based on DO_OPEN form API

		API_FileOpenPars	fop;
		GSErrCode			err;
		BNZeroMemory(&fop, sizeof(API_FileOpenPars));

		fop.fileTypeID = APIFType_PlanFile;
		fop.useStoredLib = true;

		IO::Location appFolderLoc; 
		GSErrCode errorCode = IO::fileSystem.GetSpecialLocation(IO::FileSystem::Desktop, &appFolderLoc);

		GS::UniString myPath = GS::UniString("empty");
		
		IO::Name myName = IO::Name(Name);  // Name pased in Constructor from GS::UniString
		myName.AppendExtension("pln");//Problem 1: Need to apend because passed name is up to dot for example  test.pln -> test 

		fop.file = new IO::Location(appFolderLoc, myName);

		err = ACAPI_Automate(APIDo_OpenID, &fop);  // Problem 2: returns error :APIERR_REFUSEDCMD	-2130312312	81060388	The passed identifier is not subject to the operation.

		if (err != NoError)
			ACAPI_WriteReport("Error in APIDo_OpenID:", true);


		delete fop.file;

	return;
	}		// Do_Open
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
APIERR_REFUSEDCMD error code can be returned because of the following reasons in case of APIDo_OpenID:
  • You use this code inside an undoable scope (ACAPI_CallUndoableCommand).
  • You executed this code inside a notification handler function (ACAPI_Notify_CatchProjectEvent).
Maybe there could be more reasons, but I hope you are facing one of these If not, then I will keep thinking...

View solution in original post

6 REPLIES 6
Anonymous
Not applicable
I have managed to fix the path problem - wrongly passed attributes.

However, the error is still the same. The weird thing is that when I use example form Automate_Functions it's working on demo mode. However, when I use an identical approach in my registered addon it dosent work and the error appears anyway.
Solution
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
APIERR_REFUSEDCMD error code can be returned because of the following reasons in case of APIDo_OpenID:
  • You use this code inside an undoable scope (ACAPI_CallUndoableCommand).
  • You executed this code inside a notification handler function (ACAPI_Notify_CatchProjectEvent).
Maybe there could be more reasons, but I hope you are facing one of these If not, then I will keep thinking...
Anonymous
Not applicable
Tibor wrote:
You use this code inside an undoable scope (ACAPI_CallUndoableCommand).
This was my case. I didn't realize that I was using menu registration form Properties example and there are actually called as undoable commands. Thanks a lot now it's 'working.
Anonymous
Not applicable
I was wondering recently is there any way in AC 22 to suspend or click OK on UI elements popping up during file opening.
I would like to open the file without being disturbed a least with the Library Manager, Drawing manager, Midding Addon Info and Hotlink Manager - as far as I observed those menus break opening procedure.

I found useStoredLib and libGiven properties in API_​FileOpenPars. But it feels like it doesn't mean to control UI only opening procedure itself.
If there is no way of modyfing the opening procedure. I was thinking about a method that clicks OK or ESC on each appearing UI element. Is it possible with DG library?

I'm aware that things will change in AC23 on startup but I'm looking for a working solution for today.
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
kzaremba wrote:
I was thinking about a method that clicks OK or ESC on each appearing UI element. Is it possible with DG library?
Please check the DGEnableAutoClose/DGDisableAutoClose functions. You can find them in the DG.h header file.
If you call DGEnableAutoClose then each dialog will be automatically closed by ARCHICAD.
Anonymous
Not applicable
Tibor wrote:
If you call DGEnableAutoClose then each dialog will be automatically closed by ARCHICAD.
Thanks a lot for suggestion Tibor. It works perfectly and its only one line of code to make it work.. Cool