question

Hoang Nk avatar image
0 Likes"
Hoang Nk asked Hoang Nk commented

Problem with moveobject() command

Hi folks,

I'm having a bit of a problem when using the moveobject() command to move a flow item onto a queue. I have a list of flow items and would like to place them into their respective locations (queues). However, when I use the moveobject() command, the item is not placed onto the surface of its corresponding queue but it looks like the following photo

1696234428108.png

And it even looks weirder when I tried to move the item to the queues on the upper level, the item will have a large offset with the queue surface, like in this photo

1696234604743.png

Is there any way I can fix this? Thanks a lot for your help.

Here's the code I used to make this:

Table Init = Table("coil_file"); //list of items need to be generated
int nrow = Init.numRows;
treenode coil = Model.find("/Tools/FlowItemBin/Cylinder/1");
for (int index = 1; index <= nrow; index++)
{
    string location = Init[index]["location"]; //location where the item is placed
    string coil_num = Init[index]["coil_number"];
    int width = Init[index]["width"]; //dimension of the item from the list
    int diameter = Init[index]["diameter"];
    Object newitem = coil.copy(model(), 0);
    newitem.labels.assert("Coil_number").value = coil_num;
    newitem.setSize(diameter/1000,diameter/1000,width/1000); //set item's dimensions
    Object dest = Model.find(location);
    moveobject(newitem, dest);
}
FlexSim 23.1.3
visualizationmoveobject
1696234428108.png (55.5 KiB)
1696234604743.png (102.4 KiB)
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

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Hoang Nk commented

The default placement logic of a queue will

- not take into account the rotation of the item
- place the item outside its area, if it doesn't fit into the queue (with some padding space and again without taking rotation into account)

For both cases, the solution is to deactivate the queue's stacking behaviour and instead adjust the location to what it should be in the On Entry trigger with object.setLocation().

capture1.png


capture1.png (4.8 KiB)
· 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.

Hoang Nk avatar image Hoang Nk commented ·

hi, I set the On Entry trigger in the queue as you said but it placed the item further out, is this correct?

Object current = ownerobject(c);
Object item = param(1);
int port = param(2);
Vec3 location = current.getLocation(0.5,0.5,0);
item.setLocation(location.x,location.y,location.z,0.5,0.5,0);
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Hoang Nk commented ·

The location is relative to the object's own coordinates, so the centre position of any object is:

Vec3 selfCentre=current.size/2;

You can then to choose alter z to be 0 (stack inside) or leave it (stack in middle) or do something else.

then use

Vec3 itemFactors=Vec3(0.5,0.5,0);
item.setlocation(selfCentre,itemFactors);
0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Jason Lightfoot ♦♦ commented ·

And the itemFactors vector is going to differ if the object is rotated around the x- or y-axis. (values below if rotated around one axis only)

Vec3 itemFactors = Vec3(0.5, 1, 0.5)   // xRot = 90;
Vec3 itemFactors = Vec3(0.5, 0, 0.5)   // xRot = -90;
Vec3 itemFactors = Vec3(1, 0.5, 0.5)   // yRot = 90;
Vec3 itemFactors = Vec3(0, 0.5, 0.5)   // yRot = -90;
0 Likes 0 ·
Show more comments