question

Lucas Klein avatar image
1 Like"
Lucas Klein asked Lucas Klein commented

Keep global position by code

Hello,

Is there any way to replicate the activity "Move object" from ProcessFlow with the option to maintain the item global position, using FlexScript?

Because always that I execute the "moveobject()" command, the location of the item updates according to the destination and also when I move the item back to model.

FlexSim 20.0.3
processflowflexscriptcode
· 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.

Lucas Klein avatar image Lucas Klein commented ·

Moving inside an object executes its updatelocation function, there is no problem doing this. The main use of the moveobject preserving the global position is in the way back to "model()"

0 Likes 0 ·

1 Answer

Matthew Gillespie avatar image
4 Likes"
Matthew Gillespie answered Lucas Klein commented

Use the Vec3 project() and rotationProject() methods to get the object's position and rotation within the new container. Then set the object's location and rotation to those values after moving the object.

Object obj = Model.find("Plane1/Operator1");
Object dest = model();

Vec3 center = Vec3(0.5, 0.5, 0.5);
Vec3 destPos = obj.getLocation(center).project(obj.up, dest);
Vec3 destRot = obj.rotation.projectRotation(obj.up, dest);

moveobject(obj, dest);

obj.setLocation(destPos, center);
obj.rotation = destRot;

preserveglobalposition.fsm


· 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.

Lucas Klein avatar image Lucas Klein commented ·

Thanks! I was almost at the right path, the projectRotation was the command missing.

0 Likes 0 ·