Keep global position by code

Keep global position by code

lucas_klein83QQC
Advocate Advocate
206 Views
3 Replies
Message 1 of 4

Keep global position by code

lucas_klein83QQC
Advocate
Advocate

[ FlexSim 20.0.3 ]

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.

Accepted solutions (1)
207 Views
3 Replies
Replies (3)
Message 2 of 4

lucas_klein83QQC
Advocate
Advocate

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
Message 3 of 4

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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



Matthew Gillespie
FlexSim Software Developer

Message 4 of 4

lucas_klein83QQC
Advocate
Advocate

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

0 Likes