question

Axel Kohonen avatar image
0 Likes"
Axel Kohonen asked Axel Kohonen commented

Is there a way to go to a certain row of a global table?

Hi,

When using large global tables it would be very nice to go to a certain row in the global table without having to scroll there. If I want to go to row 13450 e.g. it takes some time to scroll there. And when debugging code, it would be nice if I could get there using some kind of function call.

Is there a way to do this?

Thank you.

Kind regards,

Axel

global tablerack
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Phil BoBo avatar image
5 Likes"
Phil BoBo answered Axel Kohonen commented

You can use the scrollinfo() command to set the scroll position of a view.

The following code will scroll an active global table view to the row specified in the first line of the code.

It will go directly to the specified row if the table has less than 32767 rows (the precision limits of a Windows scroll bar) or close to that row if the table has more than 32767 rows.

int goToRow = 13450;

treenode tableView = node("TableView", activedocumentnode());
if (!objectexists(tableView))
	return 0;

double nMin = scrollinfo(tableView, 0, 1, 1);
double nMax = scrollinfo(tableView, 0, 1, 2);
double nPage = scrollinfo(tableView, 0, 1, 3);
double nPos = scrollinfo(tableView, 0, 1, 4);

if (nMax < 32767) {
	scrollinfo(tableView, 1, 1, 4, goToRow - 1);
	repaintview(tableView);
	return 0;
}

treenode tableDataNode = node(">viewfocus+", tableView);
double totalRows = tableDataNode.as(Table).numRows;
double pos = goToRow / totalRows * (nMax - nPage);
scrollinfo(tableView, 1, 1, 4, pos);
repaintview(tableView);
· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Axel Kohonen avatar image Axel Kohonen commented ·

Hi @phil.bobo

Thank you! If works nicely if the table view is selected before running this in the script window.

Is there some easy way to get the tableView of a certain Global table, which is not necessarily active? I would want to use this for debugging and going to a certain row when I do some changes to that row. E.g. if I have a table named "InputTable", how do I find the corresponding view in the View/active tree?

Thank you!

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Axel Kohonen commented ·

You can traverse through the nodes under VIEW:/active in order to find a particular window that is open. For example, this code will find an open global table view that is focused on InputTable:

treenode tableNode = Table("InputTable");

treenode tableView = NULL;
treenode openTableViews = node("VIEW:/active>Documents/Table");
for (int r = 1; r <= content(openTableViews); r++) {
	treenode openTableView = node("TableView", ownerobject(tonode(get(rank(openTableViews, r)))));
	treenode openTableNode = node(">viewfocus+", openTableView);
	if (openTableNode == tableNode) {
		tableView = openTableView;
	}
}
return tableView;

You could also use the createview() command to open the table's properties window, which will open the view if it isn't already open and activate it.

treenode tableNode = Table("InputTable");
createview(gets(guifocusclass(ownerobject(tableNode))), nodetopath(ownerobject(tableNode)));

You can combine all three of these code snippets together to accomplish what you are trying to do:

int goToRow = 13450;
treenode tableNode = Table("InputTable");

createview(gets(guifocusclass(ownerobject(tableNode))), nodetopath(ownerobject(tableNode)));

treenode tableView = NULL;
treenode openTableViews = node("VIEW:/active>Documents/Table");
for (int r = 1; r <= content(openTableViews); r++) {
	treenode openTableView = node("TableView", ownerobject(tonode(get(rank(openTableViews, r)))));
	treenode openTableNode = node(">viewfocus+", openTableView);
	if (openTableNode == tableNode) {
		tableView = openTableView;
	}
}
if (!objectexists(tableView))
	return 0;

double nMin = scrollinfo(tableView, 0, 1, 1);
double nMax = scrollinfo(tableView, 0, 1, 2);
double nPage = scrollinfo(tableView, 0, 1, 3);
double nPos = scrollinfo(tableView, 0, 1, 4);

if (nMax < 32767) {
	scrollinfo(tableView, 1, 1, 4, goToRow - 1);
	repaintview(tableView);
	return 0;
}

treenode tableDataNode = node(">viewfocus+", tableView);
double totalRows = tableDataNode.as(Table).numRows;
double pos = goToRow / totalRows * (nMax - nPage);
scrollinfo(tableView, 1, 1, 4, pos);
repaintview(tableView);
2 Likes 2 ·
Axel Kohonen avatar image Axel Kohonen Phil BoBo ♦♦ commented ·

Hi @phil.bobo

Thank you! It works really well although it does not give an error if the row number is larger than what is in the table. But that would be easy to fix I guess.

Could you consider to add this as a command into FlexSim? Probably into the table class. It would make debugging table operations easier.

Thank you!

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.