• Home
  • User Manual
  • Tutorials
  • Updates
Search Results for

    Show / Hide Table of Contents
    • Welcome to twin
    • Getting Started
      • Install and uninstall twin
      • Install and uninstall a licence
      • Start twin
    • Simulation Component Library
      • Automation
        • ScriptComponent
        • Sequence
      • BitManipulator
        • BitsToBytesConverter
        • BytesToBitsConverter
        • EndiannessChanger
      • BooleanOperations
        • BooleanFunction
        • Invert
        • InputSwitch
      • ControlPanel
        • ControlPanel
      • Conveyor
        • Conveyor
        • VacuumConveyor
      • Debug
        • Counter
      • DataManipulator
        • DataReader
        • DataTypeConverter
        • DataWriter
      • FMU
        • FMU
      • Gripper
        • KinematicGripper
        • ObjectCoupler
        • VacuumGripper
      • HardwareConnector
        • PLCConnector
        • RobotControllerConnector
      • Math
        • Gain
        • LinearFunction
        • LowPassFilter
        • NumberComparer
        • Sum
      • Motor
        • FCControlledMotor
        • ServoMotor
      • Movers
        • BoolToSignedDirection
        • DynamicCylinder
        • DynamicRotationMover
        • DynamicTranslationMover
        • KinematicCylinder
        • KinematicPathMover
        • KinematicRotationMover
        • KinematicTranslationMover
      • ObjectManipulator
        • Colorizer
        • Object3DCutter
        • VisibilityChanger
      • Sensors
        • AngleLimitSwitch
        • CollisionObserver
        • DistanceSensor
        • DynamicObjectDetector
        • LightBarrier
        • PositionLimitSwitch
        • PositionTracker
      • Sinks
        • FileLogger
        • CollisionSink
        • RaySink
      • Sources
        • BoolConstant
        • BoxSource
        • DoubleConstant
        • Object3DFileSource
        • Object3DSource
        • RandomBoolean
        • RandomNumber
        • SinusGenerator
        • SphereSource
        • StringConstant
      • Timers
        • IntervalTrigger
        • TOF
        • TON
    • Collision Detection
      • What is essential for collision detection?
      • Where can I find the mesh simplifiers?
      • Which mesh simplification methods are available?
    • twin Mirror
      • Install the twin Mirror
      • Embed the twin Mirror into your HMI
      • React on user-events
      • Manipulate 3D objects
      • Add labels and buttons
    • Video Guides
      • Install twin
      • How to handle twin
      • Organize projects
      • Import CAD files
      • Handle 3D objects
      • Organize simulation components
      • Activate physics in your simulation
      • Simulate conveyor systems
      • Simulate cylinders
      • Simulate axis systems and portals
      • Simulate sensors
      • Simulate grippers
      • Create program sequences
      • Connect to PLCs
      • Simulate robots
      • Model complex mechanical motion systems
      • Debug and analyse signals in twin
      • Best practices for maintenance efficient project development
      • FAQ

    User Events

    This documentation demonstrates how to manipulate objects via our API. This helps to make your mirror more interactive.

    Create user events

    To use custom events like click events to manipulate objects you can also use our API. For example if you want to change the color of a clicked object. To do so you can create an event via JavaScript like this to get the guid of the object and change its color.

    twin.host.notify = function (topic, payload) {
      if (topic == "objectClicked") {
        let object = twin.scene.getObject(payload.guid);
        object.setColor("red");
      }
    };
    

    This code snippet changes shows a message box the name and guid of the clicked object.

    Example

    The following code displays an example how the whole file could look like.

    <!DOCTYPE html>
    <html>
      <head>
        <script src="./js/twin.min.js"></script>
      </head>
      <body>
        <div id="twinMirror"></div>
        <script>
          window.twin = new twinLibrary.Twin();
          window.twin.start("twinMirror", "http://localhost:3000");
          twin.host.notify = function (topic, payload) {
            if (topic == "objectClicked") {
              let object = twin.scene.getObject(payload.guid);
              object.setColor("red");
            }
          };
        </script>
      </body>
    </html>
    
    In this article
    Back to top Copyright © Eberle Automatische Systeme GmbH & Co KG