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

ACAPI_Element_ChangeDefaults function question

TomWaltz
Participant
I am attempting to change the layer used for Polylines, based on the color that is selected. (Long story).

The idea is that if the user selects color 164, another function will be called to scan for what layer that should be. This part seems to work, since it does select the proper layer.

My problem is that the default layer is changed only after another tool is selected, then the Polyline tool is selected again.

Any ideas?
void 	KA_CatchColorChange()
	{
		API_Element    			element, mask;
		GSErrCode       		err;
		BNZeroMemory (&element, sizeof (API_Element));

		element.header.typeID = API_PolyLineID;
		
		err = ACAPI_Element_GetDefaults (&element, 0);
		if (element.polyLine.linePen == 164)
			{
				ACAPI_ELEMENT_MASK_CLEAR (mask); 
				ACAPI_ELEMENT_MASK_SET (mask, API_Elem_Head, layer);
				
				KA_GetLayer(annoType, element);
				
				ACAPI_Element_ChangeDefaults (&element, NULL, &mask);
			}
		return;
	}

The prototype for KA_GetLayer is
void KA_GetLayer(char annoType, API_Element &element)
Tom Waltz
3 REPLIES 3
TomWaltz
Participant
Addendum:
This works fine if the chage is made in the Polyline Default Settings menu.

However, most of our users make this change in the Info Box, so that is how I tested this function. Making the change in the Info Box causes the problem I mentioned.
Tom Waltz
Oleg
Expert
Do you want to correct default of an element in a CatchChangeDefaults notify handler of this element type.
It was need for me too. I asked about it year ago or so. May be something has changed for 9, but unfortunately the answer was like this:

" it's forbidden to change the default of the element from the notification comes during "CatchChangeDefaults" notify (there is a
safety mechanism against endless loop in the infobox). But you can change the other defaults. "
TomWaltz
Participant
My goal was to use a change of defaults, namely pen color, to trigger other changes in the defaults. For example, if user sets pen to 164, change current layer to "text" and turn on starting arrowhead.

This seems to work in the settings menus. Only if the change is made in the Info Box is there a problem.

I wondered about a feedback loop, so I created used one of the routines from the API example set to send a text string to the report window every time the defaults are changed, and whether or not the exact function was called. Archicad did not seem to consider a change made by my Add-on to be a change of defaults.
Tom Waltz