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

Compile and create my own API in C++

Anonymous
Not applicable
Hi,

i'm Alex, from Spain. I need help about how to program API's for archiCAD, specifically how to compile C++ programs alredy finished with Qt GUI in Visual Studio and transform this project in an archiCAD API. I guess is something difficult but probably is not impossible. Please if somebody can help me or suggest me something different, please just contact with me here.

Thank you!
20 REPLIES 20
Anonymous
Not applicable
Hi again,

i am "playing" with the GUI and i've found a problem. I have created a Modal dialog with 4 edit text and two buttons. But, i dont know when i try to change the size(208px) in the GRC file, it does not change in the API and i do not know why! Here, the code regarding to the GRC.

'GDLG' 32590 Modal 0 0 306 208 "Caracteristicas del Captador" {
Button 50 148 70 20 LargePlain "Aceptar"
Button 200 148 70 20 LargePlain "Cancelar"
LeftText 20 25 80 16 LargePlain "Caract. 1:"
TextEdit 105 20 100 20 LargePlain 50
LeftText 20 55 80 16 LargePlain "Caract. 2:"
TextEdit 105 50 100 20 LargePlain 50
LeftText 20 85 80 16 LargePlain "Caract. 3:"
TextEdit 105 80 100 20 LargePlain 50
LeftText 20 115 80 16 LargePlain "Caract. 4:"
TextEdit 105 110 100 20 LargePlain 50
}


'DLGH' 32590 DLG_32590_Dialogo_prueba {
1 "" Button_0
2 "" Button_1
3 "" LeftText_0
4 "" TextEdit_0
5 "" LeftText_1
6 "" TextEdit_1
7 "" LeftText_2
8 "" TextEdit_2
9 "" LeftText_3
10 "" TextEdit_3
}

Could it be something related with the handler? Even i don't think so...Thanks!
Ralph Wessel
Mentor
frankito5 wrote:
i am "playing" with the GUI and i've found a problem. I have created a Modal dialog with 4 edit text and two buttons. But, i dont know when i try to change the size(208px) in the GRC file, it does not change in the API and i do not know why!
ArchiCAD automatically stores the previous size and position of dialogs, and retrieves them the next time the dialog is displayed. To override this, you can obtain and apply the correct dialog size during the initialisation phase of the dialog. Refer to DGGetDialogSize for the means to get the correct dialog size.
Ralph Wessel BArch
Active Thread Ltd
Anonymous
Not applicable
1. Where i have to include this call function?
2. Should i have to modify the size from the GRC file?
3. Is this call correct?

void DGGetDialogSize (short dialId,short rectType,short* hSize,short* vSize);

DGGetDialogSize (Dialogo_prueba_GDLGID, DG_CLIENT, (short*)306, (short*)408);

where Dialogo_prueba_GDLGID is 32590, as the resId Modal dialog.
Ralph Wessel
Mentor
frankito5 wrote:
1. Where i have to include this call function?
You could add it to the dialog callback, when it is called for the dialog initialisation (DG_MSG_INIT).
frankito5 wrote:
2. Should i have to modify the size from the GRC file?
DGGetDialogSize can retrieve the size specified in the GRC file (with DG_ORIGFRAME).
frankito5 wrote:
3. Is this call correct?
void DGGetDialogSize (short dialId,short rectType,short* hSize,short* vSize);
DGGetDialogSize (Dialogo_prueba_GDLGID, DG_CLIENT, (short*)306, (short*)408);
That's the right call, but you shouldn't cast an integer value as a pointer. You want to retrieve the size of the dialog, so you should pass the addresses of integer variables to the function, e.g.:
short dialogWide = 0;
short dialogDeep = 0;
DGGetDialogSize (Dialogo_prueba_GDLGID, DG_ORIGFRAME, &dialogWide, &dialogDeep);
Then set the dialog size with those values using DGSetDialogSize.
Ralph Wessel BArch
Active Thread Ltd
Anonymous
Not applicable
Unfortunately it does not work. I have alredy included it in the DGCALLBACK, inicializating 'ancho' and 'alto' inside and it is supossed it has to achieve the value of wide and hight of the GRC.

static void CaractCaptador(void)
{
GSResModule filNum;
bool isOK;

// Get the dialog from our resource file
filNum = ACAPI_UseOwnResModule ();
isOK=(DGModalDialog(CaractCapt_GDLGID,CaractCaptador_Handler, 0) == DG_OK);
ACAPI_ResetResModule (filNum);

return;
}

static short DGCALLBACK CaractCaptador_Handler (short message, short dialogID, short item, DGUserData /*userData*/, DGMessageData){

// Declaramos las variables que van a recibir el valor del GRC
short ancho = 0;
short alto = 0;

switch (message) {
case DG_MSG_INIT:
API_UCCallbackType ucb;
// initialize user controls
BNZeroMemory (&ucb, sizeof (ucb));
DGGetDialogSize (CaractCapt_GDLGID, DG_ORIGFRAME, &ancho, &alto);
ucb.dialogID = dialogID;
ucb.type = APIUserControlType_WallProfile;
ucb.itemID = WallProfileItm;
ACAPI_Interface (APIIo_SetUserControlCallbackID, &ucb, NULL);
ucb.type = APIUserControlType_BeamProfile;
ucb.itemID = BeamProfileItm;
ACAPI_Interface (APIIo_SetUserControlCallbackID, &ucb, NULL);
ucb.type = APIUserControlType_ColumnProfile;
ucb.itemID = ColumnProfileItm;
ACAPI_Interface (APIIo_SetUserControlCallbackID, &ucb, NULL);
ucb.type = APIUserControlType_AllProfile;
ucb.itemID = AllProfileItm;
ACAPI_Interface (APIIo_SetUserControlCallbackID, &ucb, NULL);
break;

case DG_MSG_CLICK:
result = item;
break;

case DG_MSG_CLOSE:
result = item;
break;
}

return (result);
}

