Existence of an attribute

Existence of an attribute

marco_baccalaro
Not applicable
31 Views
2 Replies
Message 1 of 3

Existence of an attribute

marco_baccalaro
Not applicable

[ FlexSim 18.0.4 ]

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?

Accepted solutions (1)
32 Views
2 Replies
Replies (2)
Message 2 of 3

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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.



Matthew Gillespie
FlexSim Software Developer

Message 3 of 3

marco_baccalaro
Not applicable

Good! Thanks for the detailed explanation.

0 Likes