question

Marco Baccalaro avatar image
2 Likes"
Marco Baccalaro asked Marco Baccalaro commented

Existence of an attribute

I have this code that returns <no path>:

Object box = model().find("Tools/FlowItemBin/Box/Box");
treenode itemBehaviour = box.attrs.behaviour;
return itemBehaviour;

But this code returns "It exists":

Object box = model().find("Tools/FlowItemBin/Box/Box");
treenode itemBehaviour = box.attrs.behaviour;
if (itemBehaviour)
	return "It exists";
else
	return "It does not exist";

It returns "It does not exist" if I change the second row to:

treenode itemBehaviour = box.find(">behaviour");

Why does this happen? Is it because those are hashed nodes?

FlexSim 18.0.4
attributesobjectexistsobject.attrs
5 |100000

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

1 Answer

·
Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Marco Baccalaro commented

This is a bug that we'll be fixing soon, but the issue is that currently box.attrs.behaviour is exactly the same as calling behaviour(box). This, like all the old commands that return a treenode, will return saferef instead of returning a null treenode.

So currently, if you use box.attrs.behaviour, you need to treat it like an old command and use if(objectexists(itemBehaviour)).

You could also use box.attrs.find("behaviour").

We'll be fixing the attrs property so that it no longer returns saferef when the attribute doesn't exist.

· 1
5 |100000

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

Marco Baccalaro avatar image Marco Baccalaro commented ·

Good! Thanks for the detailed explanation.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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