CaractCapt_GDLGID is 32590, and u can see the GRC code regarding to this CALLBACK:

'GDLG' 32590 Modal 0 0 800 800 "Caracteristicas del Captador" {
Button 50 148 70 20 LargePlain "Aceptar"
Button 200 148 70 20 LargePlain "Cancelar"
LeftText 20 25 80 16 LargePlain "Caract. 1:"
TextEdit 105 20 100 20 LargePlain 50
LeftText 20 55 80 16 LargePlain "Caract. 2:"
TextEdit 105 50 100 20 LargePlain 50
LeftText 20 85 80 16 LargePlain "Caract. 3:"
TextEdit 105 80 100 20 LargePlain 50
LeftText 20 115 80 16 LargePlain "Caract. 4:"
TextEdit 105 110 100 20 LargePlain 50
}


'DLGH' 32590 DLG_32590_CaractEner {
1 "" Button_0
2 "" Button_1
3 "" LeftText_0
4 "" TextEdit_0
5 "" LeftText_1
6 "" TextEdit_1
7 "" LeftText_2
8 "" TextEdit_2
9 "" LeftText_3
10 "" TextEdit_3
}


Now i have the same size (no 800 x 800 as i want) i refered in last post. Could you tell me if i have made any error or if i have forgotten something? Thank you again.
Ralph Wessel
Mentor
frankito5 wrote:
Could you tell me if i have made any error or if i have forgotten something?
I can't see where you use DGSetDialogSize to set the dialog to the size obtained with DGGetDialogSize.
Ralph Wessel BArch
Active Thread Ltd
Anonymous
Not applicable
Ok, now i know how it works, getting and the setting the size, perfect!

1. Next task is fill a list box without set each field one by one and repeat DGListSetItemText" X times. I want to read from a .TXT file 52 fields. The problem is when i try to open the file, because it does not open. Where i have to include this .TXT file? Or what i have to do?


static short DGCALLBACK TreeViewDlgCallBack (short message, short dialId, short itemId,
DGUserData /*userData*/, DGMessageData /*msgData*/)
{
#define FOLDER_CONTENT 3
#define CHANGE_ICON 4
#define TREEVIEW 5

Int32 treeItem;

ifstream prov("provincias.txt", ifstream::in);

if(!prov){
cout << "Error de apertura del fichero." << endl;
return -1;
}


short indprov = 1;
char * cadprov = new char [15];

static TreeViewData tvd = { 0 };

switch (message) {
case DG_MSG_INIT:
LoadTreeViewDialogIcons (&tvd);
DGListSetHeaderItemText(SelecProv_GDLGID,3,1,"Provincia");
for(int i=0;i<52;i++)
//DGListInsertItem (short dialId,short item,short listItem);
DGListInsertItem(SelecProv_GDLGID,3,DG_LIST_BOTTOM);
//DGListSetItemText (short dialId, short item, short listItem, const char* text)
DGListSetItemText(SelecProv_GDLGID,3,indprov,"Alicante");
//DGListSetItemText(SelecProv_GDLGID,3,2,"Castellón");
//DGListSetItemText(SelecProv_GDLGID,3,3,"Valencia");
while(prov >> cadprov)
DGListSetItemText(SelecProv_GDLGID,3,indprov++,cadprov);

break;


2. Another point, i would like to see errors by the output screen, but i cant generate this output messages because there is not .EXE file. How to debug the API in VS2005 to check errors? And

3. There is one way to update the archiCAD without open&close each time i want to see the changes in the API?

Thank you,

Alex
Ralph Wessel
Mentor
frankito5 wrote:
1. I want to read from a .TXT file 52 fields. The problem is when i try to open the file, because it does not open. Where i have to include this .TXT file?
I get the impression you haven't done much C/C++ development to date. If you write the following:
ifstream prov("provincias.txt", ifstream::in);
...you haven't stated where the file should be found, so it will assume a default directory for your file, probably C:\provincias.txt. I suggest reading the Input/Output section of the API documentation. Also, look up the functionality provided by APIEnv_GetSpecFolderID to obtain the location of key directories.
frankito5 wrote:
2. How to debug the API in VS2005 to check errors?
Set the ArchiCAD application as the target for debugging.
frankito5 wrote:
3. There is one way to update the archiCAD without open&close each time i want to see the changes in the API?
Unfortunately not.
Ralph Wessel BArch
Active Thread Ltd
Anonymous
Not applicable
Set the ArchiCAD application as the target for debugging.
How to do it?
Ralph Wessel
Mentor
frankito5 wrote:
Set the ArchiCAD application as the target for debugging.
How to do it?
In the Debugging section of the project properties (see attached image).
Ralph Wessel BArch
Active Thread Ltd