Quantcast
Channel: ArchiCAD-Talk - Developer Forum
Viewing all articles
Browse latest Browse all 564

Modify an existing Library part's section destroys Libpart

$
0
0
Author:gehairing
Posted: Fri Oct 16, 2015 2:32 pm (GMT+1)


Hello all Smile

I try to modifiy an existing Library part by adding some parameters.

Here is a part of the code i use :

Code:
API_LibPart libPart;
         BNZeroMemory (&libPart, sizeof (API_LibPart));

         //TODO : Get type of libpart ?
         libPart.typeID   = APILib_ObjectID;
         libPart.location = &destinationFile;
         
         // Register the copied library part file
         err = ACAPI_LibPart_Register(&libPart);
         if(err == NoError)
         {
            // Get the library part
            err = ACAPI_LibPart_Get(&libPart);
            if(err == NoError)
            {

               // GS Doc says to free the location...
               if (libPart.location != NULL)
               {
                  delete libPart.location;
                  libPart.location = NULL;
               }
               
               // Add parameters/properties for this object
               API_LibPartSection section;
               BNZeroMemory (&section, sizeof (API_LibPartSection));
               section.sectType = API_SectParamDef;

               GSHandle sectionHdl = NULL;
               err = ACAPI_LibPart_GetSection(libPart.index, &section, &sectionHdl, NULL);

               short nPars = 3;
               API_AddParType** addPars = reinterpret_cast<API_AddParType**>(BMAllocateHandle (nPars * sizeof (API_AddParType), ALLOCATE_CLEAR, 0));
               if (addPars != NULL)
               {
                  API_AddParType* pAddPar = &(*addPars)[0];
                  pAddPar->typeID = APIParT_Mater;
                  pAddPar->typeMod = 0;
                  CHTruncate ("mat", pAddPar->name, sizeof (pAddPar->name));
                  GS::ucscpy (pAddPar->uDescname, L("Tom's Material"));
                  pAddPar->value.real = 1;
                  
                  pAddPar = &(*addPars)[1];
                  pAddPar->typeID = APIParT_Length;
                  pAddPar->typeMod = 0;
                  CHTruncate ("len", pAddPar->name, sizeof (pAddPar->name));
                  GS::ucscpy (pAddPar->uDescname, L("Tom's Length"));
                  pAddPar->value.real = 2.5;

                  pAddPar = &(*addPars)[2];
                  pAddPar->typeID = APIParT_CString;
                  pAddPar->typeMod = 0;
                  CHTruncate ("myStr", pAddPar->name, sizeof (pAddPar->name));
                  GS::ucscpy (pAddPar->uDescname, L("Tom's String parameter"));
                  GS::ucscpy (pAddPar->value.uStr, L("This is Tom's string"));
                  
                  double aa = 1.0;
                  double bb = 1.0;
                  GSHandle Sect2DHdl = NULL;
                  err = ACAPI_LibPart_GetSect_ParamDef (&libPart, addPars, &aa, &bb, Sect2DHdl, &sectionHdl);
                  
                  API_LibPartDetails details;
                  BNZeroMemory (&details, sizeof (API_LibPartDetails));
                  details.object.autoHotspot = false;
                  err = ACAPI_LibPart_SetDetails_ParamDef (&libPart, sectionHdl, &details);

                  err = ACAPI_LibPart_UpdateSection (libPart.index, &section, sectionHdl, NULL);

                  BMKillHandle (reinterpret_cast<GSHandle*>(&addPars));
                  BMKillHandle (&sectionHdl);
               }



After running this code on a valid library part the library part is no more valid. In the Library Part dialog there are messages indicating that the 2D symbol and 3D symbol are not valid.

Probably i'm not using correctly the APIs.

Do you have any idea what i am doing wrong ?

Thanks Wink


Viewing all articles
Browse latest Browse all 564

Trending Articles