Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X
Hi All,
got a problem here that I can't figure out ... and I suspect my lack of knowledge in C language.
So I have this part of code:
for (TableIdx = 0; TableIdx <= NbrOfTbl - 1; TableIdx++) { //Get the number of columns CurrTbl = MyTablesCollection[TableIdx]; //ProDwgtable(MyTablesCollection[c1]); NbrOfCols = GetTheColumnCount(&CurrTbl); // This here works NbrOfRows = GetTheRowCount(&CurrTbl); // This here works ShowMessage(" (Loop with Repeat Region) Return of functions, NbrOfCols = %d ... NbrOfRows = %d", NbrOfCols, NbrOfRows); if (NbrOfCols == 9 || NbrOfCols == 10) { ShowMessage(" Check before 'ProDwgtableCellRefmodelGet' ... NbrOfCols = %d", NbrOfCols); error = ProDwgtableCellRefmodelGet(&CurrTbl, 4, 1, ProAssemblyRepeatRg, ProMdlRepeatRg); if (error != PRO_TK_NO_ERROR) { //We want the loop to go on if the error is PRO_TK_E_NOT_FOUND if (error == PRO_TK_BAD_INPUTS) { ShowMessage(" Problem with ProDwgtableCellRefmodelGet. Error = %s", GetProErrorDesc(error)); goto _END; } } else { if (ProAssemblyRepeatRg != NULL) { TableFound = TableFound + 1; ShowMessage(" TableFound = %d", TableFound); int NbrOfColsInf = GetTheColumnCount(&CurrTbl); // This here DO NOT works int NbrOfRowsInf = GetTheRowCount(&CurrTbl); // This here DO NOT works ShowMessage(" Col: %d ... Row: %d", NbrOfColsInf, NbrOfRowsInf); goto _ExitCheckLoop; } } } ShowMessage(" TableFound (with Repeat Region) = %d", TableFound); _ExitCheckLoop:
if (TableIdx != 0) {
CurrTbl = MyTablesCollection[TableIdx];
ShowMessage(" Index of Table: %d", TableIdx);
int NbrOfCols2 = GetTheColumnCount(&CurrTbl);
int NbrOfRows2 = GetTheRowCount(&CurrTbl);
ShowMessage(" Col: %d ... Row: %d", NbrOfCols2, NbrOfRows2);
}
Both sub functions:
int GetTheColumnCount(ProDwgtable *TheTable) { //ShowMessage(" Debut sous fonction, GetTheColumnCount. %d", 1); int ColNumber = 0; ProError error; error = ProDwgtableColumnsCount(TheTable, &ColNumber); if (error != PRO_TK_NO_ERROR) { ShowMessage(" Error, in GetTheColumnCount, with ProDwgtableColumnsCount = %s", GetProErrorDesc(error)); return 0; } return ColNumber; } int GetTheRowCount(ProDwgtable *TheTable) { int RowNumber = 0; ProError error; error = ProDwgtableRowsCount(TheTable, &RowNumber); if (error != PRO_TK_NO_ERROR) { ShowMessage(" Error, in GetTheRowCount, with ProDwgtableRowsCount = %s", GetProErrorDesc(error)); return 0; } return RowNumber; }
So all this gives the below results, for a reason I can't find the variable 'CurrTbl' is becoming empty or something even tough I don't reassign anything to it. Of course later on in the code I try to work with the table and since it does not EXIST for CREO, it crashes.
Any idea of what's wrong?
Solved! Go to Solution.
this is what you should be doing:
ProError foo( ProDwgtable * MyTablesCollection, int NbrOfTbl) { for ( int tableIdx = 0; tableIdx < NbrOfTbl; ++tableIdx) { //Get the number of columns ProDwgtable *p_CurrTbl = &MyTablesCollection[tableIdx]; int NbrOfCols = GetTheColumnCount(p_CurrTbl); int NbrOfRows = GetTheRowCount(p_CurrTbl); if (NbrOfCols == 9 || NbrOfCols == 10) { ; } else { continue; } { ProAssembly proAssemblyRepeatRg = NULL; ProMdl proMdlRepeatRg = NULL; ProError error = ProDwgtableCellRefmodelGet(p_CurrTbl, 4, 1, &proAssemblyRepeatRg, &proMdlRepeatRg); if (error != PRO_TK_NO_ERROR) { continue; } if (proAssemblyRepeatRg != NULL) { int NbrOfColsInf = GetTheColumnCount(p_CurrTbl); int NbrOfRowsInf = GetTheRowCount(p_CurrTbl); } } } return PRO_TK_NO_ERROR; }
you are destroying your heap and stack by calling this:
error = ProDwgtableCellRefmodelGet(&CurrTbl, 4, 1,ProAssemblyRepeatRg, ProMdlRepeatRg);
@AlexCote wrote:
Hi All,
got a problem here that I can't figure out ... and I suspect my lack of knowledge in C language.
So I have this part of code:
for (TableIdx = 0; TableIdx <= NbrOfTbl - 1; TableIdx++) { //Get the number of columns CurrTbl = MyTablesCollection[TableIdx]; //ProDwgtable(MyTablesCollection[c1]); NbrOfCols = GetTheColumnCount(&CurrTbl); // This here works NbrOfRows = GetTheRowCount(&CurrTbl); // This here works ShowMessage(" (Loop with Repeat Region) Return of functions, NbrOfCols = %d ... NbrOfRows = %d", NbrOfCols, NbrOfRows); if (NbrOfCols == 9 || NbrOfCols == 10) { ShowMessage(" Check before 'ProDwgtableCellRefmodelGet' ... NbrOfCols = %d", NbrOfCols); error = ProDwgtableCellRefmodelGet(&CurrTbl, 4, 1, ProAssemblyRepeatRg, ProMdlRepeatRg); if (error != PRO_TK_NO_ERROR) { //We want the loop to go on if the error is PRO_TK_E_NOT_FOUND if (error == PRO_TK_BAD_INPUTS) { ShowMessage(" Problem with ProDwgtableCellRefmodelGet. Error = %s", GetProErrorDesc(error)); goto _END; } } else { if (ProAssemblyRepeatRg != NULL) { TableFound = TableFound + 1; ShowMessage(" TableFound = %d", TableFound); int NbrOfColsInf = GetTheColumnCount(&CurrTbl); // This here DO NOT works int NbrOfRowsInf = GetTheRowCount(&CurrTbl); // This here DO NOT works ShowMessage(" Col: %d ... Row: %d", NbrOfColsInf, NbrOfRowsInf); goto _ExitCheckLoop; } } } ShowMessage(" TableFound (with Repeat Region) = %d", TableFound); _ExitCheckLoop:
if (TableIdx != 0) {
CurrTbl = MyTablesCollection[TableIdx];
ShowMessage(" Index of Table: %d", TableIdx);
int NbrOfCols2 = GetTheColumnCount(&CurrTbl);
int NbrOfRows2 = GetTheRowCount(&CurrTbl);
ShowMessage(" Col: %d ... Row: %d", NbrOfCols2, NbrOfRows2);
}Both sub functions:
int GetTheColumnCount(ProDwgtable *TheTable) { //ShowMessage(" Debut sous fonction, GetTheColumnCount. %d", 1); int ColNumber = 0; ProError error; error = ProDwgtableColumnsCount(TheTable, &ColNumber); if (error != PRO_TK_NO_ERROR) { ShowMessage(" Error, in GetTheColumnCount, with ProDwgtableColumnsCount = %s", GetProErrorDesc(error)); return 0; } return ColNumber; } int GetTheRowCount(ProDwgtable *TheTable) { int RowNumber = 0; ProError error; error = ProDwgtableRowsCount(TheTable, &RowNumber); if (error != PRO_TK_NO_ERROR) { ShowMessage(" Error, in GetTheRowCount, with ProDwgtableRowsCount = %s", GetProErrorDesc(error)); return 0; } return RowNumber; }So all this gives the below results, for a reason I can't find the variable 'CurrTbl' is becoming empty or something even tough I don't reassign anything to it. Of course later on in the code I try to work with the table and since it does not EXIST for CREO, it crashes.
Any idea of what's wrong?
this line is absolutely wrong:
CurrTbl = MyTablesCollection[TableIdx]; //ProDwgtable(MyTablesCollection[c1]);
what should be there instead is:
ProDwgtable * ptr_to_dwgtable = & MyTablesCollection[TableIdx];
all sub sequential code must be changed to use ptr_to_dwgtable.
HIH.
FV.
kind of forgot to show the variable declaration I had ... my bad.
I have this in the code before that block...
Will modify to add the " * " ... just in case it's part of the problem.
this is what you should be doing:
ProError foo( ProDwgtable * MyTablesCollection, int NbrOfTbl) { for ( int tableIdx = 0; tableIdx < NbrOfTbl; ++tableIdx) { //Get the number of columns ProDwgtable *p_CurrTbl = &MyTablesCollection[tableIdx]; int NbrOfCols = GetTheColumnCount(p_CurrTbl); int NbrOfRows = GetTheRowCount(p_CurrTbl); if (NbrOfCols == 9 || NbrOfCols == 10) { ; } else { continue; } { ProAssembly proAssemblyRepeatRg = NULL; ProMdl proMdlRepeatRg = NULL; ProError error = ProDwgtableCellRefmodelGet(p_CurrTbl, 4, 1, &proAssemblyRepeatRg, &proMdlRepeatRg); if (error != PRO_TK_NO_ERROR) { continue; } if (proAssemblyRepeatRg != NULL) { int NbrOfColsInf = GetTheColumnCount(p_CurrTbl); int NbrOfRowsInf = GetTheRowCount(p_CurrTbl); } } } return PRO_TK_NO_ERROR; }
you are destroying your heap and stack by calling this:
error = ProDwgtableCellRefmodelGet(&CurrTbl, 4, 1,ProAssemblyRepeatRg, ProMdlRepeatRg);
Thanks a lot ... heap .. stack ... lots of learning still to do.
I can do lots lots of thing in VB.NET , and getting there in C# ... but this ...
Thanks again
@AlexCote wrote:
Thanks a lot ... heap .. stack ... lots of learning still to do.
I can do lots lots of thing in VB.NET , and getting there in C# ... but this ...
Thanks again
This is about as basic as for a designer to model a 3d shape from a 2d print. a designer would be required to be able to read a print, to visualize a shape and to have enough proficiency in pro/e to be able to model it...
if a function declaration looks like this :
extern ProError ProDwgtableCellRefmodelGet ( ProDwgtable* table, int column, int row, ProAssembly* assembly, ProMdl* model);
it means that the two output arguments (ProAssembly* and ProMdl*) should be passed to a function by a pointer - &assembly, &model. this is conceptually a little bit similar to using 'ref' or 'out' keywords in C#.
the memory to hold the value of ProAssembly-type variable is allocated on stack by the caller and ProDwgtableCellRefmodelGet receives the address (pointer to) of that allocated space. the function would memcpy the value of whatever it had been asked to calculate (ProAssembly...) to that memory address thus filling the previously allocated stack space.
When you had passed ProAssembly by-value in your code it had meant that a temp space was allocated by a compiler to hold the copy of whatever random numbers stack variable was initialized with, because most likely you had not said
ProAssembly assembly = NULL;
and that value was treated by ProDwgtableCellRefmodelGet as the address of the memory to store one of the queried results, and most likely, by mere accident, that value had ended up being an address of some good heap data and that good heap data was overwritten by a ProDwgtableCellRefmodelGet function and here is the pro/e crash.