How to automatically connect multiple locations to the travel path network based on proximity to nodes?

How to automatically connect multiple locations to the travel path network based on proximity to nodes?

AHashemloo
Participant Participant
24 Views
11 Replies
Message 1 of 12

How to automatically connect multiple locations to the travel path network based on proximity to nodes?

AHashemloo
Participant
Participant

[ FlexSim HC 5.1.0 ]

Hello,

Using Flexsim Healthcare, I was wondering if it is possible to automatically connect a number of selected locations to the travel path network based on the proximity of nodes in the travel path network with respect to individual locations in the selection set.

In other words, for a single selected location, the General Properties window provides a boolean option as "Connect to Path" which allows for automatically identifying the closest node in the travel path network to the selected location and creating a connection between the node and the selected location.

However, I was wondering if there is a way to use this functionality for multiple selected locations automatically (like a loop applied to each location in the selection set) so that the closest node in the network per location is identified and a connection is made.

4136-connecttopath.jpg

Thank you,

Alireza

0 Likes
Accepted solutions (1)
25 Views
11 Replies
Replies (11)
Message 2 of 12

sam_stubbsYXX86
Community Manager
Community Manager

Unfortunately, as far as I know there isn't a way to do this with multiple objects. But perhaps someone can correct me if I'm mistaken.

0 Likes
Message 3 of 12

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution
for(int i = 1; i <= content(model()); i++)
{
	treenode group = rank(model(), i);	
	if(switch_selected(group, -1))
	{
		treenode closestnode = NULL;
		double closestdist = 1000000;
		//find closest node
		for( int j = 2; j <= content(model()); j++)
		{
			treenode cur = rank(model(), j);
			if(isclasstype(cur, CLASSTYPE_NETWORKNODE))
			{
				double curx = vectorprojectx(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
				double cury = vectorprojecty(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
				double curz = vectorprojectz(up(cur), xloc(cur), yloc(cur), zloc(cur), model());
				double curdist = sqrt( sqr(curx-xloc(group)) + sqr(cury-yloc(group)) + sqr(curz-zloc(group)) );
				if(curdist < closestdist)
				{
					closestdist = curdist;
					closestnode = cur;
				}
			}
		}
			
		//if node found and not already connected, connect the group and all the members to the closest node		
		if(objectexists(closestnode))
		{
			if(content(var_s(group, "networknodes")) == 0) //nothing connected to group yet
			{
				if(getvarnum(group, "ObjectType") == OBJECT_Prop)
					contextdragconnection(closestnode, group, "A");
				else
					contextdragconnection(group, closestnode, "A");
			}
			
			string letter;
			if(getvarnum(group, "ObjectType") == OBJECT_StaffGroup)
				letter = "A";
			else
				letter = "D";
				
			for(int index=1; index<=nrop(group); index++)
			{
				treenode member = outobject(group, index);
				if(isclasstype(member, CLASSTYPE_TASKEXECUTER) && inobject(member, 1) == group)
				{
					treenode navigator = findownerobject(tonode(get(first(var_s(member, "navigator")))));
					//if member is not connected to a NetworkNavigator yet, connect it to one
					if(classobject(navigator) == node("Navigator", library()))					
						contextdragconnection(member, closestnode, letter);					
				}
			}
		}
	}
}



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 4 of 12

AHashemloo
Participant
Participant

@Matthew Gillespie Thank you. I ran the script on the given example file and it worked well.

However, as I ran the script on my own project file, I encountered errors regarding undeclared variables ("index" and "member"). Have you defined them as global variables in your example project file? I would appreciate if you could guide me how I should tackle the issue.

4162-error-01.jpg

0 Likes
Message 5 of 12

Matthew_Gillespie
Autodesk
Autodesk

It looks like I didn't attach the most recent script. I've now updated it, so it should work correctly.



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 6 of 12

AHashemloo
Participant
Participant

@Matthew Gillespie Thank you very much. I ran a test on my project file and did not receive any error messages in the compiler. This can help save a lot of time in models with many individual locations to be connected to the network.

0 Likes
Message 7 of 12

bernard_laporteFYUJD
Observer
Observer

26737-script-error.png

@Matthew Gillespie hello! found that solution you provided a while ago to "automate" the NetworkNode to Resources connection process. Now, I tried to run your Script in a newer version (19.2.0) and I receive the error in the image attached. Seems like some modification were done to FlexSim that the what looks to be Macros (OBJECT_Prop and OBJECT_StaffGroup) no longer exist.

Is it possible to update that script to be run in newer versions?

Thank you!

Bernard

0 Likes
Message 8 of 12

Matthew_Gillespie
Autodesk
Autodesk

That script was written for FlexSim Healthcare 5 which is a heavily modified version of FlexSim 7.5. Are you trying to open an HC 5 model in 19.2? That won't work. We've added healthcare features to FlexSim 19 and later, but they are not backwards compatible with HC 5.



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 9 of 12

bernard_laporteFYUJD
Observer
Observer

I was trying to run the Script on FlexSim 19.2.0, I confess I haven't noted our solution was for HC, sorry about that. But do you think something similar can be done for FlexSim 19 and beyond?

0 Likes
Message 10 of 12

Matthew_Gillespie
Autodesk
Autodesk

Yes, we should be able to write a similar script in any version of FlexSim. I was just confused by your picture because it looked like you had opened and HC model.

Please create a new question,indicate which version of FlexSim you're using, and describe what you'd like the script to do and we'll help you out.



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 11 of 12

bernard_laporteFYUJD
Observer
Observer

Awesome! Will do so! Thanks for your support!

0 Likes
Message 12 of 12

michael_machado
Not applicable

@Bernard L2 I think @Flavio did something quite similar to Promodel´s users in the past. Create a new question as @Matthew Gillespie suggested and see how we'll help you out.

0 Likes