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

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

axel_kohonen
Not applicable
31 Views
6 Replies
Message 1 of 7

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

axel_kohonen
Not applicable

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

0 Likes
Accepted solutions (1)
32 Views
6 Replies
Replies (6)
Message 2 of 7

philboboADSK
Autodesk
Autodesk
Accepted solution

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


Phil BoBo
Sr. Manager, Software Development
Message 3 of 7

axel_kohonen
Not applicable

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
Message 4 of 7

philboboADSK
Autodesk
Autodesk

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


Phil BoBo
Sr. Manager, Software Development
Message 5 of 7

axel_kohonen
Not applicable

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
Message 6 of 7

philboboADSK
Autodesk
Autodesk

I'll add a case to the dev list to consider this.

It doesn't make sense to add it to the Table class though, because that class relates to the table data, and this code is entirely UI-level about a view that is pointing at that data.



Phil BoBo
Sr. Manager, Software Development
Message 7 of 7

axel_kohonen
Not applicable

Thank you. I trust you know that best.

0 Likes