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: Mon Oct 19, 2015 4:49 pm (GMT+1)


I have found out how to manage that.
Thank you Ralph for guiding me. Smile

Here is some testing code that works, hope it can help someone one day.
Now i have to do the real clean code...

Code:
static void AddParameterTest (const API_LibPart& libPart)
{
    GSErrCode err;

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

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

   double a, b;
   Int32 addParNum, i;
    API_AddParType **addPars;
    err = ACAPI_LibPart_GetParams (libPart.index, &a, &b, &addParNum, &addPars);
    if (err) return;

   // Create enough space for all parameters
   Int32 myParameterCount = 1;
   short nPars = addParNum + myParameterCount;
   API_AddParType** newAddPars = reinterpret_cast<API_AddParType**>(BMAllocateHandle (nPars * sizeof (API_AddParType), ALLOCATE_CLEAR, 0));
   if (addPars != NULL)
   {
      // Copy all parameters
      for (i = 0; i < addParNum; i++)
      {
         (*newAddPars)[i] = (*addPars)[i];
      }

      // Add our new parameter
      API_AddParType* pAddPar = &(*newAddPars)[nPars-1];
      pAddPar->typeID = APIParT_Mater;
      pAddPar->typeMod = 0;
      CHTruncate ("mat", pAddPar->name, sizeof (pAddPar->name));
      GS::ucscpy (pAddPar->uDescname, L("Tom's testing parameter"));
      pAddPar->value.real = 1;
                  
      // Build a section handle with all parameters
      GSHandle Sect2DHdl = NULL;
      err = ACAPI_LibPart_GetSect_ParamDef (&libPart, newAddPars, &a, &b, NULL, &sectionHdl);

      BMKillHandle (reinterpret_cast<GSHandle*>(&newAddPars));
   }   

   // Update our section...
   err = ACAPI_LibPart_UpdateSection (libPart.index, &section, sectionHdl, NULL);
   BMKillHandle (&sectionHdl);

    ACAPI_DisposeAddParHdl (&addPars);
}




Viewing all articles
Browse latest Browse all 564

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>