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

Info of selected items

TomWaltz
Participant
A lot of the API examples show how to get/assign parameters of clicked elements.

Does anyone have any tips on getting the API_ElemTypeID typeID, and changing parameters on SELECTED elements?

I'm struggling with which myriad of "change/get/set" functions does what I want!
Tom Waltz
15 REPLIES 15
Anonymous
Not applicable
Use the ACAPI_Goodies function with APIAny_NeigIDToElemTypeID to convert a neig type to a element type.

Then you can then change parameters as you would in a notification handler
TomWaltz
Participant
Adam

Thanks!

does that apply to parameters inside door & window objects as well?
Tom Waltz
Anonymous
Not applicable
You can use the ACAPI_Goodies function with APIAny_NeigIDToElemTypeID to convert any neig type to an element type. Windows, doors, dimensions. See the docs.

To set the parameters do like the example in the docs under APIAny_OpenParametersID, but use ACAPI_Element_ChangeParameters instead of changeDefauts. You can use ACAPI_Element_ChangeParameters straight up without the goodie functions, but the parameter script in gdl won't run so don't.

This is to change parameters (like those in gdl). It is different to changing 'members' of an element, ie. everything you see under API_Element in the docs. To do this use ACAPI_Element_Change. This is things like door position in a wall.
TomWaltz
Participant
Thanks, Adam. I really appreciate your help so far.

It seems I was on the right path, but must have some other problem. I copied in that bit of code, compiled it, and while no errors are generated, nor can I make the parameter actually change.

I was experimenting with two different ideas: changing the "A" value of the object and changing the "width" and "height" of the window. Neither approach seemed to work. I actually want to change the "gs_detlevel_3D" parameter, but used these as test cases.

I added a ton of debugging "WriteReport" statements, and not one displays an error. All my message statements show the "successful" path was taken and no err statements were generated.

		API_ParamOwnerType 		paramOwner;
		API_ChangeParamType 		chgParam;
		API_GetParamsType 		getParams;
		API_Element 				element, mask;
		API_ElementMemo 			memo;
		GSErrCode 				err, err2;

		BNZeroMemory (&paramOwner, sizeof (API_ParamOwnerType)); 
		paramOwner.libInd = 0; 					// no library part
		paramOwner.typeID = API_WindowID;	 	// window element
		paramOwner.index = 0; 					// element default 
	

		BNZeroMemory (&getParams, sizeof (APIAny_GetActParametersID));

		err = ACAPI_Goodies (APIAny_OpenParametersID, &paramOwner, NULL);
		if (!err) {
			BNZeroMemory (&chgParam, sizeof (API_ChangeParamType));

			err = ACAPI_Goodies (APIAny_GetActParametersID, &getParams, NULL);
			if (!err) {
				chgParam.index = 0;
				// junk parameter for testing
				CHCopyC ("A", chgParam.name);
				chgParam.realValue = 2.1;
				// what I actually want to change
				//CHCopyC ("gs_detlevel_3D", chgParam.name);
				// chgParam.strValue = "Off";
				err2 = ACAPI_Goodies (APIAny_ChangeAParameterID, &chgParam, NULL);
				if (!err2){
					err = ACAPI_Goodies (APIAny_GetActParametersID, &getParams, NULL);
					if (!err){
						WriteReport_Err("APIAny_GetActParametersID successful: ", err);
					}else{
						WriteReport_Err("APIAny_GetActParametersID error: ", err);
					}
					WriteReport_Err("ACAPI_Goodies (APIAny_ChangeAParameterID) successful: ", err2);
				}else{
					WriteReport_Err("ACAPI_Goodies (APIAny_ChangeAParameterID) error: ", err2);
				}
			}else {
				WriteReport_Err("ACAPI_Goodies (APIAny_OpenParametersID) error: ", err);
			}
			ACAPI_Goodies (APIAny_CloseParametersID, NULL, NULL);
			WriteReport_Err("APIAny_OpenParametersID successful: ", err);
		}else {
			WriteReport_Err("APIAny_OpenParametersID error: ", err);
		}

		if (!err) { 			// If typeID = Window
			BNZeroMemory (&element, sizeof (API_Element));
			BNZeroMemory (&memo, sizeof (API_ElementMemo));
			element.header.typeID = API_WindowID;
			element.window.width = 1.2;
			element.window.height = 2.1;
			ACAPI_ELEMENT_MASK_CLEAR (mask);
			ACAPI_ELEMENT_MASK_SET (mask, API_WindowType, width);
			ACAPI_ELEMENT_MASK_SET (mask, API_WindowType, height);
			memo.params = getParams.params;
			err2 = ACAPI_Element_ChangeParameters (elemHead, elemCount, &element, &memo, &mask);
			if (!err2){
				WriteReport_Err("ACAPI_Element_ChangeParameters successful: ", err2);
			}else{ 
				WriteReport_Err("ACAPI_Element_ChangeParameters error: ", err2);
			}
			WriteReport_Err("ACAPI_Goodies (APIAny_ChangeAParameterID) successful: ", err);
		}else{
			WriteReport_Err("ACAPI_Goodies (APIAny_ChangeAParameterID) error:: ", err);
		}
Is there anything you (or anyone else) see that is wrong?

Thanks for any ideas!
Tom Waltz
TomWaltz
Participant
.... and the output in my Report window:
Demo layer is on
Existing layer is on
Window #14
Selected element is a Window
Element is set to existing
APIAny_GetActParametersID successful: : 0
ACAPI_Goodies (APIAny_ChangeAParameterID) successful: : 0
APIAny_OpenParametersID successful: : 0
ACAPI_Element_ChangeParameters successful: : 0
ACAPI_Goodies (APIAny_ChangeAParameterID) successful: : 0
Tom Waltz
Anonymous
Not applicable
has a quick look and you don't appear to be setting the element index anywhere. eg. chgParam.index, (*elemhead)[0].index

how does it know what element your changing?
you should try with a regular parameter as a and b are kindof special
Ralph Wessel
Mentor
TomWaltz wrote:
I was experimenting with two different ideas: changing the "A" value of the object and changing the "width" and "height" of the window. Neither approach seemed to work.

		API_ParamOwnerType 		paramOwner;
		BNZeroMemory (&paramOwner, sizeof (API_ParamOwnerType)); 
		paramOwner.libInd = 0; 					// no library part
		paramOwner.typeID = API_WindowID;	 	// window element
		paramOwner.index = 0; 					// element default 
Can you clarify what you are trying to do here? Your opening question suggests you are trying to modify a selected element, but this code would modify the default settings for placing a new Window element (you only specify the typeID and not the index of a specific element. Is that what you want? Take a look at the API documentation on the type API_ParamOwnerType for more information on this.
TomWaltz wrote:

		API_GetParamsType       getParams;
		BNZeroMemory (&getParams, sizeof(APIAny_GetActParametersID));
There is a type mismatch here - getParams is the type API_GetParamsType, but you zero it using the size of APIAny_GetActParametersID. You could also write:
BNZeroMemory (&getParams, sizeof(getParams));
Ralph Wessel BArch
TomWaltz
Participant
Can you clarify what you are trying to do here?
Ralph,

my intention is to change one of the parameters of the selected door or window.

The change is being done based on user information being entered into a custom panel on the settings menu.
Tom Waltz
Ralph Wessel
Mentor
TomWaltz wrote:
my intention is to change one of the parameters of the selected door or window.
In that case, you need to specify the index for each selected window to be changed:
paramOwner.index = <index of a selected window>;
Ralph Wessel BArch