Check if an object is already connected to a conveyor

Check if an object is already connected to a conveyor

guiroehe
Collaborator Collaborator
95 Views
2 Replies
Message 1 of 3

Check if an object is already connected to a conveyor

guiroehe
Collaborator
Collaborator

Hello,

how one can check if an object is already connected to a conveyor to avoid duplicating port connections between them?

As the conveyor can have multiple entry or exit transfers, and the transfers are separated objects, testing the list of conveyor points exhaustively is very inefficient.

Thank you.

0 Likes
96 Views
2 Replies
Replies (2)
Message 2 of 3

xavier_low
Contributor
Contributor

You can iterate over the object's outObjects and get the class object:

Object processor = Model.find("Processor1");
int isConnected = 0;

for(int i = 1; i <= processor.outObjects.length; i++) {
	Object obj = processor.outObjects[i];
	if (classobject(obj).name == "EntryTransfer")
		isConnected = 1;
}

if (!isConnected) 
	// Connect object to conveyor
	contextdragconnection(processor, Model.find("StraightConveyor1"), "A");

 

0 Likes
Message 3 of 3

guiroehe
Collaborator
Collaborator

Hi, @xavier_low ,

thank you. However this is what I mentioned on my question that is highly inefficient. It works fine for a few conveyors, not for large scale problems.

Thank you anyway.

0 Likes