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.

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.

  1. Object obj = Model.find("Plane1/Operator1");
  2. Object dest = model();
  3.  
  4. Vec3 center = Vec3(0.5, 0.5, 0.5);
  5. Vec3 destPos = obj.getLocation(center).project(obj.up, dest);
  6. Vec3 destRot = obj.rotation.projectRotation(obj.up, dest);
  7.  
  8. moveobject(obj, dest);
  9.  
  10. obj.setLocation(destPos, center);
  11. 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.