• 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
        • VisiblityChanger
      • 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
      • How to install twin
      • How to organize projects
      • How to import CAD files
      • How to handle 3D objects
      • How to activate physics in your simulation
      • How to simulate conveyor systems
      • How to simulate cylinders
      • How to simulate axis systems and portals
      • How to simulate sensors
      • How to simulate grippers
      • How to create program sequences
      • How to connect to PLCs
      • How to simulate robots
      • How to model complex mechanical motion systems
      • How to debug and analyse signals in twin

    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