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

ACAPI_Element_GetDefaults

Anonymous
Not applicable
Dear developers!

I have a simple addon which places library elements with different parameters. And i have a problem with getDefault parameters for the library items. I clear up the element and memo. Initialize element and then run Element_GetDefaults with these params. Then suddenly my element.object.libInd get something else and got a fully wrong memo as well. Where should i set my library element, to get the correct memo ? i have the correct toolboxitem, libraryIndex as well, which is used during initialization. For some item i also have the exact API_LibPart libPart if its needed.

                //clear up the params.
		BNZeroMemory(&element, sizeof(API_Element));
		BNZeroMemory(&memo, sizeof(API_ElementMemo));

		//initialize element.header
		element.header.typeID = toolboxItem.typeID; //ElementTypeID
		element.header.variationID = toolboxItem.variationID; //VariationTypeID

                //initialize element.object
		element.object.libInd = libInd; //library index
		WriteReport("element.object.libInd", element.object.libInd);

		WriteReport("variationId", toolboxItem.variationID);

		//Get memo Defaults 
		err = ACAPI_Element_GetDefaults(&element, &memo);
		//element.object.libInd = libInd;
		WriteReport("element.object.libInd", element.object.libInd);
		WriteReport("variationId", toolboxItem.variationID);
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Anonymous
Not applicable
Okay, thank you.

So you say that the correct method to place a library part is that.

-get the library part, index, toolbox, for example libPartSearch;
-ACAPI_Element_GetDefaults(&element, &memo);
- ACAPI_LibPart_GetParams(libInd, &a, &b, &parCount, &addPars); //get libpart Params which i already got, to pair the index of the params with names.
- memo.params=addPars; // update memo params with the defaults
-ACAPI_Element_Create(&element, &memo); //place the element
- dispose memo and addPars
- modify few of the params, with APIAny_OpenParametersID,APIAny_GetActParametersID,APIAny_ChangeAParameterID,APIAny_CloseParametersID,ACAPI_Element_Change

Do you know something about mep elements? which parameters should be changed to get the gs_connections working? Because i've modified (ConWidth_1,ConWidth_2,MEP_StraightLength,RotationAroundWAxis,RotationAroundZAxis,MEP_InsShow), and the connections not working, should i update manually the gs_connections array?

View solution in original post

5 REPLIES 5
Ralph Wessel
Mentor
The function ACAPI_Element_GetDefaults will really only look at the tool type and variation and extract the settings from the relevant tool. It won't take any notice of other data you inject, e.g. element.object.libInd.

I think you probably want to retrieve the parameters of the target object with ACAPI_LibPart_GetParams. This will also retrieve other relevant pieces of data for the object settings, e.g. bounding size.
Ralph Wessel BArch
Active Thread Ltd
Solution
Anonymous
Not applicable
Okay, thank you.

So you say that the correct method to place a library part is that.

-get the library part, index, toolbox, for example libPartSearch;
-ACAPI_Element_GetDefaults(&element, &memo);
- ACAPI_LibPart_GetParams(libInd, &a, &b, &parCount, &addPars); //get libpart Params which i already got, to pair the index of the params with names.
- memo.params=addPars; // update memo params with the defaults
-ACAPI_Element_Create(&element, &memo); //place the element
- dispose memo and addPars
- modify few of the params, with APIAny_OpenParametersID,APIAny_GetActParametersID,APIAny_ChangeAParameterID,APIAny_CloseParametersID,ACAPI_Element_Change

Do you know something about mep elements? which parameters should be changed to get the gs_connections working? Because i've modified (ConWidth_1,ConWidth_2,MEP_StraightLength,RotationAroundWAxis,RotationAroundZAxis,MEP_InsShow), and the connections not working, should i update manually the gs_connections array?
Ralph Wessel
Mentor
Yes, that's essentially correct.

Sorry, I don't have in-depth details about MEP object parameters.
Ralph Wessel BArch
Active Thread Ltd
Anonymous
Not applicable
Dear Ralph!

Sorry for the late reply, but i didn't have tim to test it in depth. but for now, i'm not able to place elements that way... I've got this error during element create. It looks good recognised my librarypart, which is valid and placebale. i couldn't find a clue where should i "register" ancestor, or why is it happening.

APICreate_SL :: APIERR_BADPARS :: library part's ancestor is not registered ({F938E33A-329D-4A36-BE3E-85E126820996}-{8A51B735-58FB-4ECF-98B7-CCFDB21F2453})
APICreate_SL :: APIERR_BADPARS :: library part info (1400, "fénycsöves lámpa 22")
APICreate_SL :: APIERR_BADPARS :: library part is valid and placeable
I've got these error during placing straight pipe, pipeBend and as you can see "fluorescent lamp" as well. Several other elements like Sprinkler,Dry Sprinkler and many self developed objects are placeable.
Anonymous
Not applicable
Ok this was may bad... Because someway my typeID was wrong. I set it manually API_LampID in this case and it worked, so i have to revisit how i got wrong toolboxitem.. for now it looks like i fixed it...

PS i found my mistake i tried to get toolboxitem before libpart search with only name of the part... I know it is not recommended to get parts by name but i can live with that.. Maybe later i'll change it to guid.