Graphisoft
Go to ArchicadWiki - the Archicad Knowledge Base
Post new topic   Reply to topic   printer-friendly view   .    ArchiCAD-Talk Forum Index >>> Developer Forum >>> Using API_RoomRelation structure
View previous topic :: View next topic
Author Message
suresha
Guest
Guest

Joined: 17 Sep 2009
Posts: 3
Location: Melbourne

PostPosted: Thu Sep 24, 2009 3:18 am    Post subject: Using API_RoomRelation structure Reply with quote

I am newbie here. Trying to write a program to Cycle through all the Zones. Find related objects in each Zone and Modify a Parameter.

Following is part of the code.


Code:

static GSErrCode CycleZoneObjects ( const long index, const char *floor_param, const char *floor_type )
{
   GSErrCode            lastErr;
   API_RoomRelation        relData;
   API_ElemTypeID         typeID;
   long                    ind;
   char               buffer[256];
   API_Element            element;
   API_ElementMemo         memo;

   typeID = API_ObjectID;

   lastErr = ACAPI_Element_GetRelations (API_ZoneID, index,
      typeID, &relData);
   
   if ( lastErr != NoError )
         return lastErr;
   sprintf ( buffer, "Found %d Related Objects", relData.nObject );
   WriteReport_Alert( buffer, true );
   //continue;
   {

      for ( ind=0; ind < relData.nObject; ind++)
      {
         BNZeroMemory (&element, sizeof (API_Element));
         element.header.typeID = typeID;
         element.header.index = (long) relData.objects[ind];
//Here the object index I get seems to be invalid.         
         lastErr = ACAPI_Element_Get ( &element );
         if (lastErr == NoError )
         {
            lastErr = ACAPI_Element_GetMemo_Masked ( element.header.typeID, element.header.index, APIMemoMask_AddPars, &memo);
            SetFloorParValue ( &memo.params, floor_param, floor_type);
            ACAPI_DisposeElemMemoHdls (&memo);
         }
         if (lastErr != NoError )
            WriteReport_Alert("ACAPI_Element_Get/Memo in ZoneObjects Error", true );
      }
   }

   ACAPI_DisposeRoomRelationHdls (&relData);
   return lastErr;
}


static GSErrCode CycleZones ( void)
{
   GSErrCode       lastErr;
   API_ElemTypeID  typeID;
   API_Element      elem;
   API_ElementMemo elemMemo;
   long            nElem, i;
   char         floor_param[] = "floor_f";
   char         floor_type[50];
   char         buffer[256];

   typeID = API_ZoneID;
   lastErr = ACAPI_Element_GetNum (typeID, &nElem);
   if (lastErr != NoError)
      return lastErr;

   sprintf ( buffer, "Found %ld Zones", nElem );
   WriteReport_Alert( buffer, true );

   for (i = 1; i <= nElem && !lastErr; i++)
   {
      if (!ACAPI_Element_Filter (typeID, i, APIFilt_OnVisLayer | APIFilt_OnActFloor))
         continue;
         
      BNZeroMemory (&elem, sizeof (API_Element));

      elem.header.typeID = typeID;
      elem.header.index = i;
      lastErr = ACAPI_Element_Get (&elem);
      if (lastErr == NoError && elem.header.hasMemo)
      {
         lastErr = ACAPI_Element_GetMemo_Masked ( typeID, i, APIMemoMask_AddPars, &elemMemo);
         /* Custom element processing */
         GetFloorParValue ( &elemMemo.params, floor_param, floor_type);
         if (CHEqualASCII(floor_type, "Tiles", CS_CaseInsensitive) ||
            CHEqualASCII(floor_type, "Carpet", CS_CaseInsensitive) )
         {
            sprintf(buffer, "The floor type is %s\n", floor_type);
            WriteReport_Alert(buffer, true);
            CycleZoneObjects ( elem.header.index, floor_param, floor_type );
         }
         ACAPI_DisposeElemMemoHdls (&elemMemo);
      }
   }
   return lastErr;
}


static void   DoZoneCycling (void)

{
   CycleZones();
   return;

}


I am having trouble getting the right object index from API_RoomRelation structure. When I pass the object index to ACAPI_Element_Get, I am getting error 13 which is not in the error list.

Also, I get the number of objects as 4 when there is only one object in the zone (3 more than the actual objects).

This is on ArchiCAD 10 using API 10.22

_________________
Suresh
Back to top
View user's profile Send private message
Ralph Wessel
Veteran member
Veteran member

Joined: 06 Nov 2003
Posts: 791
Location: United Kingdom

PostPosted: Thu Sep 24, 2009 10:09 am    Post subject: Re: Using API_RoomRelation structure Reply with quote

suresha wrote:
Code:

         element.header.index = (long) relData.objects[ind];
//Here the object index I get seems to be invalid.         
         lastErr = ACAPI_Element_Get ( &element );


When I pass the object index to ACAPI_Element_Get, I am getting error 13 which is not in the error list.

The error is actually 1 line above where you discover the problem. relData.objects is a handle, not a pointer, so you have to dereference it twice. That's why you have had to cast the value as (long) - the compiler was actually giving you a useful warning there.

So instead of:
Code:
element.header.index = (long) relData.objects[ind];
...you should write:
Code:
element.header.index = (*relData.objects)[ind];

_________________
Ralph Wessel
Encina Ltd
Design Software Solutions
Web: www.encina.co.uk
Back to top
View user's profile Send private message Visit poster's website
suresha
Guest
Guest

Joined: 17 Sep 2009
Posts: 3
Location: Melbourne

PostPosted: Thu Sep 24, 2009 12:40 pm    Post subject: Re: Using API_RoomRelation structure Reply with quote

Thank you very much Ralph!!

Regards,

_________________
Suresh
Back to top
View user's profile Send private message
Display posts from previous:   
View previous topic :: View next topic
Post new topic   Reply to topic   printer-friendly view       ArchiCAD-Talk Forum Index >>> Developer Forum >>> Using API_RoomRelation structure All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2008 - Graphisoft R&D Software Development zRt. All rights reserved worldwide. Terms of Use | Privacy Policy