question

Ville Teivastenaho avatar image
0 Likes"
Ville Teivastenaho asked Ville Teivastenaho commented

Different behavior with createcopy() and treenode.copy()

Hi!

I wanted to create FlowVessels with varying number of FlowTanks within them. I copied the original tank as many times as required and set all tanks to be full. When I then connected the tanks to a FlowSink and opened the flow, only the first tank was emptied properly.

When any of the copied tanks were connected, the statistics where showing that there were a flow from the tank to the sink, but within the 3D view the level indicator or stats shown there weren't updated. Also the onEmty trigger of the flowTank didn't trigger and the content on the statistics panel eventually get negative.capture.png


I first thought of adding breathes and opening and closing flows/ports after each step, but these didn's seem to help. Finally I checked a older model where I had similar logic, and noticed that in the old model I used createcopy() and in the new model treenode.copy().

Then I tried creatycopy() for the new model, and everything works smoothly. Is there difference between these methods that I'm missing or could this be some kind of bug? At least based on the documentation for the createcopy it says "This command is deprecated. Use treenode.copy() instead". So I assume they should be interchangeable.


Attached there is a really simplified model replicating the issue. With first vessel tanks created with createcopy(), and second ones with treenode.copy.Createcopy_example.fsm

FlexSim 23.2.1
FloWorkscreatecopy
capture.png (104.9 KiB)
· 2
5 |100000

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

Patrick Zweekhorst avatar image Patrick Zweekhorst commented ·
Hi @Ville Teivastenaho <

We have confirmed that this is not working and we will put this bug on the bug list to find out what is going wrong precisely. We will keep you up to date

1 Like 1 ·
Mischa Spelt avatar image Mischa Spelt commented ·

Hmm it seems that the difference is that createcopy does not run the OnCreate function whereas treenode.copy does (unless you pass the COPY_FLAG_SUPPRESS_ON_CREATE flag). We are looking into why the execution of On Create matters in this case, but perhaps FlexSim the dev team can clarify whether this discrepancy between the two copy methods is intended or not.

0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
2 Likes"
Jason Lightfoot answered Ville Teivastenaho commented

From Phil's comment here:

"treenode.copy() automatically fires the OnCreate event unless you pass a flag to suppress it.

createcopy() does not. You have to call firecreateevent() yourself to execute the OnCreate event if you use createcopy()."

· 2
5 |100000

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

Mischa Spelt avatar image Mischa Spelt commented ·

Thanks Jason! I took the liberty of converting your comment to an answer, as it answers Ville's question "Is there difference between these methods that I'm missing ".

To complete the answer: if you use treenode.copy to copy a FloWorks flow item, you should pass the flag COPY_FLAG_SUPPRESS_ON_CREATE to mimic the old createcopy behavior. We will investigate further on our side if we will want to make any change to FloWorks regarding this.


0 Likes 0 ·
Ville Teivastenaho avatar image Ville Teivastenaho Mischa Spelt commented ·

That starts to make much more sense now. I tried to search from the forum before posting, and even found that discussion, but somehow missed Phil's comment or didn't understand it's relevance to this case.


Thank you all!

0 Likes 0 ·