cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

storing and retrieving array of C stucture into model itself.

ptc-3251077
1-Newbie

storing and retrieving array of C stucture into model itself.

Hi all,

Does anyone know how to store and retrieve array of C stucture in model itself?

I know it can be done using ProExtdataSlotWrite() and ProExtdataSlotRead() API by using the 'PRO_STREAM_TYPE' data type.
But i dont have any refereance of how to do it. Does anyone can provide me some reference or example for this?

TIA

-Vaibhav Gharat


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
1 REPLY 1
LarsZiegler
5-Regular Member
(To:ptc-3251077)

Hello!

This is my used code and works fine:

CMtkErr CMtkMdlHistoryCtrl::ReadData(ProMdl Mdl)

{

CMtkErr err(MTKTHROWERROR_ON);

try

{

ProExtdataErr ExtErr;

if (Mdl == NULL)

err = PRO_TK_BAD_INPUTS;

// Load external data

ExtErr = ProExtdataLoadAll(Mdl);

if (ExtErr != PROEXTDATA_TK_NO_ERROR) throw ExtErr;

ProExtdataClass ExtdataClass;

ExtdataClass.p_model = Mdl;

wcscpy(ExtdataClass.class_name, MTKMDLHISTORYCLASS);

ProExtdataSlot ExtdataSlot;

ExtdataSlot.p_class = &ExtdataClass;

ExtdataSlot.slot_id = -1;

wcscpy(ExtdataSlot.slot_name, MTKMDLHISTORYSLOT);

int DataType, DataSize;void *Data;

ExtErr = ProExtdataSlotRead(&ExtdataSlot, KEY_BY_NAME, &DataType,

&DataSize, &Data);

if (ExtErr == PROEXTDATA_TK_NO_ERROR)

{

MtkMdlHistoryEntity *Entities = static_cast<mtkmdlhistoryentity *=">(Data);if (DataType == PRO_STREAM_TYPE)

{

int Count = DataSize / sizeof(MtkMdlHistoryEntity);

for (int i = 0; i < Count; i++)

m_pData->AddEntity(Entities[i]);

}

ExtErr = ProExtdataFree(&Data);

if (ExtErr != PROEXTDATA_TK_NO_ERROR) throw ExtErr;

}

return err;

}

catch (ProExtdataErr &ex)

{

//MtkMsgBox(ProTestProAppdataErr(ex), "ProExtdataErr", MB_OK | MB_ICONSTOP);

MtkDisplayMsg(ProTestProAppdataErr(ex), MSG_ERROR);

return PRO_TK_NO_ERROR;

}

catch (CMtkErr &e)

{

e.SetClassAndFunction("CMtkMdlHistoryCtrl", "ReadData");

e.DisplayError();

return e;

}

}

 

CMtkErr CMtkMdlHistoryCtrl::WriteData(ProMdl Mdl)

{

CMtkErr err(MTKTHROWERROR_ON);

try

{

ProExtdataErr ExtErr;

// Initialize external data

ExtErr = ProExtdataInit(Mdl);

if (ExtErr != PROEXTDATA_TK_NO_ERROR) throw ExtErr;

// Register class

ProExtdataClass ExtdataClass;

ExtErr = ProExtdataClassRegister(Mdl, MTKMDLHISTORYCLASS, &ExtdataClass);

if (ExtErr != PROEXTDATA_TK_NO_ERROR)

{

if (ExtErr = PROEXTDATA_TK_CLASS_OR_SLOT_EXISTS)

{

ExtdataClass.p_model = Mdl;

wcscpy(ExtdataClass.class_name, MTKMDLHISTORYCLASS);

}

else

throw ExtErr;

}

// Create slot

ProExtdataSlot ExtdataSlot;

ExtErr = ProExtdataSlotCreate(&ExtdataClass, MTKMDLHISTORYSLOT, &ExtdataSlot);

if (ExtErr != PROEXTDATA_TK_NO_ERROR)

{

if (ExtErr = PROEXTDATA_TK_CLASS_OR_SLOT_EXISTS)

{

ExtdataSlot.p_class = &ExtdataClass;

ExtdataSlot.slot_id = -1;

wcscpy(ExtdataSlot.slot_name, MTKMDLHISTORYSLOT);

}

else

throw ExtErr;

}

ExtErr = ProExtdataSlotWrite(&ExtdataSlot, KEY_BY_NAME, PRO_STREAM_TYPE,

sizeof(MtkMdlHistoryEntity) * m_pData->GetCount(), m_pData->GetEntities());

if (ExtErr != PROEXTDATA_TK_NO_ERROR) throw ExtErr;

return err;

}

catch (ProExtdataErr &ex)

{

//MtkMsgBox(ProTestProAppdataErr(ex), "ProExtdataErr", MB_OK | MB_ICONSTOP);

MtkDisplayMsg(ProTestProAppdataErr(ex), MSG_ERROR);

return PRO_TK_NO_ERROR;

}

catch (CMtkErr &e)

{

e.SetClassAndFunction("CMtkMdlHistoryCtrl", "WriteData");

e.DisplayError();

return e;

}

}

/*====================================================================*\

Function : ProTestProAppdataErr

Purpose : Display error message

\*====================================================================*/

char * CMtkMdlHistoryCtrl::ProTestProAppdataErr(ProExtdataErr err)

{

switch(err)

{

case PROEXTDATA_TK_NO_ERROR:

return("No error");

case PROEXTDATA_TK_INVALID_OBJ_OR_CLASS:

return("Invalid object or class");

case PROEXTDATA_TK_CLASS_OR_SLOT_EXISTS:

return("Class or slot exists");

case PROEXTDATA_TK_NAMES_TOO_LONG:

return("Names too long");

case PROEXTDATA_TK_SLOT_NOT_FOUND:

return("Slot not found");

case PROEXTDATA_TK_BAD_KEY_BY_FLAG:

return("Bay KEY_BY flag");

case PROEXTDATA_TK_INVALID_OBJ_TYPE:

return("Invalid object type");

case PROEXTDATA_TK_EMPTY_SLOT:

return("Empty slot");

case PROEXTDATA_TK_BAD_DATA_ARGS:

return("Bad data arguments");

case PROEXTDATA_TK_STREAM_TOO_LARGE:

return("Stream too large");

case PROEXTDATA_TK_INVALID_SLOT_NAME:

return("Invalid slot name");

case PROEXTDATA_TK_ERROR:

return("General error");

default :return("**UNKNOWN STATUS**");

}

}

Top Tags