Start a new topic

Deleting Tag-along extensions

Original Post by: dfoster2 Mon Dec 14 21:12:06 2009


How do I remove a tag-along extension from a node using the OpenFlight API?


Original Post by: SteveThompson Mon Dec 14 23:54:21 2009


A tag-along extension is a record attached to the node. To get the extension record use function mgGetExtRec. Now that you have the record (returned by mgGetExtRec) to delete it use mgDelete.

Original Post by: dfoster2 Tue Dec 15 16:19:36 2009


Deleting the extension record always seems to fail.


Is there a way to determine why the record won't delete?


Here is the code:


#include <mgapiall.h>


int main(int argc, char* argv[])

{

char *model_filename = argv[1];


mgInit(&argc;, argv);


mgrec* header = mgOpenDb(model_filename);

mgrec* switch_node = mgGetRecByName(header, "sw1");

mgrec* switch_ext = mgGetExtRec(switch_node, 4356);

mgbool result = mgDelete(switch_ext);

}


On a side note, I had to use the record code in mgGetExtRec() instead of the record type name in order to get this to compile. It loads the plugin at runtime, but doesn't seem to know about the plugin variables at compile time.


I have attached a very simple OpenFlight file. I don't have permission to post the plugin dll.


Any help would be appreciated.

Original Post by: SteveThompson Tue Dec 15 18:06:09 2009


I assume you checked that switch_ext was not MG_NULL. Also can you verify that your extension DLL is loading in your app?


If switch_ext is not MG_NULL and your DLL is loading properly, it could be related to the other problem you mention about the compiler not knowing about your plugin at compile time. You really should "fix" that before continuing. You cannot safely use hard coded numbers for attribute codes as you are doing. This is fraught with peril and is extremely fragile and error-prone.


To help your compile problem...

When you build your data dictionary DLL with ddbuild you get some header files created. In particular there is one called XXXcode.h where XXX is your extension prefix. If you include this file wherever you need to access your field and record codes you should be golden. And NEVER use the #define's starting with eXXX, these are "local" codes that must be translated to global codes using the XXX version of the macro.


Here is an excerpt from the header file (mycode.h) included in the sample extension distributed with the API SDK. This is the file created by ddbuild. In this case, always use myObjExt to access the tag-along object extension record, not eMyObjExt.


#define myObjExt (ddGetUCode(MY_SITEID, eMyObjExt))


Again, you must use the field and record code (#define's that go through ddGetUCode) in your XXXcode.h file to safely access extension data.


Add this include, change the call to mgGetExtRec to use the correct symbols and see if that does not help and let us know.

Login to post a comment