cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

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

How to use ChangeDefaultsExt to MyDoor Object

Anonymous
Not applicable
I would like to ChangeDefaults Door and Window(Change Object).
Ex.
- I have 2 door object [MyDoor1.gsm , MyDoor2.gsm].
- And "MyDoor1" is Defaults object then i would like change to "MyDoor2" object.
5 REPLIES 5
Anonymous
Not applicable
Traro wrote:
I would like to ChangeDefaults Door and Window(Change Object).
Ex.
- I have 2 door object [MyDoor1.gsm , MyDoor2.gsm].
- And "MyDoor1" is Defaults object then i would like change to "MyDoor2" object.
Traro,

If i understand you question properly, you can alt-click on an existing object in the floorplan to make that the default object when a new instance is placed.
Ralph Wessel
Mentor
Traro wrote:
I would like to ChangeDefaults Door and Window(Change Object).
Ex.
- I have 2 door object [MyDoor1.gsm , MyDoor2.gsm].
- And "MyDoor1" is Defaults object then i would like change to "MyDoor2" object.
I suggest first getting the object defaults with ACAPI_Element_GetDefaults. The critical information required for setting the correct library part is the libInd value in the API_ObjectType structure. This is a temporary index to the object in the loaded libraries. You can find this using ACAPI_LibPart_Search with the name of the target object.

I can't recollect whether it's essential to get the default parameters for this object to set in the tool defaults, but you can get this information using ACAPI_LibPart_GetParams (parameters and default size).
Ralph Wessel BArch
Software Engineer Speckle Systems
Tamas Zolnai
Graphisoft Alumni
Graphisoft Alumni
Ralph wrote:
Traro wrote:
I would like to ChangeDefaults Door and Window(Change Object).
Ex.
- I have 2 door object [MyDoor1.gsm , MyDoor2.gsm].
- And "MyDoor1" is Defaults object then i would like change to "MyDoor2" object.
I suggest first getting the object defaults with ACAPI_Element_GetDefaults. The critical information required for setting the correct library part is the libInd value in the API_ObjectType structure. This is a temporary index to the object in the loaded libraries. You can find this using ACAPI_LibPart_Search with the name of the target object.

I can't recollect whether it's essential to get the default parameters for this object to set in the tool defaults, but you can get this information using ACAPI_LibPart_GetParams (parameters and default size).
I absolutely agree with Ralph Wessel using these methods to change the default object. I wrote a code sample based on these methods,
which changes the default door object to "Door with Sidelight on Side 1 19". I hope it will be helpfull:

	API_LibPart			libDoor;
	API_Element			elementDoor;
	API_ElementMemo		memo;
	GSErrCode			err = NoError;

	// Get defaults for door element
	BNZeroMemory (&elementDoor, sizeof (API_Element));
	elementDoor.header.typeID = API_DoorID;
	err = ACAPI_Element_GetDefaults (&elementDoor, &memo);
	if (err != NoError) {
		WriteReport_Alert ("Cannot get door defaults");
		return;
	}

	// Get a door object from library using its name
	BNZeroMemory (&libDoor, sizeof (libDoor));
	const GS::UniString uName ("Door with Sidelight on Side 1 19");
	GS::ucscpy (libDoor.docu_UName, uName.ToUStr ());

	err = ACAPI_LibPart_Search (&libDoor, false);
	if (err != NoError) {
		WriteReport_Alert ("No libpart found with that name");
		return;
	}
	delete libDoor.location; // don't forget to free location

	// Change libInd of the default door to the new one
	{
		API_Element mask;

		ACAPI_ELEMENT_MASK_CLEAR (mask);
		ACAPI_ELEMENT_MASK_SET (mask, API_DoorType, openingBase.libInd);
		elementDoor.door.openingBase.libInd = libDoor.index;

		err = ACAPI_Element_ChangeDefaults (&elementDoor, &memo, &mask);
		if (err != NoError) {
			WriteReport_Alert ("Cannot change door defaults");
			return;
		}
	}

	// Check whether defaults were updated
	{
		API_Element elementDoor2;

		elementDoor2.header.typeID = API_DoorID;
		err = ACAPI_Element_GetDefaults (&elementDoor2, NULL);
		if (err != NoError) {
			WriteReport_Alert ("Cannot get door defaults");
			return;
		}
		if (elementDoor2.door.openingBase.libInd != libDoor.index) {
			WriteReport_Alert ("Door default settings were not updated");
			return;
		}
	}
This example changes only the default door object nothing more (e.g. not using default parameters of this door object).

Traro,
Is this what you searching for?
Tamás Zolnai
Graphisoft
Anonymous
Not applicable
Thanks to everyone
Tamas Zolnai
Graphisoft Alumni
Graphisoft Alumni
To load also the default parameters (e.g. marker) of the door object from library,
amend the code as the following lines shows ('+' means additions):

...
// Change libInd of the default door to the new one
{
    API_Element mask;

    ACAPI_ELEMENT_MASK_CLEAR (mask);
    ACAPI_ELEMENT_MASK_SET (mask, API_DoorType, openingBase.libInd);
    elementDoor.door.openingBase.libInd = libDoor.index;

+  // Set default params of the new door object
+  {
+     double a, b;
+     Int32 addParNum;
+     API_AddParType  **addPars;
+
+     err = ACAPI_LibPart_GetParams (libDoor.index, &a, &b, &addParNum, &addPars);
+     if (err) {
+        WriteReport_Alert ("Cannot get libpart params");
+        return;
+     }
+     memo.params = addPars;
+  }

    err = ACAPI_Element_ChangeDefaults (&elementDoor, &memo, &mask);
    if (err != NoError) {
       WriteReport_Alert ("Cannot change door defaults");
       return;
    }
+   ACAPI_DisposeElemMemoHdls (&memo);
}
...
Tamás Zolnai
Graphisoft

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!