question

Patrick Cloutier avatar image
0 Likes"
Patrick Cloutier asked Phil BoBo commented

How to reference the size of an item in the outobject?

Hello, how do I write the code to reference the size of an item in the outobject?

I tried: current.outObjects[1].subnodes[1].size.x

But it doesn't work. It says label does not exit.

I can't use first because I'll then need to create a loop to look at all the items in the outobject,

Thanks,

FlexSim 17.2.2
referencing
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

·
Phil BoBo avatar image
1 Like"
Phil BoBo answered Phil BoBo commented

subnodes[] is an array of treenodes. size is a property of an Object. You need to cast it to an Object:

current.outObjects[1].subnodes[1].as(Object).size.x;
· 4
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 Cloutier avatar image Patrick Cloutier commented ·

That doesn't work as is. I've attached the model. I want to send a maximum of 6 square meters of items in Queue2. The code is in the Send to Port of Queue1.max-area-available.fsm

By the way, I made it work by doing the area calculation within Queue2 and placing the info on a label on Queue2. But since I will need to select between hundreds of possible send to locations I'd much rather have the code in the sending object (queue1).

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Patrick Cloutier commented ·

You are getting the following exception:

time: 2.000000 exception: FlexScript exception: Label property length retrieved on /Queue2. Label does not exist. at MODEL:/Queue1>variables/sendtoport

You are trying to get Queue2's length on line 6:

if (current.outObjects[1].length==0) return 1;

Since an Object doesn't have a property called length, it is trying to get a label called length, which Queue2 doesn't have.

The non-existent label's value is always 0, so this always returns 1.

You should be trying to get the length of its subnodes property:

if (current.outObjects[1].subnodes.length==0) return 1;

It isn't even hitting your code in lines 9 -19.

You could have found that out by putting in a breakpoint and debugging this function.

0 Likes 0 ·
Patrick Cloutier avatar image Patrick Cloutier Phil BoBo ♦♦ commented ·

Yes you're right. I have never used breakpoints and I'm not familiar with it. I will look into this. Thanks a lot and sorry for my silly question.

0 Likes 0 ·
Show more comments

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.