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

[SOLVED] Parameters

Anonymous
Not applicable
Could i get parameters using ACAPI_Element_Select.
F.e. get parameters from selected object and use these parameters for other object. I need hight, width, lenght, and position, probably sym_pos, or is there other way to get position?

I hope this makes sense.
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Ralph Wessel
Mentor
New wrote:
As i understand getParams.params is a list of all the rest parameters how do i choose one of them ?
If you look at the structure of API_GetParamsType, you will see the the params member declared like this:
	API_AddParType					**params;
This means that params is a handle, or a pointer to a pointer. You could get the first parameter by simply dereferencing the handle twice, e.g.
API_AddParType firstParameter = **getParams.params;
But what you really want to do is access all the values. The easiest approach is to dereference the handle once and then treat the resulting pointer as an array, so the first parameter could also be expressed like this:
API_AddParType firstParameter = (*getParams.params)[0];
The nth parameter could be accessed like this:
API_AddParType nthParameter = (*getParams.params);
To determine how many parameters the handle contains, you want to divide the total amount of memory allocated to the handle by the size of a single parameter:
GSSize parameterCount = BMGetHandleSize(getParams.params) / sizeof(API_AddParType);
Ralph Wessel BArch

View solution in original post

13 REPLIES 13
Ralph Wessel
Mentor
New wrote:
Could i get parameters using ACAPI_Element_Select.
F.e. get parameters from selected object and use these parameters for other object. I need hight, width, lenght, and position, probably sym_pos, or is there other way to get position?
ACAPI_Element_Select gives you a list of indices to the selected elements. To retrieve the parameters from one of those indices, look at APIAny_OpenParametersID and APIAny_GetActParametersID. This will give you access to all the parameter including the A, B, and zzyzx, but that isn't necessarily the actual bounding size. It would be easier to use APIDb_CalcBoundsID for that purpose.

The parameters do not contain the object position. You need to retrieve the other element settings through ACAPI_Element_Get. For an ordinary object, e.g. not a door/window, the 2D position is API_ObjectType.pos
Ralph Wessel BArch
Anonymous
Not applicable
Thanks for help Ralph.

Will try to make it work.
Anonymous
Not applicable
Haven't figured out how to get rest of the parameters, did get a and b.

API_AddParType and call parameter index ? or i could call by parameter name ?
Anonymous
Not applicable
As i understand getParams.params is a list of all the rest parameters how do i choose one of them ?

I belive this would be right approach but not sure how to go further...
    BNZeroMemory (&getParams, sizeof (API_GetParamsType));  
         err = ACAPI_Goodies (APIAny_GetActParametersID, &getParams, NULL);  
         if (err == NoError)  
         {  
            BNZeroMemory (&element, sizeof (API_Element));  
            BNZeroMemory (&memo, sizeof (API_ElementMemo));  
            element.header.typeID = API_ObjectID;  
            element.header.index = selectedInd;  
	    ACAPI_ELEMENT_MASK_CLEAR (mask);  
            memo.params = getParams.params; 
Solution
Ralph Wessel
Mentor
New wrote:
As i understand getParams.params is a list of all the rest parameters how do i choose one of them ?
If you look at the structure of API_GetParamsType, you will see the the params member declared like this:
	API_AddParType					**params;
This means that params is a handle, or a pointer to a pointer. You could get the first parameter by simply dereferencing the handle twice, e.g.
API_AddParType firstParameter = **getParams.params;
But what you really want to do is access all the values. The easiest approach is to dereference the handle once and then treat the resulting pointer as an array, so the first parameter could also be expressed like this:
API_AddParType firstParameter = (*getParams.params)[0];
The nth parameter could be accessed like this:
API_AddParType nthParameter = (*getParams.params);
To determine how many parameters the handle contains, you want to divide the total amount of memory allocated to the handle by the size of a single parameter:
GSSize parameterCount = BMGetHandleSize(getParams.params) / sizeof(API_AddParType);
Ralph Wessel BArch
Anonymous
Not applicable
Big thanks Ralph!!!

I think i got it now, thanks.
Will get right on it
Anonymous
Not applicable
Ralph wrote:
GSSize parameterCount = BMGetHandleSize(getParams.params) / sizeof(API_AddParType);
I have tried this part and got error:
API_AddParType is not valid with GS::GSConstHandle

Why ?
Ralph Wessel
Mentor
kzaremba wrote:
Ralph wrote:
GSSize parameterCount = BMGetHandleSize(getParams.params) / sizeof(API_AddParType);
I have tried this part and got error:
API_AddParType is not valid with GS::GSConstHandle
The compiler only sees 2 different types that have no defined conversion. In this case we know they are actually the same thing, so the simplest solution (given that this part of the API is C) is to use a C-style cast:
GSSize parameterCount = BMGetHandleSize((GS::GSConstHandle) getParams.params) / sizeof(API_AddParType);
I wouldn't recommend that approach for C++, but the technique still exists for bridging to C in situations like this.
Ralph Wessel BArch
Anonymous
Not applicable
Ralph wrote:
C in situations
I see mysteries of C... Thanks a lot it's working!

Why it used to work without casting before ?