destroymessageevents command

destroymessageevents command

amerloQ2XZU
Advocate Advocate
502 Views
7 Replies
Message 1 of 8

destroymessageevents command

amerloQ2XZU
Advocate
Advocate

[ FlexSim 20.0.2 ]

Hi community,

today I run into an issue with destroymessageevents command.

The sequence to reproduce it is simple.

1. I created a delayed message with the code

Object s = Model.find("Source1);

s.message(10,s,100);

2. I executed the code to remove the message from the event list

Object s = Model.find("Source1");
destroymessageevents(s,0,s);

After executing the script, nothing happens!

Can someone help me? I attached the model.

0 Likes
Accepted solutions (1)
503 Views
7 Replies
Replies (7)
Message 2 of 8

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

This is a bug. The message() method isn't setting the event code of the event it creates. Thanks for pointing it out. We'll have this fixed for the next bug fix release.

The senddelayedmessage() command works fine if you need a workaround.



Matthew Gillespie
FlexSim Software Developer

Message 3 of 8

amerloQ2XZU
Advocate
Advocate

I tried your solution, but it works partially.

If I don't use the any filter it works, but when I add some message parameter doesn't destroy the message. Could you check my attached model? Thanks!

destroymessageevents-workaround.fsm

0 Likes
Message 4 of 8

tanner_p
Not applicable

@Alessio Merlo,

Just leave out the message parameter and it destroys all of the messages:

25507-destroy-message-help.png

25485-destroymessageevents-workaround-1.fsm

0 Likes
Message 5 of 8

Matthew_Gillespie
Autodesk
Autodesk

Yes, but it looks like it's supposed to be filtering out which events it destroys based off the message parameters.



Matthew Gillespie
FlexSim Software Developer

Message 6 of 8

Matthew_Gillespie
Autodesk
Autodesk

I'm not sure why that's not working, I'll look into it some more.



Matthew Gillespie
FlexSim Software Developer

Message 7 of 8

amerloQ2XZU
Advocate
Advocate

I need to filter on message parameter, then if you fix the issue in the next release is perfect! Thanks for your support!

0 Likes
Message 8 of 8

Matthew_Gillespie
Autodesk
Autodesk

I looked into this and it looks like the way we create message events has changed a lot since the destroymessageevents() command was added. I'll add a case to the dev list, but this won't be an easy fix like the previous fix.

However, you can use some of the other event commands to loop over the events in the event list and destroy the ones you're looking for. For example:

Object s = Model.find("Source1");
Variant p1 = 100;

int numEvents = maintree().find("project/exec/events").subnodes.length;
for (int i = numEvents; i >= 1; i--) {
	if (eventget(i, 3) == EVENT_SENDMESSAGE && eventget(i, 1) == s && eventget(i, 5) == s) {		
		treenode eventNode = eventget(i,6);
		if (getsdtvalue(eventNode, "p1") == p1)
			destroyevent(eventNode);
	}
}


Matthew Gillespie
FlexSim Software Developer