Skip to main content
1-Visitor
June 20, 2019
Solved

Going crazy over this ... ProDwgTable going from Exist to not !!!

  • June 20, 2019
  • 1 reply
  • 2344 views

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.

image.png

Any idea of what's wrong?

Best answer by FV_01

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);

1 reply

FV_01
June 20, 2019

@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.

image.png

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.

AlexCote1-VisitorAuthor
1-Visitor
June 20, 2019

kind of forgot to show the variable declaration I had ... my bad.

I have this in the code before that block...image.png

Will modify to add the " * " ... just in case it's part of the problem.

FV_01
FV_0117-PeridotAnswer
June 20, 2019

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);