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

Need help on ACAPI_LibPart_UpdateSection

Hoa Tu
Newcomer
Hi,

I am trying to change the subtype of a library part using the ACAPI_LibPart_UpdateSection function as the following code segment:

// ----------------------------------------------------------------
char buffer[1000];

API_LibPartSection section;
GSHandle sectionHdl;

BNZeroMemory (&section, sizeof (API_LibPartSection));
section.sectType = API_SectAncestors;

sectionHdl = NULL;

// ModelElemID definded as:
// #define ModelElemID "{103E8D2C-8230-42E1-9597-46F84CCE28C0}-{00000000-0000-0000-0000-000000000000}"


strcpy_s (buffer, sizeof (buffer), ModelElemID);

sectionHdl = BMAllocateHandle (strlen(buffer), ALLOCATE_CLEAR, 0);
if (sectionHdl != NULL) {
memcpy (*sectionHdl, buffer, strlen(buffer));
err = ACAPI_LibPart_UpdateSection (libPart.index, &section, sectionHdl, NULL);
if (err) {
WriteReport_Err (err, "[Do_UpdateLibraryPart]Error in ACAPI_LibPart_UpdateSection, API_SectAncestors, libPart.index = %d", libPart.index);
}
BMKillHandle ((GSHandle*) &sectionHdl);
}


// ----------------------------------------------------------------



It does not seem to work. The updated object has the subtype shown as unknown subtype. I have updated other sections of the libpart such as API_Sect1DScript, API_Sect2DScript... ok.



Please help. Thanks in advance.



Regards,

Hoa TU

PS. This is developed for ArchiCAD 12
5 REPLIES 5
Ralph Wessel
Mentor
Hoa wrote:
I am trying to change the subtype of a library part using the ACAPI_LibPart_UpdateSection function as the following code segment:
Have you tried using APIEnv_OverwriteLibPartID and ACAPI_LibPart_Create to change the object?
Ralph Wessel BArch
Software Engineer Speckle Systems
Hoa Tu
Newcomer
Have you tried using APIEnv_OverwriteLibPartID and ACAPI_LibPart_Create to change the object?
Ralph,
Thanks for your suggestion, but I can not use the ACAPI_LibPart_Create, because it will change the GUID of the object.

Regards,
Hoa
Ralph Wessel
Mentor
Hoa wrote:
Thanks for your suggestion, but I can not use the ACAPI_LibPart_Create, because it will change the GUID of the object.
Not if you use it with APIEnv_OverwriteLibPartID. My understanding is that this will become a new revision of the same object, i.e. any projects referencing the object will still recognise it from the GUID.
Ralph Wessel BArch
Software Engineer Speckle Systems
Hoa Tu
Newcomer
Ralph,
Thanks. I will have a close look at your suggestion and will let you know the outcome of it.
Regards,
Hoa
Hoa Tu
Newcomer
I have tried using APIEnv_OverwriteLibPartID and ACAPI_LibPart_Create to change the subtype of the object. Well the result is interesting:

With ArchiCAD 12, the GUID of the object changed, so any object placed before the change will not be recognisable any more.

With ArchiCAD 14, the GUID of the object remained the same, so everything seems ok.

Since we are going to use AC14 soon, so I am not going to worry about the AC12 problem.

Thanks for your help.
Cheers,
Hoa